Rename cmdlineBasenameOffset to cmdlineBasenameEnd to properly indicate the fields purpose

This commit is contained in:
Benny Baumann 2021-04-10 11:46:57 +02:00 committed by BenBE
parent 666f70c58c
commit 94a52cb5c9
10 changed files with 41 additions and 41 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->cmdlineBasenameOffset; i++) {
for (int i = 0; i < this->cmdlineBasenameEnd; 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->cmdlineBasenameOffset - basename;
len = this->cmdlineBasenameEnd - basename;
}
}
@ -541,7 +541,7 @@ void Process_init(Process* this, const Settings* settings) {
this->showChildren = true;
this->show = true;
this->updated = false;
this->cmdlineBasenameOffset = -1;
this->cmdlineBasenameEnd = -1;
if (Process_getuid == (uid_t)-1) {
Process_getuid = getuid();

View File

@ -102,8 +102,8 @@ typedef struct Process_ {
*/
char* cmdline;
/* Offset in cmdline of the process basename */
int cmdlineBasenameOffset;
/* End Offset in cmdline of the process basename */
int cmdlineBasenameEnd;
/* Start Offset in cmdline of the process basename */
int cmdlineBasenameStart;

View File

@ -101,7 +101,7 @@ bool Process_isThread(const Process* this) {
return false;
}
static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* cmdlineBasenameOffset) {
static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* cmdlineBasenameEnd) {
/* 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* cmdlineBa
/* Save where the argv[0] string starts. */
sp = cp;
*cmdlineBasenameOffset = 0;
*cmdlineBasenameEnd = 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* cmdlineBa
}
/* Note location of current '\0'. */
np = cp;
if (*cmdlineBasenameOffset == 0) {
*cmdlineBasenameOffset = cp - sp;
if (*cmdlineBasenameEnd == 0) {
*cmdlineBasenameEnd = cp - sp;
}
}
}
@ -223,8 +223,8 @@ static char* DarwinProcess_getCmdLine(const struct kinfo_proc* k, int* cmdlineBa
/* Empty or unterminated string. */
goto ERROR_B;
}
if (*cmdlineBasenameOffset == 0) {
*cmdlineBasenameOffset = np - sp;
if (*cmdlineBasenameEnd == 0) {
*cmdlineBasenameEnd = np - sp;
}
/* Make a copy of the string. */
@ -239,7 +239,7 @@ ERROR_B:
free( procargs );
ERROR_A:
*cmdlineBasenameOffset = -1;
*cmdlineBasenameEnd = -1;
retval = xStrdup(k->kp_proc.p_comm);
return retval;
@ -287,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->cmdlineBasenameOffset);
proc->cmdline = DarwinProcess_getCmdLine(ps, &proc->cmdlineBasenameEnd);
}
/* 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->cmdlineBasenameOffset);
proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->cmdlineBasenameEnd);
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->cmdlineBasenameOffset);
proc->cmdline = DragonFlyBSDProcessList_readProcessName(dfpl->kd, kproc, &proc->cmdlineBasenameEnd);
}
}

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->cmdlineBasenameOffset);
proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->cmdlineBasenameEnd);
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->cmdlineBasenameOffset);
proc->cmdline = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->cmdlineBasenameEnd);
}
}

View File

@ -193,7 +193,7 @@ colorized for better readability, and it is implicit that only upto
*/
#define TASK_COMM_LEN 16
static bool findCommInCmdline(const char *comm, const char *cmdline, int cmdlineBasenameOffset, int *pCommStart, int *pCommEnd) {
static bool findCommInCmdline(const char *comm, const char *cmdline, int cmdlineBasenameStart, int *pCommStart, int *pCommEnd) {
/* Try to find procComm in tokenized cmdline - this might in rare cases
* mis-identify a string or fail, if comm or cmdline had been unsuitably
* modified by the process */
@ -201,10 +201,10 @@ static bool findCommInCmdline(const char *comm, const char *cmdline, int cmdline
size_t tokenLen;
const size_t commLen = strlen(comm);
if (cmdlineBasenameOffset < 0)
if (cmdlineBasenameStart < 0)
return false;
for (const char *token = cmdline + cmdlineBasenameOffset; *token; ) {
for (const char *token = cmdline + cmdlineBasenameStart; *token;) {
for (tokenBase = token; *token && *token != '\n'; ++token) {
if (*token == '/') {
tokenBase = token + 1;
@ -249,7 +249,7 @@ static int matchCmdlinePrefixWithExeSuffix(const char *cmdline, int cmdlineBaseO
* that make htop's identification of the basename in cmdline unreliable.
* For e.g. /usr/libexec/gdm-session-worker modifies its cmdline to
* "gdm-session-worker [pam/gdm-autologin]" and htop ends up with
* procCmdlineBasenameOffset at "gdm-autologin]". This issue could arise with
* proccmdlineBasenameEnd at "gdm-autologin]". This issue could arise with
* chrome as well as it stores in cmdline its concatenated argument vector,
* without NUL delimiter between the arguments (which may contain a '/')
*
@ -391,21 +391,21 @@ void LinuxProcess_makeCommandStr(Process* this) {
char *strStart = mc->str;
char *str = strStart;
int cmdlineBasenameOffset = this->cmdlineBasenameStart;
int cmdlineBasenameEnd = this->cmdlineBasenameOffset;
int cmdlineBasenameStart = this->cmdlineBasenameStart;
int cmdlineBasenameEnd = this->cmdlineBasenameEnd;
if (!cmdline) {
cmdlineBasenameOffset = 0;
cmdlineBasenameStart = 0;
cmdlineBasenameEnd = 0;
cmdline = "(zombie)";
}
assert(cmdlineBasenameOffset >= 0);
assert(cmdlineBasenameOffset <= (int)strlen(cmdline));
assert(cmdlineBasenameStart >= 0);
assert(cmdlineBasenameStart <= (int)strlen(cmdline));
if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */
if (showMergedCommand && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */
if (strncmp(cmdline + cmdlineBasenameOffset, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) {
if (strncmp(cmdline + cmdlineBasenameStart, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) {
WRITE_HIGHLIGHT(0, strlen(procComm), commAttr, CMDLINE_HIGHLIGHT_FLAG_COMM);
str = stpcpy(str, procComm);
@ -414,11 +414,11 @@ void LinuxProcess_makeCommandStr(Process* this) {
}
if (showProgramPath) {
WRITE_HIGHLIGHT(cmdlineBasenameOffset, cmdlineBasenameEnd - cmdlineBasenameOffset, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME);
WRITE_HIGHLIGHT(cmdlineBasenameStart, cmdlineBasenameEnd - cmdlineBasenameStart, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME);
(void)stpcpyWithNewlineConversion(str, cmdline);
} else {
WRITE_HIGHLIGHT(0, cmdlineBasenameEnd - cmdlineBasenameOffset, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME);
(void)stpcpyWithNewlineConversion(str, cmdline + cmdlineBasenameOffset);
WRITE_HIGHLIGHT(0, cmdlineBasenameEnd - cmdlineBasenameStart, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME);
(void)stpcpyWithNewlineConversion(str, cmdline + cmdlineBasenameStart);
}
return;
@ -460,10 +460,10 @@ void LinuxProcess_makeCommandStr(Process* this) {
/* Try to match procComm with procExe's basename: This is reliable (predictable) */
if (searchCommInCmdline) {
/* commStart/commEnd will be adjusted later along with cmdline */
haveCommInCmdline = findCommInCmdline(procComm, cmdline, cmdlineBasenameOffset, &commStart, &commEnd);
haveCommInCmdline = findCommInCmdline(procComm, cmdline, cmdlineBasenameStart, &commStart, &commEnd);
}
int matchLen = matchCmdlinePrefixWithExeSuffix(cmdline, cmdlineBasenameOffset, procExe, exeBasenameOffset, exeBasenameLen);
int matchLen = matchCmdlinePrefixWithExeSuffix(cmdline, cmdlineBasenameStart, procExe, exeBasenameOffset, exeBasenameLen);
bool haveCommField = false;

View File

@ -1013,7 +1013,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
if (amtRead == 0) {
if (process->state == 'Z') {
process->cmdlineBasenameOffset = 0;
process->cmdlineBasenameEnd = 0;
} else {
((LinuxProcess*)process)->isKernelThread = true;
}
@ -1135,7 +1135,7 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
if (!process->cmdline || !String_eq(command, process->cmdline)) {
free_and_xStrdup(&process->cmdline, command);
process->cmdlineBasenameStart = tokenStart;
process->cmdlineBasenameOffset = tokenEnd;
process->cmdlineBasenameEnd = tokenEnd;
lp->mergedCommand.cmdlineChanged = true;
}
@ -1460,14 +1460,14 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
LinuxProcessList_readCwd(lp, procFd);
}
if (proc->state == 'Z' && (proc->cmdlineBasenameOffset == 0)) {
proc->cmdlineBasenameOffset = -1;
if (proc->state == 'Z' && (proc->cmdlineBasenameEnd == 0)) {
proc->cmdlineBasenameEnd = -1;
free_and_xStrdup(&proc->cmdline, command);
proc->cmdlineBasenameStart = 0;
lp->mergedCommand.commChanged = true;
} else if (Process_isThread(proc)) {
if (settings->showThreadNames || Process_isKernelThread(proc)) {
proc->cmdlineBasenameOffset = -1;
proc->cmdlineBasenameEnd = -1;
free_and_xStrdup(&proc->cmdline, command);
proc->cmdlineBasenameStart = 0;
lp->mergedCommand.commChanged = true;

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->cmdlineBasenameOffset);
proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameEnd);
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->cmdlineBasenameOffset);
proc->cmdline = OpenBSDProcessList_readProcessName(this->kd, kproc, &proc->cmdlineBasenameEnd);
}
}

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->cmdlineBasenameOffset = -1;
proc->cmdlineBasenameEnd = -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->cmdlineBasenameOffset = -1;
proc->cmdlineBasenameEnd = -1;
proc->updated = true;
proc->state = 'R';