DragonFlyBSD: Implement CWD column

This commit is contained in:
Benny Baumann 2021-05-25 19:05:16 +02:00
parent 06073699ba
commit c2e2556403
3 changed files with 26 additions and 1 deletions

View File

@ -47,6 +47,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
[TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, .pidColumn = true, },
[PROC_COMM] = { .name = "COMM", .title = "COMM ", .description = "comm string of the process", .flags = 0, },
[PROC_EXE] = { .name = "EXE", .title = "EXE ", .description = "Basename of exe of the process", .flags = 0, },
[CWD] = { .name = "CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_CWD, },
[JID] = { .name = "JID", .title = "JID", .description = "Jail prison ID", .flags = 0, .pidColumn = true, },
[JAIL] = { .name = "JAIL", .title = "JAIL ", .description = "Jail prison name", .flags = 0, },
};

View File

@ -296,6 +296,26 @@ static void DragonFlyBSDProcessList_updateExe(const struct kinfo_proc* kproc, Pr
Process_updateExe(proc, target);
}
static void DragonFlyBSDProcessList_updateCwd(const struct kinfo_proc* kproc, Process* proc) {
const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_CWD, kproc->kp_pid };
char buffer[2048];
size_t size = sizeof(buffer);
if (sysctl(mib, 4, buffer, &size, NULL, 0) != 0) {
free(proc->procCwd);
proc->procCwd = NULL;
return;
}
/* Kernel threads return an empty buffer */
if (buffer[0] == '\0') {
free(proc->procCwd);
proc->procCwd = NULL;
return;
}
free_and_xStrdup(&proc->procCwd, buffer);
}
static void DragonFlyBSDProcessList_updateProcessName(kvm_t* kd, const struct kinfo_proc* kproc, Process* proc) {
Process_updateComm(proc, kproc->kp_comm);
@ -459,6 +479,10 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
DragonFlyBSDProcessList_updateExe(kproc, proc);
DragonFlyBSDProcessList_updateProcessName(dfpl->kd, kproc, proc);
if (settings->flags & PROCESS_FLAG_CWD) {
DragonFlyBSDProcessList_updateCwd(kproc, proc);
}
ProcessList_add(super, proc);
dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid);

View File

@ -12,7 +12,7 @@ in the source distribution for its full text.
JID = 100, \
JAIL = 101, \
\
DUMMY_BUMP_FIELD = PROC_EXE, \
DUMMY_BUMP_FIELD = CWD, \
// End of list