From 65d18fce4c11bd5364694656680fcf0238a42970 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Fri, 6 Sep 2024 15:50:23 +0200 Subject: [PATCH] fix(activate): use exe instead of comm for parent shell detection Currently, we are using psutil.Process().name(), which includes the command as entered on the command line. This becomes an issue if the export script is initiated within another script. run.sh #!/usr/bin/bash . ./export.sh In this case the activate script will see `run.sh` instead of bash. /proc//com vs /proc//exe Use exe(), which contains the full executable path to fix this. Signed-off-by: Frantisek Hrbata --- tools/export_utils/activate_venv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/export_utils/activate_venv.py b/tools/export_utils/activate_venv.py index bee77167a7..8949943afc 100644 --- a/tools/export_utils/activate_venv.py +++ b/tools/export_utils/activate_venv.py @@ -107,7 +107,7 @@ def detect_shell(args: Any) -> str: detected_shell_name = '' while True: parent_pid = psutil.Process(current_pid).ppid() - parent_name = psutil.Process(parent_pid).name() + parent_name = os.path.basename(psutil.Process(parent_pid).exe()) if not parent_name.lower().startswith('python'): detected_shell_name = parent_name conf.DETECTED_SHELL_PATH = psutil.Process(parent_pid).exe()