Fix infinite loop when the viewer exits

* The viewer now sends `SIGHUP` to the main process when it exists
* The main process signal handler kills the viewer and terminates the
  notifier/main event loop when receiving `SIGINT`/`SIGTERM`/`SIGQUIT`
* The main process signal handler just terminates the notifier/main
  event loop when receiving `SIGHUP`
* Clean just after the notifier/main loop finishes
This commit is contained in:
Paul van Tilburg 2023-08-18 22:59:27 +02:00
parent fb1a0606fd
commit 5b7130c2f9
Signed by: paul
GPG Key ID: C6DE073EDA9EEC4D
1 changed files with 15 additions and 10 deletions

View File

@ -172,18 +172,9 @@ viewer_pid =
view(infile, mode)
# If xdvi/evince exits, this program should exit too.
puts "#{PROGRAM}: viewer exited, so will I!"
Process.kill("TERM", pid)
Process.kill("HUP", pid)
end
# Handle signals.
["INT", "TERM", "QUIT"].each do |sig|
Signal.trap(sig) do
Process.kill(sig, viewer_pid)
clean(infile)
exit
end
end
## Main event loop
# Add input file with dependancies to the watch list and start event loop.
@ -203,4 +194,18 @@ dirs.each do |dir|
end
end
# Handle signals during the main event loop.
["INT", "TERM", "QUIT"].each do |sig|
Signal.trap(sig) do
puts "#{PROGRAM}: caught signal #{sig}, stopping the viewer..."
Process.kill(sig, viewer_pid)
notifier.stop
end
end
Signal.trap("HUP") { notifier.stop }
# Run the main event loop.
notifier.run
# Clean before finishing!
clean(infile)