diff --git a/builder/build/filesystem.py b/builder/build/filesystem.py index 557620c..0a29261 100644 --- a/builder/build/filesystem.py +++ b/builder/build/filesystem.py @@ -5,6 +5,7 @@ from builder.lib import utils from builder.component import user from builder.lib.config import ArchBuilderConfigError from builder.lib.context import ArchBuilderContext +from builder.lib.cgroup import CGroup log = getLogger(__name__) @@ -14,6 +15,7 @@ def chroot_run( cwd: str = None, env: dict = None, stdin: str | bytes = None, + cgroup: CGroup = None, ) -> int: """ Chroot into rootfs and run programs @@ -24,7 +26,7 @@ def chroot_run( path = ctx.get_rootfs() args = ["chroot", path] args.extend(utils.parse_cmd_args(cmd)) - return ctx.run_external(args, cwd, env, stdin) + return ctx.run_external(args, cwd, env, stdin, cgroup) def proc_mkdir(ctx: ArchBuilderContext, file: dict, path: str): diff --git a/builder/lib/context.py b/builder/lib/context.py index 0802408..3d23ac5 100644 --- a/builder/lib/context.py +++ b/builder/lib/context.py @@ -142,7 +142,8 @@ class ArchBuilderContext: /, cwd: str = None, env: dict = None, - stdin: str | bytes = None + stdin: str | bytes = None, + cgroup: CGroup = None, ) -> int: """ Run external command @@ -153,7 +154,8 @@ class ArchBuilderContext: log.debug(f"running external command {argv}") fstdin = None if stdin is None else PIPE proc = Popen(args, cwd=cwd, env=env, stdin=fstdin) - self.cgroup.add_pid(proc.pid) + if cgroup is None: cgroup = self.cgroup + cgroup.add_pid(proc.pid) if stdin: if type(stdin) is str: stdin = stdin.encode() proc.stdin.write(stdin)