]> arthur.barton.de Git - bup.git/commitdiff
on: always catch our exceptions
authorRob Browning <rlb@defaultvalue.org>
Thu, 13 Nov 2014 19:11:49 +0000 (13:11 -0600)
committerRob Browning <rlb@defaultvalue.org>
Wed, 14 Jan 2015 01:35:40 +0000 (19:35 -0600)
Thanks to Gabriel Filion for reporting the issue.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/on-cmd.py

index fca058c763c9c10082f0857b7b3d51c046cdd68b..60759b64a6d6d85332c489de8a81df04f6d57f94 100755 (executable)
@@ -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)