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/<pid>/com vs /proc/<pid>/exe

Use exe(), which contains the full executable path to fix this.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata 2024-09-06 15:50:23 +02:00
parent f90b847cb1
commit 65d18fce4c

View File

@ -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()