]> arthur.barton.de Git - bup.git/commitdiff
main: even more fixes for signal handling.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 14 Mar 2010 05:55:08 +0000 (00:55 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 14 Mar 2010 05:55:08 +0000 (00:55 -0500)
If the child doesn't die after the first SIGINT and the user presses ctrl-c
one more time, the main bup process would die instead of forwarding it on to
the child.  That's no good; we actually have to loop forwarding signals
until the child is really good and dead.

And if the child refuses to die, well, he's the one with the bug, not
main.py.  So main.py should stay alive too in the name of not losing track
of things.

main.py

diff --git a/main.py b/main.py
index 50eb24454154b216287563e1ad5c773d27bb24b9..941242ef4bbb9f6962c930346f916a1ec8bcfd01 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -120,22 +120,26 @@ signal.signal(signal.SIGINT, handler)
 
 ret = 95
 p = None
-killsig = signal.SIGTERM
 try:
     try:
         p = subprocess.Popen([subpath(subcmd)] + argv[2:],
                              stdout=outf, stderr=errf, preexec_fn=force_tty)
-        ret = p.wait()
+        while 1:
+            # if we get a signal while waiting, we have to keep waiting, just
+            # in case our child doesn't die.
+            try:
+                ret = p.wait()
+                break
+            except SigException, e:
+                log('\nbup: %s\n' % e)
+                os.kill(p.pid, e.signum)
+                ret = 94
     except OSError, e:
         log('%s: %s\n' % (subpath(subcmd), e))
         ret = 98
-    except SigException, e:
-        log('\nbup: %s\n' % e)
-        killsig = e.signum
-        ret = 94
 finally:
     if p and p.poll() == None:
-        os.kill(p.pid, killsig)
+        os.kill(p.pid, signal.SIGTERM)
         p.wait()
     if n:
         n.stdin.close()