mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
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 */
|
||||
char *procExe;
|
||||
|
||||
/* Offset in procExe of the process basename */
|
||||
int procExeBasenameOffset;
|
||||
|
||||
/* Tells if the executable has been replaced in the filesystem since start */
|
||||
bool procExeDeleted;
|
||||
|
||||
|
@ -424,8 +424,8 @@ void LinuxProcess_makeCommandStr(Process* this) {
|
||||
return;
|
||||
}
|
||||
|
||||
int exeLen = lp->procExeLen;
|
||||
int exeBasenameOffset = lp->procExeBasenameOffset;
|
||||
int exeLen = strlen(this->procExe);
|
||||
int exeBasenameOffset = this->procExeBasenameOffset;
|
||||
int exeBasenameLen = exeLen - exeBasenameOffset;
|
||||
|
||||
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];
|
||||
if (this->procExeDeleted)
|
||||
attr = CRT_colors[FAILED_READ];
|
||||
procExe = this->procExe + lp->procExeBasenameOffset;
|
||||
procExe = this->procExe + this->procExeBasenameOffset;
|
||||
} else {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
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);
|
||||
}
|
||||
case PROC_EXE: {
|
||||
const char *exe1 = v1->procExe ? (v1->procExe + p1->procExeBasenameOffset) : (Process_isKernelThread(p1) ? kthreadID : "");
|
||||
const char *exe2 = v2->procExe ? (v2->procExe + p2->procExeBasenameOffset) : (Process_isKernelThread(p2) ? kthreadID : "");
|
||||
const char *exe1 = v1->procExe ? (v1->procExe + v1->procExeBasenameOffset) : (Process_isKernelThread(p1) ? kthreadID : "");
|
||||
const char *exe2 = v2->procExe ? (v2->procExe + v2->procExeBasenameOffset) : (Process_isKernelThread(p2) ? kthreadID : "");
|
||||
return strcmp(exe1, exe2);
|
||||
}
|
||||
case CWD:
|
||||
|
@ -63,8 +63,6 @@ typedef struct LinuxProcessMergedCommand_ {
|
||||
|
||||
typedef struct LinuxProcess_ {
|
||||
Process super;
|
||||
int procExeLen;
|
||||
int procExeBasenameOffset;
|
||||
int procCmdlineBasenameOffset;
|
||||
int procCmdlineBasenameEnd;
|
||||
LinuxProcessMergedCommand mergedCommand;
|
||||
|
@ -1167,29 +1167,34 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, openat_arg_t proc
|
||||
if (amtRead > 0) {
|
||||
filename[amtRead] = 0;
|
||||
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);
|
||||
lp->procExeLen = amtRead;
|
||||
|
||||
/* exe is guaranteed to contain at least one /, but validate anyway */
|
||||
while (amtRead && filename[--amtRead] != '/')
|
||||
;
|
||||
lp->procExeBasenameOffset = amtRead + 1;
|
||||
|
||||
process->procExeBasenameOffset = amtRead + 1;
|
||||
lp->mergedCommand.exeChanged = true;
|
||||
|
||||
const char* deletedMarker = " (deleted)";
|
||||
if (strlen(process->procExe) > strlen(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] == '/') {
|
||||
lp->procExeBasenameOffset = 0;
|
||||
if (process->procExeDeleted) {
|
||||
process->procExe[strlen(process->procExe) - strlen(deletedMarker)] = '\0';
|
||||
|
||||
if (String_eq(process->procExe, "/"))
|
||||
process->procExeBasenameOffset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (process->procExe) {
|
||||
free(process->procExe);
|
||||
process->procExe = NULL;
|
||||
lp->procExeLen = 0;
|
||||
lp->procExeBasenameOffset = 0;
|
||||
process->procExeBasenameOffset = 0;
|
||||
process->procExeDeleted = false;
|
||||
lp->mergedCommand.exeChanged = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user