From b839987df7f6fc761c96b651a3dfc49eb13e879a Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 1 Feb 2021 22:24:42 +0100 Subject: [PATCH] Rename basenameOffset to cmdlineBasenameOffset --- Process.c | 6 +++--- Process.h | 6 +++--- darwin/DarwinProcess.c | 21 +++++++++++---------- dragonflybsd/DragonFlyBSDProcessList.c | 4 ++-- freebsd/FreeBSDProcessList.c | 4 ++-- linux/LinuxProcessList.c | 10 +++++----- openbsd/OpenBSDProcessList.c | 4 ++-- solaris/SolarisProcessList.c | 2 +- unsupported/UnsupportedProcessList.c | 2 +- 9 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Process.c b/Process.c index a45d9c00..e65eb998 100644 --- a/Process.c +++ b/Process.c @@ -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(); diff --git a/Process.h b/Process.h index 0f08e03e..9bfe4d5d 100644 --- a/Process.h +++ b/Process.h @@ -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; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index d94203c7..9e55c0fa 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -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 */ diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 16ee37a9..627ca004 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -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); } } diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 0d5e4565..8c940420 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -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); } } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 71c51a43..a55bada7 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -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; diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 9ad13c8f..06e02dfd 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -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); } } diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 8d9cf639..103074a8 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -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; diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 4323a26f..f939be0f 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -46,7 +46,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { proc->ppid = 1; proc->tgid = 0; free_and_xStrdup(&proc->cmdline, ""); - proc->basenameOffset = 0; + proc->cmdlineBasenameOffset = -1; proc->updated = true; proc->state = 'R';