]> arthur.barton.de Git - bup.git/commitdiff
cmd/daemon: close file descriptors correctly in parent process.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 13 Feb 2011 10:29:59 +0000 (02:29 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 13 Feb 2011 13:02:21 +0000 (05:02 -0800)
The client wasn't getting disconnected when the server died, because the
daemon was still hanging on to its copy of the original socket, due to some
misplaced os.dup() calls.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
cmd/daemon-cmd.py

index b83669acc1808c13482eb5caba868c731a2a1c6f..c46f411c25c1956e2ac75de6cc901a998552c32d 100755 (executable)
@@ -49,10 +49,16 @@ try:
         [rl,wl,xl] = select.select(socks, [], [], 60)
         for l in rl:
             s, src = l.accept()
-            log("Socket accepted connection from %s\n" % (src,))
-            sp = subprocess.Popen([path.exe(), 'mux', '--', 'server'] + extra,
-                                  stdin=os.dup(s.fileno()), stdout=os.dup(s.fileno()))
-            s.close()
+            try:
+                log("Socket accepted connection from %s\n" % (src,))
+                fd1 = os.dup(s.fileno())
+                fd2 = os.dup(s.fileno())
+                sp = subprocess.Popen([path.exe(), 'mux', '--', 'server']
+                                      + extra, stdin=fd1, stdout=fd2)
+            finally:
+                s.close()
+                os.close(fd1)
+                os.close(fd2)
 finally:
     for l in socks:
         l.shutdown(socket.SHUT_RDWR)