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.
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,