diff --git a/Process.c b/Process.c index 4f4b25f3b..80c9090c4 100644 --- a/Process.c +++ b/Process.c @@ -321,6 +321,27 @@ void Process_makeCommandStr(Process* this, const Settings* settings) { assert(cmdlineBasenameStart >= 0); assert(cmdlineBasenameStart <= (int)strlen(cmdline)); + int exeLen = 0; + int exeBasenameOffset = 0; + int exeBasenameLen = 0; + int matchLen = 0; + if (procExe) { + exeLen = strlen(procExe); + exeBasenameOffset = this->procExeBasenameOffset; + exeBasenameLen = exeLen - exeBasenameOffset; + + assert(exeBasenameOffset >= 0); + assert(exeBasenameOffset <= (int)strlen(procExe)); + + if (this->cmdline) { + matchLen = matchCmdlinePrefixWithExeSuffix(this->cmdline, cmdlineBasenameStart, procExe, exeBasenameOffset, exeBasenameLen); + } + if (matchLen) { + cmdlineBasenameStart = matchLen - exeBasenameLen; + cmdlineBasenameEnd = matchLen; + } + } + if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */ if ((showMergedCommand || (Process_isUserlandThread(this) && showThreadNames)) && procComm && strlen(procComm)) { /* set column to or prefix it with comm */ if (strncmp(cmdline + cmdlineBasenameStart, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) { @@ -350,13 +371,6 @@ void Process_makeCommandStr(Process* this, const Settings* settings) { return; } - int exeLen = strlen(this->procExe); - int exeBasenameOffset = this->procExeBasenameOffset; - int exeBasenameLen = exeLen - exeBasenameOffset; - - assert(exeBasenameOffset >= 0); - assert(exeBasenameOffset <= (int)strlen(procExe)); - bool haveCommInExe = false; if (procExe && procComm && (!Process_isUserlandThread(this) || showThreadNames)) { haveCommInExe = strncmp(procExe + exeBasenameOffset, procComm, TASK_COMM_LEN - 1) == 0; @@ -395,8 +409,6 @@ void Process_makeCommandStr(Process* this, const Settings* settings) { haveCommInCmdline = (!Process_isUserlandThread(this) || showThreadNames) && findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commEnd); } - int matchLen = matchCmdlinePrefixWithExeSuffix(cmdline, cmdlineBasenameStart, procExe, exeBasenameOffset, exeBasenameLen); - bool haveCommField = false; if (!haveCommInExe && !haveCommInCmdline && procComm && (!Process_isUserlandThread(this) || showThreadNames)) {