mirror of
https://github.com/BigfootACA/arch-image-builder.git
synced 2024-09-21 12:02:48 +08:00
builder: lib: context.py: add multiple cgroup supports
Signed-off-by: BigfootACA <bigfoot@classfun.cn>
This commit is contained in:
parent
c3297b2aa0
commit
f6a1c73125
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user