Call makeCommandStr on all platforms

This commit is contained in:
Benny Baumann 2021-04-18 18:10:04 +02:00 committed by BenBE
parent bcb18ef822
commit a61a2e6d47
9 changed files with 28 additions and 11 deletions

View File

@ -388,6 +388,17 @@ void Process_makeCommandStr(Process *this) {
bool searchCommInCmdline = settings->findCommInCmdline;
bool stripExeFromCmdline = settings->stripExeFromCmdline;
/* Nothing to do to (Re)Generate the Command string, if the process is:
* - a kernel thread, or
* - a zombie from before being under htop's watch, or
* - a user thread and showThreadNames is not set */
if (Process_isKernelThread(this))
return;
if (this->state == 'Z' && !this->mergedCommand.str)
return;
if (Process_isUserlandThread(this) && settings->showThreadNames)
return;
/* this->mergedCommand.str needs updating only if its state or contents changed.
* Its content is based on the fields cmdline, comm, and exe. */
if (

View File

@ -609,6 +609,8 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) Vector_get(this->processes, i);
Process_makeCommandStr(p);
if (p->tombStampMs > 0) {
// remove tombed process
if (this->monotonicMs >= p->tombStampMs) {
@ -623,8 +625,6 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
// immediately remove
ProcessList_remove(this, p);
}
} else {
p->updated = false;
}
}

View File

@ -285,6 +285,7 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps,
Process_fillStarttimeBuffer(proc);
proc->cmdline = DarwinProcess_getCmdLine(ps, &proc->cmdlineBasenameEnd);
proc->mergedCommand.cmdlineChanged = true;
}
/* Mutable information */

View File

@ -419,6 +419,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
ProcessList_add(super, proc);
proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->cmdlineBasenameEnd);
proc->mergedCommand.cmdlineChanged = true;
dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid);
} else {
proc->processor = kproc->kp_lwp.kl_cpuid;
@ -436,6 +438,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
if (settings->updateProcessNames) {
free(proc->cmdline);
proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->cmdlineBasenameEnd);
proc->mergedCommand.cmdlineChanged = true;
}
}

View File

@ -468,7 +468,10 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
Process_fillStarttimeBuffer(proc);
proc->user = UsersTable_getRef(super->usersTable, proc->st_uid);
ProcessList_add(super, proc);
proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->cmdlineBasenameEnd);
proc->mergedCommand.cmdlineChanged = true;
fp->jname = FreeBSDProcessList_readJailName(kproc);
proc->tty_nr = kproc->ki_tdev;
@ -496,6 +499,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
if (settings->updateProcessNames) {
free(proc->cmdline);
proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->cmdlineBasenameEnd);
proc->mergedCommand.cmdlineChanged = true;
}
}

View File

@ -1425,15 +1425,6 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
}
}
}
/* (Re)Generate the Command string, but only if the process is:
* - not a kernel thread, and
* - not a zombie or it became zombie under htop's watch, and
* - not a user thread or if showThreadNames is not set */
if (!Process_isKernelThread(proc) &&
(proc->state != 'Z' || proc->mergedCommand.str) &&
(!Process_isUserlandThread(proc) || !settings->showThreadNames)) {
Process_makeCommandStr(proc);
}
#ifdef HAVE_DELAYACCT
if (settings->flags & PROCESS_FLAG_LINUX_DELAYACCT) {

View File

@ -259,7 +259,9 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
Process_fillStarttimeBuffer(proc);
proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid);
ProcessList_add(&this->super, proc);
proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameEnd);
proc->mergedCommand.cmdlineChanged = true;
proc->tty_nr = kproc->p_tdev;
const char* name = ((dev_t)kproc->p_tdev != NODEV) ? devname(kproc->p_tdev, S_IFCHR) : NULL;
@ -273,6 +275,7 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
if (settings->updateProcessNames) {
free(proc->cmdline);
proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameEnd);
proc->mergedCommand.cmdlineChanged = true;
}
}

View File

@ -364,6 +364,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
sproc->zname = SolarisProcessList_readZoneName(spl->kd, sproc);
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
proc->cmdline = xStrdup(_psinfo->pr_fname);
proc->mergedCommand.cmdlineChanged = true;
}
// End common code pass 1
@ -411,6 +412,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
sproc->realppid = _psinfo->pr_pid;
sproc->realtgid = _psinfo->pr_pid;
proc->starttime_ctime = _lwpsinfo->pr_start.tv_sec;
proc->mergedCommand.cmdlineChanged = true;
}
// Top-level process only gets this for the representative LWP
@ -434,6 +436,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
Process_fillStarttimeBuffer(proc);
ProcessList_add(pl, proc);
}
proc->updated = true;
// End common code pass 2

View File

@ -47,6 +47,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
proc->tgid = 0;
free_and_xStrdup(&proc->cmdline, "<unsupported architecture>");
proc->cmdlineBasenameEnd = -1;
proc->mergedCommand.cmdlineChanged = true;
proc->updated = true;
proc->state = 'R';