summaryrefslogtreecommitdiffstats
path: root/pyfirstaidkit/utils.py
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2008-02-28 13:10:00 +0100
committerMartin Sivak <msivak@redhat.com>2008-02-28 13:10:00 +0100
commit70efb5c67c477c8b9a801686878f158b0cbdb262 (patch)
treed1bf6072c7827fb1e7e0dcb456398a0d19545efa /pyfirstaidkit/utils.py
parent92f53d10c28dca52f02e7a2b9c7a90cfda5d43b4 (diff)
downloadfirstaidkit-70efb5c67c477c8b9a801686878f158b0cbdb262.tar.gz
firstaidkit-70efb5c67c477c8b9a801686878f158b0cbdb262.tar.xz
firstaidkit-70efb5c67c477c8b9a801686878f158b0cbdb262.zip
Update the spawnvch function to use the subprocess module
Diffstat (limited to 'pyfirstaidkit/utils.py')
-rw-r--r--pyfirstaidkit/utils.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/pyfirstaidkit/utils.py b/pyfirstaidkit/utils.py
index f23e33f..5893985 100644
--- a/pyfirstaidkit/utils.py
+++ b/pyfirstaidkit/utils.py
@@ -19,20 +19,23 @@ import os
import sys
import subprocess
-def spawnvch(executable, params, chroot): #returns errorcode
- """Simpliest chroot modification of spawn
+def chroot_func(dir):
+ def do_chroot():
+ return os.chroot(dir)
+
+ if os.path.abspath(dir)=="/":
+ return lambda: True
+ else:
+ return do_chroot
+
+def spawnvch(executable, args, chroot, env = None):
+ """Use Popen to launch program in chroot
executable - path to binary to execute (in chroot!)
- params - it's parameters
+ args - it's parameters
chroot - directory to chroot to
-Returns the error code returned by process"""
+Returns the subprocess.Popen object"""
- pid = os.fork()
- if pid==0: #child
- os.chroot(chroot)
- os.execv(executable, params)
- sys.exit(1)
- else:
- res = os.waitpid(pid, 0)
- return os.WEXITSTATUS(res)
+ return subprocess.Popen(executable = executable, args = args, preexec_fn = chroot_func(chroot), env = env,
+ stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)