Rename basenameOffset to cmdlineBasenameOffset

This commit is contained in:
Benny Baumann 2021-02-01 22:24:42 +01:00 committed by BenBE
parent d74e8b7554
commit b839987df7
9 changed files with 30 additions and 29 deletions

View File

@ -259,7 +259,7 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea
if (this->settings->highlightBaseName || !this->settings->showProgramPath) { if (this->settings->highlightBaseName || !this->settings->showProgramPath) {
int basename = 0; int basename = 0;
for (int i = 0; i < this->basenameOffset; i++) { for (int i = 0; i < this->cmdlineBasenameOffset; i++) {
if (cmdline[i] == '/') { if (cmdline[i] == '/') {
basename = i + 1; basename = i + 1;
} else if (cmdline[i] == ':') { } else if (cmdline[i] == ':') {
@ -273,7 +273,7 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea
} else { } else {
cmdline += basename; cmdline += basename;
} }
len = this->basenameOffset - basename; len = this->cmdlineBasenameOffset - basename;
} }
} }
@ -541,7 +541,7 @@ void Process_init(Process* this, const Settings* settings) {
this->showChildren = true; this->showChildren = true;
this->show = true; this->show = true;
this->updated = false; this->updated = false;
this->basenameOffset = -1; this->cmdlineBasenameOffset = -1;
if (Process_getuid == (uid_t)-1) { if (Process_getuid == (uid_t)-1) {
Process_getuid = getuid(); Process_getuid = getuid();

View File

@ -102,15 +102,15 @@ typedef struct Process_ {
*/ */
char* cmdline; char* cmdline;
/* Offset in cmdline of the process basename */
int cmdlineBasenameOffset;
/* The process' "command" name */ /* The process' "command" name */
char *procComm; char *procComm;
/* The main process executable */ /* The main process executable */
char *procExe; char *procExe;
/* Offset in comm of the process basename */
int basenameOffset;
/* CPU number last executed on */ /* CPU number last executed on */
int processor; int processor;

View File

@ -101,7 +101,7 @@ bool Process_isThread(const Process* this) {
return false; return false;
} }
static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* basenameOffset) { static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* cmdlineBasenameOffset) {
/* This function is from the old Mac version of htop. Originally from ps? */ /* This function is from the old Mac version of htop. Originally from ps? */
int mib[3], argmax, nargs, c = 0; int mib[3], argmax, nargs, c = 0;
size_t size; size_t size;
@ -199,7 +199,7 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* basenameO
/* Save where the argv[0] string starts. */ /* Save where the argv[0] string starts. */
sp = cp; sp = cp;
*basenameOffset = 0; *cmdlineBasenameOffset = 0;
for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) { for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) {
if ( *cp == '\0' ) { if ( *cp == '\0' ) {
c++; c++;
@ -209,8 +209,8 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* basenameO
} }
/* Note location of current '\0'. */ /* Note location of current '\0'. */
np = cp; np = cp;
if (*basenameOffset == 0) { if (*cmdlineBasenameOffset == 0) {
*basenameOffset = cp - sp; *cmdlineBasenameOffset = cp - sp;
} }
} }
} }
@ -223,8 +223,8 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* basenameO
/* Empty or unterminated string. */ /* Empty or unterminated string. */
goto ERROR_B; goto ERROR_B;
} }
if (*basenameOffset == 0) { if (*cmdlineBasenameOffset == 0) {
*basenameOffset = np - sp; *cmdlineBasenameOffset = np - sp;
} }
/* Make a copy of the string. */ /* Make a copy of the string. */
@ -237,10 +237,11 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* basenameO
ERROR_B: ERROR_B:
free( procargs ); free( procargs );
ERROR_A:
retval = xStrdup(k->kp_proc.p_comm);
*basenameOffset = strlen(retval);
ERROR_A:
*cmdlineBasenameOffset = -1;
retval = xStrdup(k->kp_proc.p_comm);
return retval; return retval;
} }
@ -286,7 +287,7 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps,
proc->starttime_ctime = ep->p_starttime.tv_sec; proc->starttime_ctime = ep->p_starttime.tv_sec;
Process_fillStarttimeBuffer(proc); Process_fillStarttimeBuffer(proc);
proc->cmdline = DarwinProcess_getCmdLine(ps, &(proc->basenameOffset)); proc->cmdline = DarwinProcess_getCmdLine(ps, &proc->cmdlineBasenameOffset);
} }
/* Mutable information */ /* Mutable information */

View File

@ -417,7 +417,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
} }
ProcessList_add(super, proc); ProcessList_add(super, proc);
proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->basenameOffset); proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->cmdlineBasenameOffset);
dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid);
} else { } else {
proc->processor = kproc->kp_lwp.kl_cpuid; proc->processor = kproc->kp_lwp.kl_cpuid;
@ -434,7 +434,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
} }
if (settings->updateProcessNames) { if (settings->updateProcessNames) {
free(proc->cmdline); free(proc->cmdline);
proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->basenameOffset); proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->cmdlineBasenameOffset);
} }
} }

View File

