Include comm before cmdline if exe could not be read, but comm mismatches basename from cmdline

Also highlights entries where exe was marked deleted
This commit is contained in:
Benny Baumann 2020-11-23 22:55:56 +01:00 committed by BenBE
parent ec36c5ccf8
commit 21e3063e2e
3 changed files with 35 additions and 2 deletions

View File

@ -399,16 +399,33 @@ void LinuxProcess_makeCommandStr(Process* this) {
int cmdlineBasenameOffset = lp->procCmdlineBasenameOffset; int cmdlineBasenameOffset = lp->procCmdlineBasenameOffset;
if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */ if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */
if (showMergedCommand && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */
if (strncmp(cmdline + cmdlineBasenameOffset, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) {
mc->commStart = 0;
mc->commEnd = strlen(procComm);
str = stpcpy(str, procComm);
mc->sep1 = str - strStart;
str = stpcpy(str, SEPARATOR);
}
}
if (showProgramPath) { if (showProgramPath) {
(void) stpcpyWithNewlineConversion(strStart, cmdline); (void) stpcpyWithNewlineConversion(str, cmdline);
mc->baseStart = cmdlineBasenameOffset; mc->baseStart = cmdlineBasenameOffset;
mc->baseEnd = lp->procCmdlineBasenameEnd; mc->baseEnd = lp->procCmdlineBasenameEnd;
} else { } else {
(void) stpcpyWithNewlineConversion(strStart, cmdline + cmdlineBasenameOffset); (void) stpcpyWithNewlineConversion(str, cmdline + cmdlineBasenameOffset);
mc->baseStart = 0; mc->baseStart = 0;
mc->baseEnd = lp->procCmdlineBasenameEnd - cmdlineBasenameOffset; mc->baseEnd = lp->procCmdlineBasenameEnd - cmdlineBasenameOffset;
} }
if (mc->sep1) {
mc->baseStart += str - strStart - SEPARATOR_LEN + 1;
mc->baseEnd += str - strStart - SEPARATOR_LEN + 1;
}
return; return;
} }
@ -520,6 +537,9 @@ static void LinuxProcess_writeCommand(const Process* this, int attr, int baseAtt
bool highlightBaseName = this->settings->highlightBaseName; bool highlightBaseName = this->settings->highlightBaseName;
if(lp->procExeDeleted)
baseAttr = CRT_colors[FAILED_READ];
RichString_append(str, attr, lp->mergedCommand.str); RichString_append(str, attr, lp->mergedCommand.str);
if (lp->mergedCommand.commEnd) { if (lp->mergedCommand.commEnd) {
@ -716,6 +736,8 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
case PROC_EXE: { case PROC_EXE: {
if (lp->procExe) { if (lp->procExe) {
attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_BASENAME : PROCESS_BASENAME]; attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_BASENAME : PROCESS_BASENAME];
if (lp->procExeDeleted)
attr = CRT_colors[FAILED_READ];
xSnprintf(buffer, n, "%-15.15s ", lp->procExe + lp->procExeBasenameOffset); xSnprintf(buffer, n, "%-15.15s ", lp->procExe + lp->procExeBasenameOffset);
} else { } else {
attr = CRT_colors[PROCESS_SHADOW]; attr = CRT_colors[PROCESS_SHADOW];

View File

@ -130,6 +130,7 @@ typedef struct LinuxProcess_ {
char *procExe; char *procExe;
int procExeLen; int procExeLen;
int procExeBasenameOffset; int procExeBasenameOffset;
bool procExeDeleted;
int procCmdlineBasenameOffset; int procCmdlineBasenameOffset;
int procCmdlineBasenameEnd; int procCmdlineBasenameEnd;
LinuxProcessMergedCommand mergedCommand; LinuxProcessMergedCommand mergedCommand;

View File

@ -1051,12 +1051,22 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
; ;
lp->procExeBasenameOffset = amtRead + 1; lp->procExeBasenameOffset = amtRead + 1;
lp->mergedCommand.exeChanged = true; lp->mergedCommand.exeChanged = true;
const char* deletedMarker = " (deleted)";
if (strlen(lp->procExe) > strlen(deletedMarker)) {
lp->procExeDeleted = String_eq(lp->procExe + strlen(lp->procExe) - strlen(deletedMarker), deletedMarker);
if (lp->procExeDeleted && strlen(lp->procExe) - strlen(deletedMarker) == 1 && lp->procExe[0] == '/') {
lp->procExeBasenameOffset = 0;
}
}
} }
} else if (lp->procExe) { } else if (lp->procExe) {
free(lp->procExe); free(lp->procExe);
lp->procExe = NULL; lp->procExe = NULL;
lp->procExeLen = 0; lp->procExeLen = 0;
lp->procExeBasenameOffset = 0; lp->procExeBasenameOffset = 0;
lp->procExeDeleted = false;
lp->mergedCommand.exeChanged = true; lp->mergedCommand.exeChanged = true;
} }