Skip to content

Commit ac2cdee

Browse files
authored
Merge pull request #1999 from MatthewLavine/main
linux: resolve actual executable path for Flatpak processes
2 parents 008c621 + 2cc9321 commit ac2cdee

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Process.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,29 @@ void Process_makeCommandStr(Process* this, const Settings* settings) {
346346
}
347347
if (matchLen) {
348348
cmdlineBasenameLen = exeBasenameLen;
349+
} else if (this->cmdline) {
350+
/* Strip /proc pseudo-paths from merged command */
351+
#define PATH_PROC_EXE_SELF "/proc/self/exe"
352+
#define PATH_PROC_EXE_SELF_LEN (sizeof(PATH_PROC_EXE_SELF)-1)
353+
#define PATH_PROC_EXE_THREAD "/proc/thread-self/exe"
354+
#define PATH_PROC_EXE_THREAD_LEN (sizeof(PATH_PROC_EXE_THREAD)-1)
355+
356+
const size_t cmdlineLen = strlen(this->cmdline);
357+
const char sep_self = cmdlineLen >= PATH_PROC_EXE_SELF_LEN ? this->cmdline[PATH_PROC_EXE_SELF_LEN] : 0;
358+
const char sep_thread = cmdlineLen >= PATH_PROC_EXE_THREAD_LEN ? this->cmdline[PATH_PROC_EXE_THREAD_LEN] : 0;
359+
360+
if (String_startsWith(this->cmdline, PATH_PROC_EXE_SELF) &&
361+
(sep_self == '\0' || sep_self == ' ' || sep_self == '\n')) {
362+
matchLen = PATH_PROC_EXE_SELF_LEN;
363+
} else if (String_startsWith(this->cmdline, PATH_PROC_EXE_THREAD) &&
364+
(sep_thread == '\0' || sep_thread == ' ' || sep_thread == '\n')) {
365+
matchLen = PATH_PROC_EXE_THREAD_LEN;
366+
}
367+
368+
#undef PATH_PROC_EXE_THREAD
369+
#undef PATH_PROC_EXE_SELF_LEN
370+
#undef PATH_PROC_EXE_SELF
371+
#undef PATH_PROC_EXE_THREAD_LEN
349372
}
350373
}
351374

0 commit comments

Comments
 (0)