mrrl

Minimal Reliable Reproducible Linux
git clone https://ccx.te2000.cz/git/mrrl
Log | Files | Refs | Submodules | README

commit 6b7088caf4f21f8301b800404e930b9804ff5587
parent 765c82af8208928dfb7915a48577ec9f3c9b3b5d
Author: ccx <ccx@te2000.cz>
Date:   Mon, 26 Feb 2024 16:21:16 +0000

Use lazy umount where necessary

Diffstat:
Mns_sandbox.py | 19+++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/ns_sandbox.py b/ns_sandbox.py @@ -25,11 +25,12 @@ CLONE_NEWTIME = 0x00000080 # New time namespace SYS_pivot_root = 155 -MNT_FORCE = 1 -MNT_DETACH = 2 -MNT_EXPIRE = 4 +MNT_FORCE = 1 +MNT_DETACH = 2 +MNT_EXPIRE = 4 UMOUNT_NOFOLLOW = 8 + class MountFlag(int, enum.Enum): """Mount flags.""" @@ -120,6 +121,7 @@ def c_path(path): def c_error(): return OSError(ctypes.get_errno(), os.strerror(ctypes.get_errno())) + def unshare(flags): if libc.unshare(flags) != 0: raise c_error() @@ -254,10 +256,7 @@ def pivot_and_umount(new_root, put_old, umount_list): pivot_root(new_root, put_old) os.chdir('/') # so we don't stand in the old root for mtp in umount_list: - try: - lazy_umount(mtp_prefix + mtp) - except OSError as exc: - sys.stderr.write(f'Error: failed to umount {mtp_prefix}{mtp} {exc}\n') + lazy_umount(mtp_prefix + mtp) def nonblock_cloexec(fd): @@ -433,7 +432,7 @@ class Settings: assert isinstance(self.root, pathlib.PosixPath) assert self.root.is_absolute() - assert self.root.is_dir() + assert self.root.is_dir(), self.root if self.untar is None: self._check_root() @@ -461,7 +460,7 @@ class Settings: vars=v, command=tuple(args.command), extra_mount=tuple(args.extra_mount) if args.extra_mount is not None else (), - drop_to=(int(env['UID']), int(env['GID'])) if args.mode == 'root' else None, + drop_to=(int(env['pthbs_uid']), int(env['pthbs_gid'])) if args.mode == 'root' else None, untar=args.untar and pathlib.PosixPath(args.untar), ) @@ -533,7 +532,7 @@ def root_sandbox_setup(settings): mount('sandbox_root', r, 'tmpfs', MountFlag.NOSUID) (r / 'oldroot').mkdir() subprocess.check_call( - ('tar', 'xpf', settings.untar.absolute()), + ('/bin/tar', 'xpf', settings.untar.absolute()), shell=False, cwd=r, )