summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenny Baumann <BenBE@geshi.org>2021-05-25 19:02:12 +0200
committerBenny Baumann <BenBE@geshi.org>2021-05-25 21:55:04 +0200
commitb6ff5c8a2e5981a0e71423953b565a1389c5428d (patch)
tree5091521cb893526ab1e35db19768254d08e35700
parentc408add10847c597de9fb7ba76295c386dc39649 (diff)
Move CWD field handling to platform-neutral code
-rw-r--r--Process.c17
-rw-r--r--Process.h8
-rw-r--r--linux/LinuxProcess.c19
-rw-r--r--linux/LinuxProcess.h2
-rw-r--r--linux/LinuxProcessList.c10
-rw-r--r--linux/ProcessField.h3
6 files changed, 32 insertions, 27 deletions
diff --git a/Process.c b/Process.c
index a70d391c..e30c6808 100644
--- a/Process.c
+++ b/Process.c
@@ -777,6 +777,20 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
Process_printLeftAlignedField(str, attr, procExe, TASK_COMM_LEN - 1);
return;
}
+ case CWD: {
+ const char* cwd;
+ if (!this->procCwd) {
+ attr = CRT_colors[PROCESS_SHADOW];
+ cwd = "N/A";
+ } else if (String_startsWith(this->procCwd, "/proc/") && strstr(this->procCwd, " (deleted)") != NULL) {
+ attr = CRT_colors[PROCESS_SHADOW];
+ cwd = "main thread terminated";
+ } else {
+ cwd = this->procCwd;
+ }
+ Process_printLeftAlignedField(str, attr, cwd, 25);
+ return;
+ }
case ELAPSED: Process_printTime(str, /* convert to hundreds of a second */ this->processList->realtimeMs / 10 - 100 * this->starttime_ctime, coloring); return;
case MAJFLT: Process_printCount(str, this->majflt, coloring); return;
case MINFLT: Process_printCount(str, this->minflt, coloring); return;
@@ -915,6 +929,7 @@ void Process_done(Process* this) {
free(this->cmdline);
free(this->procComm);
free(this->procExe);
+ free(this->procCwd);
free(this->mergedCommand.str);
free(this->tty_name);
}
@@ -1074,6 +1089,8 @@ int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField
const char *exe2 = p2->procExe ? (p2->procExe + p2->procExeBasenameOffset) : (Process_isKernelThread(p2) ? kthreadID : "");
return SPACESHIP_NULLSTR(exe1, exe2);
}
+ case CWD:
+ return SPACESHIP_NULLSTR(p1->procCwd, p2->procCwd);
case ELAPSED:
r = -SPACESHIP_NUMBER(p1->starttime_ctime, p2->starttime_ctime);
return r != 0 ? r : SPACESHIP_NUMBER(p1->pid, p2->pid);
diff --git a/Process.h b/Process.h
index b2d3482e..2ff1aa09 100644
--- a/Process.h
+++ b/Process.h
@@ -17,7 +17,9 @@ in the source distribution for its full text.
#include "RichString.h"
-#define PROCESS_FLAG_IO 0x0001
+#define PROCESS_FLAG_IO 0x00000001
+#define PROCESS_FLAG_CWD 0x00000002
+
#define DEFAULT_HIGHLIGHT_SECS 5
typedef enum ProcessField_ {
@@ -49,6 +51,7 @@ typedef enum ProcessField_ {
ELAPSED = 54,
PROC_COMM = 124,
PROC_EXE = 125,
+ CWD = 126,
/* Platform specific fields, defined in ${platform}/ProcessField.h */
PLATFORM_PROCESS_FIELDS
@@ -151,6 +154,9 @@ typedef struct Process_ {
/* The main process executable */
char *procExe;
+ /* The process/thread working directory */
+ char *procCwd;
+
/* Offset in procExe of the process basename */
int procExeBasenameOffset;
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c
index d90c8d1e..bd7a7300 100644
--- a/linux/LinuxProcess.c
+++ b/linux/LinuxProcess.c
@@ -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);
}
diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h
index fe9d88e2..5f77db2e 100644
--- a/linux/LinuxProcess.h
+++ b/linux/LinuxProcess.h
@@ -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;
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index b89b76dd..79706c04 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -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);
}
diff --git a/linux/ProcessField.h b/linux/ProcessField.h
index a4e03009..c8d24c0b 100644
--- a/linux/ProcessField.h
+++ b/linux/ProcessField.h
@@ -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

© 2014-2024 Faster IT GmbH | imprint | privacy policy