]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Only use unshare to become root if we're actually going to use a scope
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 1 Aug 2024 14:35:36 +0000 (16:35 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 2 Aug 2024 07:32:04 +0000 (09:32 +0200)
If the relevant environment variables are not set, scope_cmd() will
return an empty list and we won't use a scope after all. In that case
we don't need to use unshare either to become root and can rely on our
own become_root() function so check whether we're actually going to use
a scope or not.

mkosi/qemu.py

index bd1ddcf3f7ef7074175217a1014dcea6c6daf94d..058cbc1d85d45fdc86c5cdc8646904da2e7523cf 100644 (file)
@@ -351,8 +351,9 @@ def start_virtiofsd(config: Config, directory: PathString, *, name: str, selinux
             gid = INVOKING_USER.gid if os.getgid() != INVOKING_USER.gid else None
             scope = scope_cmd(name=name, description=description, user=uid, group=gid)
         elif not uidmap and (os.getuid() == 0 or unshare_version() >= "2.38"):
-            runas = become_root_cmd()
             scope = scope_cmd(name=name, description=description)
+            if scope:
+                runas = become_root_cmd()
 
         with spawn(
             cmdline,