From c1766d1d3346d095ecb3664d74b9a590c897b455 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 4 Nov 2024 12:51:27 +0100 Subject: [PATCH] Don't put /usr/bin and /usr/sbin in front of extra search paths in $PATH Currently extra search paths don't get used because we always add /usr/bin and /usr/sbin earlier in $PATH. --- mkosi/run.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mkosi/run.py b/mkosi/run.py index 549f076a4..b8dc84b8c 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -565,22 +565,22 @@ def sandbox_cmd( home = None - cmdline += [ - "--setenv", - "PATH", - ":".join( - [ - *(["/scripts"] if scripts else []), - "/usr/bin", - "/usr/sbin", - *( - [s for s in os.environ["PATH"].split(":") if home and s.startswith(os.fspath(home))] - if tools != Path("/") - else [os.environ["PATH"]] - ), - ] - ), - ] + path = [] + if scripts: + path += ["/scripts"] + if tools != Path("/"): + path += [ + s + for s in os.environ["PATH"].split(":") + if s in ("/usr/bin", "/usr/sbin") or (home and s.startswith(os.fspath(home))) + ] + + # Make sure that /usr/bin and /usr/sbin are always in $PATH. + path += [s for s in ("/usr/bin", "/usr/sbin") if s not in path] + else: + path += os.environ["PATH"].split(":") + + cmdline += ["--setenv", "PATH", ":".join(path)] if scripts: cmdline += ["--ro-bind", scripts, "/scripts"]