]> git.ipfire.org Git - pakfire.git/blobdiff - python/pakfire/chroot.py
Add cgroup support.
[pakfire.git] / python / pakfire / chroot.py
index c620fdb8cf1514ecdfae5df8b71f211143304ba5..521759b10e023f9699c170bd6e6e5da944d8aaac 100644 (file)
@@ -79,7 +79,7 @@ def logOutput(fds, logger, returnOutput=1, start=0, timeout=0):
        return output
 
 
-def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True, returnOutput=0, personality=None, logger=None, env=None, *args, **kargs):
+def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True, returnOutput=0, personality=None, logger=None, env=None, cgroup=None, *args, **kargs):
        # Save the output of command
        output = ""
 
@@ -93,8 +93,6 @@ def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True
                logger.debug("Executing command: %s in %s" % (command, chrootPath or "/"))
 
        try:
-               child = None
-
                # Create new child process
                child = subprocess.Popen(
                        command,
@@ -107,6 +105,10 @@ def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True
                        env=env
                )
 
+               # If cgroup is given, attach the subprocess.
+               if cgroup:
+                       cgroup.attach_task(child.pid)
+
                # use select() to poll for output so we dont block
                output = logOutput([child.stdout, child.stderr], logger, returnOutput, start, timeout)