Merge branch 'show-thread-names-fix' of BenBE/htop

This commit is contained in:
Daniel Lange 2021-07-18 10:21:06 +02:00
commit 2fe4a6351e
2 changed files with 9 additions and 5 deletions

View File

@ -390,6 +390,7 @@ void Process_makeCommandStr(Process* this) {
bool showProgramPath = settings->showProgramPath; bool showProgramPath = settings->showProgramPath;
bool searchCommInCmdline = settings->findCommInCmdline; bool searchCommInCmdline = settings->findCommInCmdline;
bool stripExeFromCmdline = settings->stripExeFromCmdline; bool stripExeFromCmdline = settings->stripExeFromCmdline;
bool showThreadNames = settings->showThreadNames;
/* Nothing to do to (Re)Generate the Command string, if the process is: /* Nothing to do to (Re)Generate the Command string, if the process is:
* - a kernel thread, or * - a kernel thread, or
@ -409,6 +410,7 @@ void Process_makeCommandStr(Process* this) {
mc->prevPathSet == showProgramPath && mc->prevPathSet == showProgramPath &&
mc->prevCommSet == searchCommInCmdline && mc->prevCommSet == searchCommInCmdline &&
mc->prevCmdlineSet == stripExeFromCmdline && mc->prevCmdlineSet == stripExeFromCmdline &&
mc->prevShowThreadNames == showThreadNames &&
!mc->cmdlineChanged && !mc->cmdlineChanged &&
!mc->commChanged && !mc->commChanged &&
!mc->exeChanged !mc->exeChanged
@ -438,6 +440,7 @@ void Process_makeCommandStr(Process* this) {
mc->prevPathSet = showProgramPath; mc->prevPathSet = showProgramPath;
mc->prevCommSet = searchCommInCmdline; mc->prevCommSet = searchCommInCmdline;
mc->prevCmdlineSet = stripExeFromCmdline; mc->prevCmdlineSet = stripExeFromCmdline;
mc->prevShowThreadNames = showThreadNames;
/* Mark everything as unchanged */ /* Mark everything as unchanged */
mc->cmdlineChanged = false; mc->cmdlineChanged = false;
@ -496,7 +499,7 @@ void Process_makeCommandStr(Process* this) {
assert(cmdlineBasenameStart <= (int)strlen(cmdline)); assert(cmdlineBasenameStart <= (int)strlen(cmdline));
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 (showMergedCommand && showThreadNames && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */
if (strncmp(cmdline + cmdlineBasenameStart, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) { if (strncmp(cmdline + cmdlineBasenameStart, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) {
WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM);
str = stpcpy(str, procComm); str = stpcpy(str, procComm);
@ -520,7 +523,7 @@ void Process_makeCommandStr(Process* this) {
assert(exeBasenameOffset <= (int)strlen(procExe)); assert(exeBasenameOffset <= (int)strlen(procExe));
bool haveCommInExe = false; bool haveCommInExe = false;
if (procExe && procComm) { if (procExe && procComm && showThreadNames) {
haveCommInExe = strncmp(procExe + exeBasenameOffset, procComm, TASK_COMM_LEN - 1) == 0; haveCommInExe = strncmp(procExe + exeBasenameOffset, procComm, TASK_COMM_LEN - 1) == 0;
} }
@ -552,14 +555,14 @@ void Process_makeCommandStr(Process* this) {
/* Try to match procComm with procExe's basename: This is reliable (predictable) */ /* Try to match procComm with procExe's basename: This is reliable (predictable) */
if (searchCommInCmdline) { if (searchCommInCmdline) {
/* commStart/commEnd will be adjusted later along with cmdline */ /* commStart/commEnd will be adjusted later along with cmdline */
haveCommInCmdline = findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commEnd); haveCommInCmdline = showThreadNames && findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commEnd);
} }
int matchLen = matchCmdlinePrefixWithExeSuffix(cmdline, cmdlineBasenameStart, procExe, exeBasenameOffset, exeBasenameLen); int matchLen = matchCmdlinePrefixWithExeSuffix(cmdline, cmdlineBasenameStart, procExe, exeBasenameOffset, exeBasenameLen);
bool haveCommField = false; bool haveCommField = false;
if (!haveCommInExe && !haveCommInCmdline && procComm) { if (!haveCommInExe && !haveCommInCmdline && procComm && showThreadNames) {
WRITE_SEPARATOR; WRITE_SEPARATOR;
WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM);
str = stpcpy(str, procComm); str = stpcpy(str, procComm);
@ -579,7 +582,7 @@ void Process_makeCommandStr(Process* this) {
WRITE_SEPARATOR; WRITE_SEPARATOR;
} }
if (!haveCommInExe && haveCommInCmdline && !haveCommField) if (!haveCommInExe && haveCommInCmdline && !haveCommField && showThreadNames)
WRITE_HIGHLIGHT(commStart, commEnd - commStart, commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM); WRITE_HIGHLIGHT(commStart, commEnd - commStart, commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM);
/* Display cmdline if it hasn't been consumed by procExe */ /* Display cmdline if it hasn't been consumed by procExe */

View File

@ -87,6 +87,7 @@ typedef struct ProcessMergedCommand_ {
bool prevPathSet : 1; /* whether showProgramPath was set */ bool prevPathSet : 1; /* whether showProgramPath was set */
bool prevCommSet : 1; /* whether findCommInCmdline was set */ bool prevCommSet : 1; /* whether findCommInCmdline was set */
bool prevCmdlineSet : 1; /* whether stripExeFromCmdline was set */ bool prevCmdlineSet : 1; /* whether stripExeFromCmdline was set */
bool prevShowThreadNames : 1; /* whether showThreadNames was set */
} ProcessMergedCommand; } ProcessMergedCommand;
typedef struct Process_ { typedef struct Process_ {