chiark / gitweb /
: ${:=} not ${:=}
[autopkgtest.git] / virt-subproc / VirtSubproc.py
index 6c17f52d538550a22e911943d4b9bcf3230e3d34..bbe0521d6e4a3ca705e4aa0a7b231aff79a6ad8d 100644 (file)
@@ -65,7 +65,8 @@ def cmdnumargs(c, ce, nargs=0, noptargs=0):
 
 def cmd_capabilities(c, ce):
        cmdnumargs(c, ce)
-       return caller.hook_capabilities() + ['execute-debug']
+       return caller.hook_capabilities() + ['execute-debug',
+               'print-execute-command']
 
 def cmd_quit(c, ce):
        cmdnumargs(c, ce)
@@ -76,6 +77,16 @@ def cmd_close(c, ce):
        if not downtmp: bomb("`close' when not open")
        cleanup()
 
+def cmd_print_execute_command(c, ce):
+       cmdnumargs(c, ce)
+       if not downtmp: bomb("`print-execute-command' when not open")
+       if hasattr(caller,'hook_callerexeccmd'):
+               (cl,kvl) = caller.hook_callerexeccmd()
+       else:
+               cl = down
+               kvl = ['shstring']
+       return [','.join(map(urllib.quote, cl))] + kvl
+
 def preexecfn():
        caller.hook_forked_inchild()
 
@@ -136,7 +147,7 @@ def down_python_script(gobody, functions=''):
                        "import os\n"
                        "def setfd(fd,fnamee,write,mode=0666):\n"
                        "       fname = urllib.unquote(fnamee)\n"
-                       "       if write: rw = os.O_WRONLY|os.O_CREAT\n"
+                       "       if write: rw = os.O_WRONLY|os.O_CREAT|os.O_TRUNC\n"
                        "       else: rw = os.O_RDONLY\n"
                        "       nfd = os.open(fname, rw, mode)\n"
                        "       if fd >= 0: os.dup2(nfd,fd)\n"
@@ -315,7 +326,8 @@ def command():
        c = map(urllib.unquote, ce)
        if not c: bomb('empty commands are not permitted')
        debug('executing '+string.join(ce))
-       try: f = globals()['cmd_'+c[0]]
+       c_lookup = c[0].replace('-','_')
+       try: f = globals()['cmd_'+c_lookup]
        except KeyError: bomb("unknown command `%s'" % ce[0])
        try:
                r = f(c, ce)
@@ -325,9 +337,16 @@ def command():
                r = fc.e
        print string.join(r)
 
+signal_list = [        signal.SIGHUP, signal.SIGTERM,
+               signal.SIGINT, signal.SIGPIPE ]
+
+def sethandlers(f):
+       for signum in signal_list: signal.signal(signum, f)
+
 def cleanup():
        global downtmp, cleaning
        debug("cleanup...");
+       sethandlers(signal.SIG_DFL)
        cleaning = True
        if downtmp: caller.hook_cleanup()
        cleaning = False
@@ -354,12 +373,7 @@ def error_cleanup():
 def prepare():
        global downtmp, cleaning
        downtmp = None
-       signal_list = [ signal.SIGHUP, signal.SIGTERM,
-                       signal.SIGINT, signal.SIGPIPE ]
-       def sethandlers(f):
-               for signum in signal_list: signal.signal(signum, f)
        def handler(sig, *any):
-               sethandlers(signal.SIG_DFL)
                cleanup()
                os.kill(os.getpid(), sig)
        sethandlers(handler)