mirror of https://github.com/xzeldon/htop.git
Move procExeBasenameOffset to main Process structure
This drops procExeLen, as that field is implicit by strlen(Process->procExe)
This commit is contained in:
parent
93a44acf7e
commit
a685661866
|
@ -111,6 +111,9 @@ typedef struct Process_ {
|
||||||
/* The main process executable */
|
/* The main process executable */
|
||||||
char *procExe;
|
char *procExe;
|
||||||
|
|
||||||
|
/* Offset in procExe of the process basename */
|
||||||
|
int procExeBasenameOffset;
|
||||||
|
|
||||||
/* Tells if the executable has been replaced in the filesystem since start */
|
/* Tells if the executable has been replaced in the filesystem since start */
|
||||||
bool procExeDeleted;
|
bool procExeDeleted;
|
||||||
|
|
||||||
|
|
|
@ -424,8 +424,8 @@ void LinuxProcess_makeCommandStr(Process* this) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exeLen = lp->procExeLen;
|
int exeLen = strlen(this->procExe);
|
||||||
int exeBasenameOffset = lp->procExeBasenameOffset;
|
int exeBasenameOffset = this->procExeBasenameOffset;
|
||||||
int exeBasenameLen = exeLen - exeBasenameOffset;
|
int exeBasenameLen = exeLen - exeBasenameOffset;
|
||||||
|
|
||||||
assert(exeBasenameOffset >= 0);
|
assert(exeBasenameOffset >= 0);
|
||||||
|
@ -700,7 +700,7 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
|
||||||
attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_BASENAME : PROCESS_BASENAME];
|
attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_BASENAME : PROCESS_BASENAME];
|
||||||
if (this->procExeDeleted)
|
if (this->procExeDeleted)
|
||||||
attr = CRT_colors[FAILED_READ];
|
attr = CRT_colors[FAILED_READ];
|
||||||
procExe = this->procExe + lp->procExeBasenameOffset;
|
procExe = this->procExe + this->procExeBasenameOffset;
|
||||||
} else {
|
} else {
|
||||||
attr = CRT_colors[PROCESS_SHADOW];
|
attr = CRT_colors[PROCESS_SHADOW];
|
||||||
procExe = Process_isKernelThread(lp) ? kthreadID : "N/A";
|
procExe = Process_isKernelThread(lp) ? kthreadID : "N/A";
|
||||||
|
@ -819,8 +819,8 @@ static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proce
|
||||||
return strcmp(comm1, comm2);
|
return strcmp(comm1, comm2);
|
||||||
}
|
}
|
||||||
case PROC_EXE: {
|
case PROC_EXE: {
|
||||||
const char *exe1 = v1->procExe ? (v1->procExe + p1->procExeBasenameOffset) : (Process_isKernelThread(p1) ? kthreadID : "");
|
const char *exe1 = v1->procExe ? (v1->procExe + v1->procExeBasenameOffset) : (Process_isKernelThread(p1) ? kthreadID : "");
|
||||||
const char *exe2 = v2->procExe ? (v2->procExe + p2->procExeBasenameOffset) : (Process_isKernelThread(p2) ? kthreadID : "");
|
const char *exe2 = v2->procExe ? (v2->procExe + v2->procExeBasenameOffset) : (Process_isKernelThread(p2) ? kthreadID : "");
|
||||||
return strcmp(exe1, exe2);
|
return strcmp(exe1, exe2);
|
||||||
}
|
}
|
||||||
case CWD:
|
case CWD:
|
||||||
|
|
|
@ -63,8 +63,6 @@ typedef struct LinuxProcessMergedCommand_ {
|
||||||
|
|
||||||
typedef struct LinuxProcess_ {
|
typedef struct LinuxProcess_ {
|
||||||
Process super;
|
Process super;
|
||||||
int procExeLen;
|
|
||||||
int procExeBasenameOffset;
|
|
||||||
int procCmdlineBasenameOffset;
|
int procCmdlineBasenameOffset;
|
||||||
int procCmdlineBasenameEnd;
|
int procCmdlineBasenameEnd;
|
||||||
LinuxProcessMergedCommand mergedCommand;
|
LinuxProcessMergedCommand mergedCommand;
|
||||||
|
|
|
@ -1167,29 +1167,34 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
|
||||||
if (amtRead > 0) {
|
if (amtRead > 0) {
|
||||||
filename[amtRead] = 0;
|
filename[amtRead] = 0;
|
||||||
lp->mergedCommand.maxLen += amtRead; /* accommodate exe */
|
lp->mergedCommand.maxLen += amtRead; /* accommodate exe */
|
||||||
if (!process->procExe || !String_eq(filename, process->procExe)) {
|
if (!process->procExe ||
|
||||||
|
(!process->procExeDeleted && !String_eq(filename, process->procExe)) ||
|
||||||
|
(process->procExeDeleted && !String_startsWith(filename, process->procExe))) {
|
||||||
free_and_xStrdup(&process->procExe, filename);
|
free_and_xStrdup(&process->procExe, filename);
|
||||||
lp->procExeLen = amtRead;
|
|
||||||
/* exe is guaranteed to contain at least one /, but validate anyway */
|
/* exe is guaranteed to contain at least one /, but validate anyway */
|
||||||
while (amtRead && filename[--amtRead] != '/')
|
while (amtRead && filename[--amtRead] != '/')
|
||||||
;
|
;
|
||||||
lp->procExeBasenameOffset = amtRead + 1;
|
|
||||||
|
process->procExeBasenameOffset = amtRead + 1;
|
||||||
lp->mergedCommand.exeChanged = true;
|
lp->mergedCommand.exeChanged = true;
|
||||||
|
|
||||||
const char* deletedMarker = " (deleted)";
|
const char* deletedMarker = " (deleted)";
|
||||||
if (strlen(process->procExe) > strlen(deletedMarker)) {
|
if (strlen(process->procExe) > strlen(deletedMarker)) {
|
||||||
process->procExeDeleted = String_eq(process->procExe + strlen(process->procExe) - strlen(deletedMarker), deletedMarker);
|
process->procExeDeleted = String_eq(process->procExe + strlen(process->procExe) - strlen(deletedMarker), deletedMarker);
|
||||||
|
|
||||||
if (process->procExeDeleted && strlen(process->procExe) - strlen(deletedMarker) == 1 && process->procExe[0] == '/') {
|
if (process->procExeDeleted) {
|
||||||
lp->procExeBasenameOffset = 0;
|
process->procExe[strlen(process->procExe) - strlen(deletedMarker)] = '\0';
|
||||||
|
|
||||||
|
if (String_eq(process->procExe, "/"))
|
||||||
|
process->procExeBasenameOffset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (process->procExe) {
|
} else if (process->procExe) {
|
||||||
free(process->procExe);
|
free(process->procExe);
|
||||||
process->procExe = NULL;
|
process->procExe = NULL;
|
||||||
lp->procExeLen = 0;
|
process->procExeBasenameOffset = 0;
|
||||||
lp->procExeBasenameOffset = 0;
|
|
||||||
process->procExeDeleted = false;
|
process->procExeDeleted = false;
|
||||||
lp->mergedCommand.exeChanged = true;
|
lp->mergedCommand.exeChanged = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue