diff options
author | Alon Levy <alevy@redhat.com> | 2013-09-02 17:38:45 +0300 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2013-10-14 12:47:14 +0300 |
commit | 9f4e429c13fd6e56a200d58c735b37d7eeb671fe (patch) | |
tree | df3b98f313daa585ccc181fbdd96fa4e397c47cf | |
parent | a6d00dccbf8257c0d225e0886cb2d4a8ba60fe38 (diff) |
Xspice: use subprocess.Popen, nicer cleanup of files/processes
Signed-off-by: Alon Levy <alevy@redhat.com>
-rwxr-xr-x | scripts/Xspice | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/scripts/Xspice b/scripts/Xspice index bfa9197..b50ea46 100755 --- a/scripts/Xspice +++ b/scripts/Xspice @@ -22,6 +22,7 @@ import sys import tempfile import atexit import time +from subprocess import Popen def which(x): for p in os.environ['PATH'].split(':'): @@ -124,13 +125,28 @@ def error(msg, exit_code=1): if not args.xorg: error("Xorg missing") +cleanup_files = [] +cleanup_processes = [] + def cleanup(): - if os.path.isfile(cf.name + ".log"): - os.remove(cf.name + ".log") + for f in cleanup_files: + if os.path.isfile(f): + os.remove(f) + for p in cleanup_processes: + p.kill() + for p in cleanup_processes: + p.wait() + +def launch(*args, **kw): + p = Popen(*args, **kw) + cleanup_processes.append(p) + return p + +atexit.register(cleanup) if args.auto: - atexit.register(cleanup) cf = tempfile.NamedTemporaryFile(prefix="Xspice-", delete=True) + cleanup_files.append(cf.name + ".log") args.config = cf.name xorg_args = [ '-logfile', cf.name + ".log" ] + xorg_args cf.write(""" @@ -206,10 +222,10 @@ if cgdb and args.cgdb: # This is currently mandatory; the driver cannot survive a reset xorg_args = [ '-noreset' ] + xorg_args -xpid = os.spawnv(os.P_NOWAIT, args.xorg, exec_args + xorg_args) +xorg = launch(executable=args.xorg, args=exec_args + xorg_args) time.sleep(2) -retpid,rc = os.waitpid(xpid, os.WNOHANG) +retpid,rc = os.waitpid(xorg.pid, os.WNOHANG) if retpid != 0: print "Error: X server is not running" else: @@ -219,7 +235,7 @@ else: os.spawnlpe(os.P_NOWAIT, args.xsession, environ) try: - os.waitpid(xpid, 0) + xorg.wait() except KeyboardInterrupt: # Catch Ctrl-C as that is the common way of ending this script print "Keyboard Interrupt" |