mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
Move CWD field handling to platform-neutral code
This commit is contained in:
@ -99,7 +99,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
|
||||
[SECATTR] = { .name = "SECATTR", .title = " Security Attribute ", .description = "Security attribute of the process (e.g. SELinux or AppArmor)", .flags = PROCESS_FLAG_LINUX_SECATTR, },
|
||||
[PROC_COMM] = { .name = "COMM", .title = "COMM ", .description = "comm string of the process from /proc/[pid]/comm", .flags = 0, },
|
||||
[PROC_EXE] = { .name = "EXE", .title = "EXE ", .description = "Basename of exe of the process from /proc/[pid]/exe", .flags = 0, },
|
||||
[CWD] = { .name ="CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_LINUX_CWD, },
|
||||
[CWD] = { .name = "CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_CWD, },
|
||||
};
|
||||
|
||||
Process* LinuxProcess_new(const Settings* settings) {
|
||||
@ -116,7 +116,6 @@ void Process_delete(Object* cast) {
|
||||
#ifdef HAVE_OPENVZ
|
||||
free(this->ctid);
|
||||
#endif
|
||||
free(this->cwd);
|
||||
free(this->secattr);
|
||||
free(this);
|
||||
}
|
||||
@ -259,20 +258,6 @@ static void LinuxProcess_writeField(const Process* this, RichString* str, Proces
|
||||
xSnprintf(buffer, n, "%5lu ", lp->ctxt_diff);
|
||||
break;
|
||||
case SECATTR: snprintf(buffer, n, "%-30s ", lp->secattr ? lp->secattr : "?"); break;
|
||||
case CWD: {
|
||||
const char* cwd;
|
||||
if (!lp->cwd) {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
cwd = "N/A";
|
||||
} else if (String_startsWith(lp->cwd, "/proc/") && strstr(lp->cwd, " (deleted)") != NULL) {
|
||||
attr = CRT_colors[PROCESS_SHADOW];
|
||||
cwd = "main thread terminated";
|
||||
} else {
|
||||
cwd = lp->cwd;
|
||||
}
|
||||
Process_printLeftAlignedField(str, attr, cwd, 25);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
Process_writeField(this, str, field);
|
||||
return;
|
||||
@ -364,8 +349,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 CWD:
|
||||
return SPACESHIP_NULLSTR(p1->cwd, p2->cwd);
|
||||
default:
|
||||
return Process_compareByKey_Base(v1, v2, key);
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ in the source distribution for its full text.
|
||||
#define PROCESS_FLAG_LINUX_CTXT 0x00004000
|
||||
#define PROCESS_FLAG_LINUX_SECATTR 0x00008000
|
||||
#define PROCESS_FLAG_LINUX_LRS_FIX 0x00010000
|
||||
#define PROCESS_FLAG_LINUX_CWD 0x00020000
|
||||
#define PROCESS_FLAG_LINUX_DELAYACCT 0x00040000
|
||||
|
||||
typedef struct LinuxProcess_ {
|
||||
@ -100,7 +99,6 @@ typedef struct LinuxProcess_ {
|
||||
unsigned long ctxt_diff;
|
||||
char* secattr;
|
||||
unsigned long long int last_mlrs_calctime;
|
||||
char* cwd;
|
||||
} LinuxProcess;
|
||||
|
||||
extern int pageSize;
|
||||
|
@ -911,17 +911,17 @@ static void LinuxProcessList_readCwd(LinuxProcess* process, openat_arg_t procFd)
|
||||
#endif
|
||||
|
||||
if (r < 0) {
|
||||
free(process->cwd);
|
||||
process->cwd = NULL;
|
||||
free(process->super.procCwd);
|
||||
process->super.procCwd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
pathBuffer[r] = '\0';
|
||||
|
||||
if (process->cwd && String_eq(process->cwd, pathBuffer))
|
||||
if (process->super.procCwd && String_eq(process->super.procCwd, pathBuffer))
|
||||
return;
|
||||
|
||||
free_and_xStrdup(&process->cwd, pathBuffer);
|
||||
free_and_xStrdup(&process->super.procCwd, pathBuffer);
|
||||
}
|
||||
|
||||
#ifdef HAVE_DELAYACCT
|
||||
@ -1434,7 +1434,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
|
||||
LinuxProcessList_readSecattrData(lp, procFd);
|
||||
}
|
||||
|
||||
if (settings->flags & PROCESS_FLAG_LINUX_CWD) {
|
||||
if (settings->flags & PROCESS_FLAG_CWD) {
|
||||
LinuxProcessList_readCwd(lp, procFd);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,8 @@ in the source distribution for its full text.
|
||||
M_PSSWP = 121, \
|
||||
CTXT = 122, \
|
||||
SECATTR = 123, \
|
||||
CWD = 126, \
|
||||
\
|
||||
DUMMY_BUMP_FIELD = CWD, \
|
||||
// End of list
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user