From 44257b7edef394e0d3a0e684a49160831b04f1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 30 May 2024 09:58:06 +0800 Subject: [PATCH] Shell: don't try to get arg1 if python was executed without extra args --- src/common/processing_linux.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 24ae675b8..ac4ee2b9f 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -166,15 +166,16 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons do arg0++; while (*arg0 == '\0'); assert(arg0 < procArgs2 + len); + if (argc > 1) { // #977 - char* p = (char*) strrchr(arg0, '/'); + const char* p = strrchr(arg0, '/'); if (p) - { p++; - if (ffStrStartsWithIgnCase(p, "python")) // /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python /Users/carter/.local/bin/xonsh - arg0 = p + strlen(p) + 1; - } + else + p = arg0; + if (ffStrStartsWithIgnCase(p, "python")) // /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python /Users/carter/.local/bin/xonsh + arg0 = p + strlen(p) + 1; } if (*arg0 == '-') arg0++; // Login shells @@ -221,12 +222,12 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons { char* p = (char*) memrchr(args, '/', arg0Len); if (p) - { p++; - if (ffStrStartsWith(p, "python")) // /usr/local/bin/python3.9 /home/carter/.local/bin/xonsh - { - arg0 += arg0Len + 1; - } + else + p = arg0; + if (ffStrStartsWith(p, "python")) // /usr/local/bin/python3.9 /home/carter/.local/bin/xonsh + { + arg0 += arg0Len + 1; } } if (arg0[0] == '-') arg0++;