From 8dc4f77f42abf32e5d26bbe751d439eaa49e64bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 18 Feb 2025 09:17:55 +0800 Subject: [PATCH] Shell (Haiku): fix arg0 detection --- src/common/processing_linux.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index a26e53848..934a1c01b 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -319,17 +319,20 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons team_info info; if (get_team_info(pid, &info) == B_OK) { - // This is tricky. info.args is not encoded, so that we don't know if - // a whitespace in args is part of the file path or an argument separator + // This is tricky. Paths in info.args are not quoted, so that we don't know + // if a whitespace in args is part of the file path or an argument separator if (info.argc == 1) ffStrbufSetS(exe, info.args); else { - int argc = info.argc; - for (const char* p = info.args; (p = strchr(p, ' ')); ++p) + // args = "/bin/bash -l" + // argc = 2 + int argc = info.argc - 1; // 1 + const char* arg0End = strchr(p, ' '); // " -l" + for (const char* p = arg0End + 1; (p = strchr(p, ' ')); ++p) --argc; if (argc == 1) - ffStrbufSetS(exe, info.args); + ffStrbufSetNS(exe, info.args, arg0End - info.args /* /bin/bash */); } } }