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) {
int basename = 0;
for (int i = 0; i < this->basenameOffset; i++) {
for (int i = 0; i < this->cmdlineBasenameOffset; i++) {
if (cmdline[i] == '/') {
basename = i + 1;
} else if (cmdline[i] == ':') {
@ -273,7 +273,7 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea
} else {
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->show = true;
this->updated = false;
this->basenameOffset = -1;
this->cmdlineBasenameOffset = -1;
if (Process_getuid == (uid_t)-1) {
Process_getuid = getuid();

View File

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

View File

@ -101,7 +101,7 @@ bool Process_isThread(const Process* this) {
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? */
int mib[3], argmax, nargs, c = 0;
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. */
sp = cp;
*basenameOffset = 0;
*cmdlineBasenameOffset = 0;
for ( np = NULL; c < nargs && cp < &procargs[size]; cp++ ) {
if ( *cp == '\0' ) {
c++;
@ -209,8 +209,8 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* basenameO
}
/* Note location of current '\0'. */
np = cp;
if (*basenameOffset == 0) {
*basenameOffset = cp - sp;
if (*cmdlineBasenameOffset == 0) {
*cmdlineBasenameOffset = cp - sp;
}
}
}
@ -223,8 +223,8 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* basenameO
/* Empty or unterminated string. */
goto ERROR_B;
}
if (*basenameOffset == 0) {
*basenameOffset = np - sp;
if (*cmdlineBasenameOffset == 0) {
*cmdlineBasenameOffset = np - sp;
}
/* Make a copy of the string. */
@ -237,10 +237,11 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* basenameO
ERROR_B:
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;
}
@ -286,7 +287,7 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps,
proc->starttime_ctime = ep->p_starttime.tv_sec;
Process_fillStarttimeBuffer(proc);
proc->cmdline = DarwinProcess_getCmdLine(ps, &(proc->basenameOffset));
proc->cmdline = DarwinProcess_getCmdLine(ps, &proc->cmdlineBasenameOffset);
}
/* Mutable information */

View File

@ -417,7 +417,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
}
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);
} else {
proc->processor = kproc->kp_lwp.kl_cpuid;
@ -434,7 +434,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
}
if (settings->updateProcessNames) {
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);
proc->user = UsersTable_getRef(super->usersTable, proc->st_uid);
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);
proc->tty_nr = kproc->ki_tdev;
@ -494,7 +494,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
}
if (settings->updateProcessNames) {
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 (process->state == 'Z') {
process->basenameOffset = 0;
process->cmdlineBasenameOffset = 0;
} else {
((LinuxProcess*)process)->isKernelThread = true;
}
@ -1133,7 +1133,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
LinuxProcess *lp = (LinuxProcess *)process;
lp->mergedCommand.maxLen = lastChar + 1; /* accommodate cmdline */
if (!process->cmdline || !String_eq(command, process->cmdline)) {
process->basenameOffset = tokenEnd;
process->cmdlineBasenameOffset = tokenEnd;
free_and_xStrdup(&process->cmdline, command);
lp->procCmdlineBasenameOffset = tokenStart;
lp->procCmdlineBasenameEnd = tokenEnd;
@ -1456,15 +1456,15 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
LinuxProcessList_readCwd(lp, procFd);
}
if (proc->state == 'Z' && (proc->basenameOffset == 0)) {
proc->basenameOffset = -1;
if (proc->state == 'Z' && (proc->cmdlineBasenameOffset == 0)) {
proc->cmdlineBasenameOffset = -1;
free_and_xStrdup(&proc->cmdline, command);
lp->procCmdlineBasenameOffset = 0;
lp->procCmdlineBasenameEnd = 0;
lp->mergedCommand.commChanged = true;
} else if (Process_isThread(proc)) {
if (settings->showThreadNames || Process_isKernelThread(proc)) {
proc->basenameOffset = -1;
proc->cmdlineBasenameOffset = -1;
free_and_xStrdup(&proc->cmdline, command);
lp->procCmdlineBasenameOffset = 0;
lp->procCmdlineBasenameEnd = 0;

View File

@ -257,7 +257,7 @@ 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->basenameOffset);
proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameOffset);
proc->tty_nr = kproc->p_tdev;
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 {
if (settings->updateProcessNames) {
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;
if (!preExisting) { // Tasks done only for NEW LWPs
sproc->is_lwp = true;
proc->basenameOffset = -1;
proc->cmdlineBasenameOffset = -1;
proc->ppid = _psinfo->pr_pid * 1024;
proc->tgid = _psinfo->pr_pid * 1024;
sproc->realppid = _psinfo->pr_pid;

View File

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