mirror of https://github.com/xzeldon/htop.git
Move PROC_COMM/PROC_EXE column handling to global Process implementation
This commit is contained in:
parent
a61a2e6d47
commit
aa8552ba88
41
Process.c
41
Process.c
|
@ -35,6 +35,9 @@ in the source distribution for its full text.
|
|||
#endif
|
||||
|
||||
|
||||
/* Used to identify kernel threads in Comm and Exe columns */
|
||||
static const char *const kthreadID = "KTHREAD";
|
||||
|
||||
static uid_t Process_getuid = (uid_t)-1;
|
||||
|
||||
int Process_pidDigits = 7;
|
||||
|
@ -745,6 +748,34 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
|||
Process_writeCommand(this, attr, baseattr, str);
|
||||
return;
|
||||
}
|
||||
case PROC_COMM: {
|
||||
const char* procComm;
|
||||
if (this->procComm) {
|
||||
attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_COMM : PROCESS_COMM];
|
||||
procComm = this->procComm;
|
||||
} else {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
procComm = Process_isKernelThread(this) ? kthreadID : "N/A";
|
||||
}
|
||||
|
||||
Process_printLeftAlignedField(str, attr, procComm, TASK_COMM_LEN - 1);
|
||||
return;
|
||||
}
|
||||
case PROC_EXE: {
|
||||
const char* procExe;
|
||||
if (this->procExe) {
|
||||
attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_BASENAME : PROCESS_BASENAME];
|
||||
if (this->procExeDeleted)
|
||||
attr = CRT_colors[FAILED_READ];
|
||||
procExe = this->procExe + this->procExeBasenameOffset;
|
||||
} else {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
procExe = Process_isKernelThread(this) ? kthreadID : "N/A";
|
||||
}
|
||||
|
||||
Process_printLeftAlignedField(str, attr, procExe, TASK_COMM_LEN - 1);
|
||||
return;
|
||||
}
|
||||
case MAJFLT: Process_printCount(str, this->majflt, coloring); return;
|
||||
case MINFLT: Process_printCount(str, this->minflt, coloring); return;
|
||||
case M_RESIDENT: Process_printKBytes(str, this->m_resident, coloring); return;
|
||||
|
@ -1031,6 +1062,16 @@ int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField
|
|||
return SPACESHIP_NUMBER(p1->m_resident, p2->m_resident);
|
||||
case COMM:
|
||||
return SPACESHIP_NULLSTR(Process_getCommand(p1), Process_getCommand(p2));
|
||||
case PROC_COMM: {
|
||||
const char *comm1 = p1->procComm ? p1->procComm : (Process_isKernelThread(p1) ? kthreadID : "");
|
||||
const char *comm2 = p2->procComm ? p2->procComm : (Process_isKernelThread(p2) ? kthreadID : "");
|
||||
return SPACESHIP_NULLSTR(comm1, comm2);
|
||||
}
|
||||
case PROC_EXE: {
|
||||
const char *exe1 = p1->procExe ? (p1->procExe + p1->procExeBasenameOffset) : (Process_isKernelThread(p1) ? kthreadID : "");
|
||||
const char *exe2 = p2->procExe ? (p2->procExe + p2->procExeBasenameOffset) : (Process_isKernelThread(p2) ? kthreadID : "");
|
||||
return SPACESHIP_NULLSTR(exe1, exe2);
|
||||
}
|
||||
case MAJFLT:
|
||||
return SPACESHIP_NUMBER(p1->majflt, p2->majflt);
|
||||
case MINFLT:
|
||||
|
|
|
@ -46,6 +46,8 @@ typedef enum ProcessField_ {
|
|||
NLWP = 51,
|
||||
TGID = 52,
|
||||
PERCENT_NORM_CPU = 53,
|
||||
PROC_COMM = 124,
|
||||
PROC_EXE = 125,
|
||||
|
||||
/* Platform specific fields, defined in ${platform}/ProcessField.h */
|
||||
PLATFORM_PROCESS_FIELDS
|
||||
|
|
|
@ -29,9 +29,6 @@ in the source distribution for its full text.
|
|||
int pageSize;
|
||||
int pageSizeKB;
|
||||
|
||||
/* Used to identify kernel threads in Comm and Exe columns */
|
||||
static const char *const kthreadID = "KTHREAD";
|
||||
|
||||
const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
|
||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||
[PID] = { .name = "PID", .title = "PID", .description = "Process/thread ID", .flags = 0, .pidColumn = true, },
|
||||
|
@ -315,33 +312,6 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
|
|||
}
|
||||
return;
|
||||
}
|
||||
case PROC_COMM: {
|
||||
const char* procComm;
|
||||
if (this->procComm) {
|
||||
attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_COMM : PROCESS_COMM];
|
||||
procComm = this->procComm;
|
||||
} else {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
procComm = Process_isKernelThread(this) ? kthreadID : "N/A";
|
||||
}
|
||||
/* 15 being (TASK_COMM_LEN - 1) */
|
||||
Process_printLeftAlignedField(str, attr, procComm, 15);
|
||||
return;
|
||||
}
|
||||
case PROC_EXE: {
|
||||
const char* procExe;
|
||||
if (this->procExe) {
|
||||
attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_BASENAME : PROCESS_BASENAME];
|
||||
if (this->procExeDeleted)
|
||||
attr = CRT_colors[FAILED_READ];
|
||||
procExe = this->procExe + this->procExeBasenameOffset;
|
||||
} else {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
procExe = Process_isKernelThread(this) ? kthreadID : "N/A";
|
||||
}
|
||||
Process_printLeftAlignedField(str, attr, procExe, 15);
|
||||
return;
|
||||
}
|
||||
case CWD: {
|
||||
const char* cwd;
|
||||
if (!lp->cwd) {
|
||||
|
@ -447,16 +417,6 @@ static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proce
|
|||
return SPACESHIP_NUMBER(p1->ctxt_diff, p2->ctxt_diff);
|
||||
case SECATTR:
|
||||
return SPACESHIP_NULLSTR(p1->secattr, p2->secattr);
|
||||
case PROC_COMM: {
|
||||
const char *comm1 = v1->procComm ? v1->procComm : (Process_isKernelThread(v1) ? kthreadID : "");
|
||||
const char *comm2 = v2->procComm ? v2->procComm : (Process_isKernelThread(v2) ? kthreadID : "");
|
||||
return strcmp(comm1, comm2);
|
||||
}
|
||||
case PROC_EXE: {
|
||||
const char *exe1 = v1->procExe ? (v1->procExe + v1->procExeBasenameOffset) : (Process_isKernelThread(v1) ? kthreadID : "");
|
||||
const char *exe2 = v2->procExe ? (v2->procExe + v2->procExeBasenameOffset) : (Process_isKernelThread(v2) ? kthreadID : "");
|
||||
return strcmp(exe1, exe2);
|
||||
}
|
||||
case CWD:
|
||||
return SPACESHIP_NULLSTR(p1->cwd, p2->cwd);
|
||||
default:
|
||||
|
|
|
@ -44,8 +44,6 @@ in the source distribution for its full text.
|
|||
M_PSSWP = 121, \
|
||||
CTXT = 122, \
|
||||
SECATTR = 123, \
|
||||
PROC_COMM = 124, \
|
||||
PROC_EXE = 125, \
|
||||
CWD = 126, \
|
||||
// End of list
|
||||
|
||||
|
|
Loading…
Reference in New Issue