From 1cc405648237561b15e101d025cc742595a50590 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 7 Jun 2023 14:01:42 +0200 Subject: [PATCH] clearer comments and conditions for resolving $PATH --- systemdspawner/systemd.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/systemdspawner/systemd.py b/systemdspawner/systemd.py index 36d1d83..02033ff 100644 --- a/systemdspawner/systemd.py +++ b/systemdspawner/systemd.py @@ -148,9 +148,14 @@ async def start_transient_service( # systemd-run does not use the unit's $PATH environment # to resolve relative paths. if not os.path.isabs(cmd[0]): - path = os.getenv("PATH", os.defpath) if environment_variables and "PATH" in environment_variables: + # if unit specifies a $PATH, use it path = environment_variables["PATH"] + else: + # search current process $PATH by default. + # this is the default behavior of shutil.which(path=None) + # but we still need the value for the error message + path = os.getenv("PATH", os.defpath) exe = cmd[0] abs_exe = shutil.which(exe, path=path) if not abs_exe: