Skip to content

Commit ce27f83

Browse files
committed
Respect "Show custom thread names" setting update
Update merged command-line when started with "Show custom thread names" disabled and enabling at runtime. Also only consider showThreadNames when working on userland threads.
1 parent 2d1b6f4 commit ce27f83

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

Process.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void Process_makeCommandStr(Process* this) {
401401
return;
402402
if (this->state == 'Z' && !this->mergedCommand.str)
403403
return;
404-
if (Process_isUserlandThread(this) && settings->showThreadNames)
404+
if (Process_isUserlandThread(this) && settings->showThreadNames && (showThreadNames == mc->prevShowThreadNames))
405405
return;
406406

407407
/* this->mergedCommand.str needs updating only if its state or contents changed.
@@ -500,7 +500,7 @@ void Process_makeCommandStr(Process* this) {
500500
assert(cmdlineBasenameStart <= (int)strlen(cmdline));
501501

502502
if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */
503-
if (showMergedCommand && showThreadNames && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */
503+
if (showMergedCommand && (!Process_isUserlandThread(this) || showThreadNames) && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */
504504
if (strncmp(cmdline + cmdlineBasenameStart, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) {
505505
WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM);
506506
str = stpcpy(str, procComm);
@@ -524,7 +524,7 @@ void Process_makeCommandStr(Process* this) {
524524
assert(exeBasenameOffset <= (int)strlen(procExe));
525525

526526
bool haveCommInExe = false;
527-
if (procExe && procComm && showThreadNames) {
527+
if (procExe && procComm && (!Process_isUserlandThread(this) || showThreadNames)) {
528528
haveCommInExe = strncmp(procExe + exeBasenameOffset, procComm, TASK_COMM_LEN - 1) == 0;
529529
}
530530

@@ -556,14 +556,14 @@ void Process_makeCommandStr(Process* this) {
556556
/* Try to match procComm with procExe's basename: This is reliable (predictable) */
557557
if (searchCommInCmdline) {
558558
/* commStart/commEnd will be adjusted later along with cmdline */
559-
haveCommInCmdline = showThreadNames && findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commEnd);
559+
haveCommInCmdline = (!Process_isUserlandThread(this) || showThreadNames) && findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commEnd);
560560
}
561561

562562
int matchLen = matchCmdlinePrefixWithExeSuffix(cmdline, cmdlineBasenameStart, procExe, exeBasenameOffset, exeBasenameLen);
563563

564564
bool haveCommField = false;
565565

566-
if (!haveCommInExe && !haveCommInCmdline && procComm && showThreadNames) {
566+
if (!haveCommInExe && !haveCommInCmdline && procComm && (!Process_isUserlandThread(this) || showThreadNames)) {
567567
WRITE_SEPARATOR;
568568
WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM);
569569
str = stpcpy(str, procComm);
@@ -583,7 +583,7 @@ void Process_makeCommandStr(Process* this) {
583583
WRITE_SEPARATOR;
584584
}
585585

586-
if (!haveCommInExe && haveCommInCmdline && !haveCommField && showThreadNames)
586+
if (!haveCommInExe && haveCommInCmdline && !haveCommField && (!Process_isUserlandThread(this) || showThreadNames))
587587
WRITE_HIGHLIGHT(commStart, commEnd - commStart, commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM);
588588

589589
/* Display cmdline if it hasn't been consumed by procExe */

linux/LinuxProcessList.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
12231223
if ((amtRead = xReadfileat(procFd, "comm", command, sizeof(command))) > 0) {
12241224
command[amtRead - 1] = '\0';
12251225
Process_updateComm(process, command);
1226-
} else if (process->procComm) {
1226+
} else {
12271227
Process_updateComm(process, NULL);
12281228
}
12291229

@@ -1543,18 +1543,15 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
15431543
LinuxProcessList_readAutogroup(lp, procFd);
15441544
}
15451545

1546-
if (proc->state == 'Z' && !proc->cmdline && statCommand[0]) {
1546+
if (!proc->cmdline && statCommand[0] &&
1547+
(proc->state == 'Z' || Process_isKernelThread(proc) || settings->showThreadNames)) {
15471548
Process_updateCmdline(proc, statCommand, 0, strlen(statCommand));
1548-
} else if (Process_isThread(proc)) {
1549-
if ((settings->showThreadNames || Process_isKernelThread(proc)) && statCommand[0]) {
1550-
Process_updateCmdline(proc, statCommand, 0, strlen(statCommand));
1551-
}
1549+
}
15521550

1553-
if (Process_isKernelThread(proc)) {
1554-
pl->kernelThreads++;
1555-
} else {
1556-
pl->userlandThreads++;
1557-
}
1551+
if (Process_isKernelThread(proc)) {
1552+
pl->kernelThreads++;
1553+
} else if (Process_isUserlandThread(proc)) {
1554+
pl->userlandThreads++;
15581555
}
15591556

15601557
/* Set at the end when we know if a new entry is a thread */

0 commit comments

Comments
 (0)