@ -467,7 +467,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
Process_fillStarttimeBuffer(proc); Process_fillStarttimeBuffer(proc);
proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); proc->user = UsersTable_getRef(super->usersTable, proc->st_uid);
ProcessList_add(super, proc); ProcessList_add(super, proc);
proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset); proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->cmdlineBasenameOffset);
fp->jname = FreeBSDProcessList_readJailName(kproc); fp->jname = FreeBSDProcessList_readJailName(kproc);
proc->tty_nr = kproc->ki_tdev; proc->tty_nr = kproc->ki_tdev;
@ -494,7 +494,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
} }
if (settings->updateProcessNames) { if (settings->updateProcessNames) {
free(proc->cmdline); free(proc->cmdline);
proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset); proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->cmdlineBasenameOffset);
} }
} }

View File

@ -1013,7 +1013,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
if (amtRead == 0) { if (amtRead == 0) {
if (process->state == 'Z') { if (process->state == 'Z') {
process->basenameOffset = 0; process->cmdlineBasenameOffset = 0;
} else { } else {
((LinuxProcess*)process)->isKernelThread = true; ((LinuxProcess*)process)->isKernelThread = true;
} }
@ -1133,7 +1133,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
LinuxProcess *lp = (LinuxProcess *)process; LinuxProcess *lp = (LinuxProcess *)process;
lp->mergedCommand.maxLen = lastChar + 1; /* accommodate cmdline */ lp->mergedCommand.maxLen = lastChar + 1; /* accommodate cmdline */
if (!process->cmdline || !String_eq(command, process->cmdline)) { if (!process->cmdline || !String_eq(command, process->cmdline)) {
process->basenameOffset = tokenEnd; process->cmdlineBasenameOffset = tokenEnd;
free_and_xStrdup(&process->cmdline, command); free_and_xStrdup(&process->cmdline, command);
lp->procCmdlineBasenameOffset = tokenStart; lp->procCmdlineBasenameOffset = tokenStart;
lp->procCmdlineBasenameEnd = tokenEnd; lp->procCmdlineBasenameEnd = tokenEnd;
@ -1456,15 +1456,15 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
LinuxProcessList_readCwd(lp, procFd); LinuxProcessList_readCwd(lp, procFd);
} }
if (proc->state == 'Z' && (proc->basenameOffset == 0)) { if (proc->state == 'Z' && (proc->cmdlineBasenameOffset == 0)) {
proc->basenameOffset = -1; proc->cmdlineBasenameOffset = -1;
free_and_xStrdup(&proc->cmdline, command); free_and_xStrdup(&proc->cmdline, command);
lp->procCmdlineBasenameOffset = 0; lp->procCmdlineBasenameOffset = 0;
lp->procCmdlineBasenameEnd = 0; lp->procCmdlineBasenameEnd = 0;
lp->mergedCommand.commChanged = true; lp->mergedCommand.commChanged = true;
} else if (Process_isThread(proc)) { } else if (Process_isThread(proc)) {
if (settings->showThreadNames || Process_isKernelThread(proc)) { if (settings->showThreadNames || Process_isKernelThread(proc)) {
proc->basenameOffset = -1; proc->cmdlineBasenameOffset = -1;
free_and_xStrdup(&proc->cmdline, command); free_and_xStrdup(&proc->cmdline, command);
lp->procCmdlineBasenameOffset = 0; lp->procCmdlineBasenameOffset = 0;
lp->procCmdlineBasenameEnd = 0; lp->procCmdlineBasenameEnd = 0;

View File

@ -257,7 +257,7 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
Process_fillStarttimeBuffer(proc); Process_fillStarttimeBuffer(proc);
proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid); proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid);
ProcessList_add(&this->super, proc); ProcessList_add(&this->super, proc);
proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset); proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameOffset);
proc->tty_nr = kproc->p_tdev; proc->tty_nr = kproc->p_tdev;
const char* name = ((dev_t)kproc->p_tdev != NODEV) ? devname(kproc->p_tdev, S_IFCHR) : NULL; const char* name = ((dev_t)kproc->p_tdev != NODEV) ? devname(kproc->p_tdev, S_IFCHR) : NULL;
@ -270,7 +270,7 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
} else { } else {
if (settings->updateProcessNames) { if (settings->updateProcessNames) {
free(proc->cmdline); free(proc->cmdline);
proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->basenameOffset); proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameOffset);
} }
} }

View File

@ -404,7 +404,7 @@ static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo,
proc->time = _lwpsinfo->pr_time.tv_sec; proc->time = _lwpsinfo->pr_time.tv_sec;
if (!preExisting) { // Tasks done only for NEW LWPs if (!preExisting) { // Tasks done only for NEW LWPs
sproc->is_lwp = true; sproc->is_lwp = true;
proc->basenameOffset = -1; proc->cmdlineBasenameOffset = -1;
proc->ppid = _psinfo->pr_pid * 1024; proc->ppid = _psinfo->pr_pid * 1024;
proc->tgid = _psinfo->pr_pid * 1024; proc->tgid = _psinfo->pr_pid * 1024;
sproc->realppid = _psinfo->pr_pid; sproc->realppid = _psinfo->pr_pid;

View File

@ -46,7 +46,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
proc->ppid = 1; proc->ppid = 1;
proc->tgid = 0; proc->tgid = 0;
free_and_xStrdup(&proc->cmdline, "<unsupported architecture>"); free_and_xStrdup(&proc->cmdline, "<unsupported architecture>");
proc->basenameOffset = 0; proc->cmdlineBasenameOffset = -1;
proc->updated = true; proc->updated = true;
proc->state = 'R'; proc->state = 'R';