From: Avery Pennarun Date: Sun, 14 Mar 2010 05:55:08 +0000 (-0500) Subject: main: even more fixes for signal handling. X-Git-Tag: bup-0.12b~3 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=da300a19fbe9147bbe7414b9bf555c8e1a585309 main: even more fixes for signal handling. 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. --- diff --git a/main.py b/main.py index 50eb244..941242e 100755 --- 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()