From f6a1c73125bd59598c63f0f8388ec8c7f441bfc7 Mon Sep 17 00:00:00 2001 From: BigfootACA Date: Sun, 21 Jul 2024 17:17:24 +0800 Subject: [PATCH] builder: lib: context.py: add multiple cgroup supports Signed-off-by: BigfootACA --- builder/build/filesystem.py | 4 +++- builder/lib/context.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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)