diff options
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/cgroup.py | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/examples/cgroup.py b/examples/cgroup.py index 0c52efb..baacf35 100755 --- a/examples/cgroup.py +++ b/examples/cgroup.py @@ -78,17 +78,16 @@ def start_transient_unit_with_ravel(pid: int) -> None: def main() -> None: mycgroup = get_cgroup() - mycgroupdir = pathlib.Path("/sys/fs/cgroup") / mycgroup.relative_to("/") - if not os.access(mycgroupdir, os.W_OK): + if not os.access( + pathlib.Path("/sys/fs/cgroup") / mycgroup.relative_to("/"), + os.W_OK, + ): # For some shells - notably from graphical desktop environments, the # hiearchy is immediatly writeable. For others, we may create a scope # unit. if ravel is not None: start_transient_unit_with_ravel(os.getpid()) mycgroup = get_cgroup() - mycgroupdir = pathlib.Path( - "/sys/fs/cgroup" - ) / mycgroup.relative_to("/") else: # Re-execute ourselves via systemd-run. if ( @@ -111,23 +110,7 @@ def main() -> None: | linuxnamespaces.CloneFlags.NEWNS | linuxnamespaces.CloneFlags.NEWCGROUP, ) - cgroupfd = linuxnamespaces.open_tree( - mycgroupdir, - linuxnamespaces.OpenTreeFlags.OPEN_TREE_CLONE - | linuxnamespaces.OpenTreeFlags.AT_RECURSIVE, - ) - linuxnamespaces.mount("tmpfs", "/sys", "tmpfs", data="mode=0755") - os.mkdir("/sys/fs") - os.mkdir("/sys/fs/cgroup") - linuxnamespaces.mount( - "tmpfs", - "/sys", - "tmpfs", - linuxnamespaces.MountFlags.fromstr("remount,ro,noexec,nosuid,nodev"), - "mode=0755", - ) - linuxnamespaces.move_mount(cgroupfd, "/sys/fs/cgroup") - cgroupfd.close() + linuxnamespaces.populate_sys("/", "/", mycgroup) os.execlp(os.environ["SHELL"], os.environ["SHELL"]) |