chiark / gitweb /
close spurious fds in child after forking; debug on entry to cleanup
authorIan Jackson <ian@anarres>
Wed, 14 Feb 2007 12:16:34 +0000 (12:16 +0000)
committerIan Jackson <ian@anarres>
Wed, 14 Feb 2007 12:16:34 +0000 (12:16 +0000)
virt-subproc/VirtSubproc.py
virt-subproc/adt-virt-chroot
virt-subproc/adt-virt-xenlvm

index bc9af88100d8463669a6cba7d684628b1f2efed7..192e7297973a2b6405807e6958b5f012a9ff38c0 100644 (file)
@@ -64,9 +64,12 @@ def cmd_close(c, ce):
        if not downtmp: bomb("`close' when not open")
        cleanup()
 
+def preexecfn():
+       caller.hook_forked_inchild()
+
 def execute_raw(what, instr, *popenargs, **popenargsk):
        debug(" ++ %s" % string.join(popenargs[0]))
-       sp = subprocess.Popen(*popenargs, **popenargsk)
+       sp = subprocess.Popen(preexec_fn=preexecfn, *popenargs, **popenargsk)
        if instr is None: popenargsk['stdin'] = devnull_read
        (out, err) = sp.communicate(instr)
        if err: bomb("%s unexpectedly produced stderr output `%s'" %
@@ -186,7 +189,6 @@ def copyupdown(c, ce, upp):
        localfd = None
        deststdout = devnull_read
        srcstdin = devnull_read
-       preexecfns = [None, None]
        if not dirsp:
                modestr = ''
                if upp:
@@ -231,11 +233,12 @@ def copyupdown(c, ce, upp):
        subprocs = [None,None]
        debug(" +< %s" % string.join(cmdls[0]))
        subprocs[0] = subprocess.Popen(cmdls[0], stdin=srcstdin,
-                       stdout=subprocess.PIPE, preexec_fn=preexecfns[0])
+                       stdout=subprocess.PIPE, preexec_fn=preexecfn)
        debug(" +> %s" % string.join(cmdls[1]))
        subprocs[1] = subprocess.Popen(cmdls[1], stdin=subprocs[0].stdout,
-                       stdout=deststdout, preexec_fn=preexecfns[1])
+                       stdout=deststdout, preexec_fn=preexecfn)
        for sdn in [1,0]:
+               debug(" +"+"<>"[sdn]+"?");
                status = subprocs[sdn].wait()
                if status: bomb("%s %s failed, status %d" %
                        (wh, ['source','destination'][sdn], status))
@@ -260,6 +263,7 @@ def command():
 
 def cleanup():
        global downtmp, cleaning
+       debug("cleanup...");
        cleaning = True
        if downtmp: caller.hook_cleanup()
        cleaning = False
index 4ec079ca405de047a2bd44e64856a15f3377a036..5fdfe262fd9373f3d9ca1a52503fd1318e54f8f2 100755 (executable)
@@ -75,6 +75,9 @@ def hook_open():
 def hook_cleanup():
        vsp.execute('rm -rf --', [downtmp], downp=True)
 
+def hook_forked_inchild():
+       pass
+
 def hook_capabilities():
        return capabilities
 
index dedf7fe7040c425607bd4fdf0e225ba774880361..a4a1ec5032d1d38780d0b53b0ee6bdad1d8e38ee 100755 (executable)
@@ -105,6 +105,11 @@ def do_close():
        withholder = None
        if rc: bomb("with-testbed failed when closing/resetting, code %d" % rc)
 
+def hook_forked_inchild():
+       if withholder is not None:
+               withholder.stdin.close()
+               withholder.stdout.close()
+
 def hook_open():
        hook_cleanup()
        do_open()