From: Daan De Meyer Date: Mon, 29 Jul 2024 18:28:02 +0000 (+0200) Subject: Only look at $USER if we can't find a user in /etc/passwd X-Git-Tag: v24.3~1^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33f712345831b468e6dea01e2705603c3b9bf6d2;p=thirdparty%2Fmkosi.git Only look at $USER if we can't find a user in /etc/passwd --- diff --git a/mkosi/user.py b/mkosi/user.py index 6dc72eaa4..2298de3c1 100644 --- a/mkosi/user.py +++ b/mkosi/user.py @@ -39,7 +39,16 @@ class INVOKING_USER: @classmethod @functools.lru_cache(maxsize=1) def name(cls) -> str: - return os.getenv("USER", pwd.getpwuid(cls.uid).pw_name) + try: + return pwd.getpwuid(cls.uid).pw_name + except KeyError: + if cls.uid == 0: + return "root" + + if not (user := os.getenv("USER")): + die(f"Could not find user name for UID {cls.uid}") + + return user @classmethod @functools.lru_cache(maxsize=1)