From: Rob Browning Date: Thu, 13 Nov 2014 19:11:49 +0000 (-0600) Subject: on: always catch our exceptions X-Git-Tag: 0.27-rc1~17 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=ca5b6b7e4a1167e42fae808dc5d89fed82b64639 on: always catch our exceptions Thanks to Gabriel Filion for reporting the issue. Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/cmd/on-cmd.py b/cmd/on-cmd.py index fca058c..60759b6 100755 --- a/cmd/on-cmd.py +++ b/cmd/on-cmd.py @@ -23,38 +23,44 @@ def handler(signum, frame): signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGINT, handler) -sp = None -p = None -ret = 99 +try: + sp = None + p = None + ret = 99 -hp = extra[0].split(':') -if len(hp) == 1: - (hostname, port) = (hp[0], None) -else: - (hostname, port) = hp + hp = extra[0].split(':') + if len(hp) == 1: + (hostname, port) = (hp[0], None) + else: + (hostname, port) = hp -argv = extra[1:] -p = ssh.connect(hostname, port, 'on--server') + argv = extra[1:] + p = ssh.connect(hostname, port, 'on--server') + + try: + argvs = '\0'.join(['bup'] + argv) + p.stdin.write(struct.pack('!I', len(argvs)) + argvs) + p.stdin.flush() + sp = subprocess.Popen([path.exe(), 'server'], + stdin=p.stdout, stdout=p.stdin) + p.stdin.close() + p.stdout.close() + finally: + 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() + if sp: + sp.wait() + break + except SigException, e: + log('\nbup on: %s\n' % e) + os.kill(p.pid, e.signum) + ret = 84 +except SigException, e: + if ret == 0: + ret = 99 + log('\nbup on: %s\n' % e) -try: - argvs = '\0'.join(['bup'] + argv) - p.stdin.write(struct.pack('!I', len(argvs)) + argvs) - p.stdin.flush() - sp = subprocess.Popen([path.exe(), 'server'], - stdin=p.stdout, stdout=p.stdin) - p.stdin.close() - p.stdout.close() -finally: - 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() - if sp: - sp.wait() - break - except SigException, e: - log('\nbup on: %s\n' % e) - os.kill(p.pid, e.signum) - ret = 84 sys.exit(ret)