From c5d363406e59c38ce07a1c995d6930c799f3dce1 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 4 Dec 2020 22:37:54 +0100 Subject: [PATCH] Fix infinite loop when exiting viewer The CLD signal handler cleaned the ini file leading to another CLD signal, which called the handler again etc. Replace this by just killing the main process after the viewer exists in the code for the fork. Also note that we don't know which child process exited in the CLD signal handler. This might be the viewer, but also rubber. --- rubberin | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/rubberin b/rubberin index 03e6365..35c7eea 100755 --- a/rubberin +++ b/rubberin @@ -28,6 +28,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +require "English" require "getoptlong" require "rb-inotify" require "pathname" @@ -79,13 +80,13 @@ end def view(infile, mode) case mode when :dvi - exec "xdvi.bin", - "-watchfile", "1", - "-name", "xdvi", infile.with_extname("dvi").to_s + system "xdvi.bin", + "-watchfile", "1", + "-name", "xdvi", infile.with_extname("dvi").to_s when :ps - exec "evince", infile.with_extname("ps").to_s + system "evince", infile.with_extname("ps").to_s when :pdf, :pspdf - exec "evince", infile.with_extname("pdf").to_s + system "evince", infile.with_extname("pdf").to_s end end @@ -168,8 +169,14 @@ compile(infile, mode) puts # Spawn a viewer based on the mode. -viewer_pid = fork -view(infile, mode) if not viewer_pid +pid = $PROCESS_ID +viewer_pid = + fork do + view(infile, mode) + # If xdvi/evince exits, this program should exit too. + puts "#{PROGRAM}: viewer exited, so will I!" + Process.kill("TERM", pid) + end # Handle signals. ["INT", "TERM", "QUIT"].each do |sig| @@ -180,13 +187,6 @@ view(infile, mode) if not viewer_pid end end -# If xdvi/evince exits, this program should exit too. -Signal.trap("CLD") do - puts "#{PROGRAM}: viewer exited, so will I!" - clean(infile) - exit -end - ## Main event loop # Add input file with dependancies to the watch list and start event loop.