summaryrefslogtreecommitdiffstats
path: root/freebsd
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2021-03-21 19:40:56 +0100
committercgzones <cgzones@googlemail.com>2021-04-14 17:29:56 +0200
commit9a8221568ada269d20c3e9d291ad5f9d07cac755 (patch)
tree025f098f3e98e3ae27105feb60dc76d4ff627452 /freebsd
parent36880cd61c52f13c6fd284aa23d42d9493d3ab2e (diff)
Rework TTY column
* Rename internal identifier from TTY_NR to just TTY * Unify column header on platforms * Use devname(3) on BSD derivate to show the actual terminal, simplifies current FreeBSD implementation. * Use 'unsigned long int' as id type, to fit dev_t on Linux. Only on Solaris the terminal path is not yet resolved.
Diffstat (limited to 'freebsd')
-rw-r--r--freebsd/FreeBSDProcess.c14
-rw-r--r--freebsd/FreeBSDProcess.h5
-rw-r--r--freebsd/FreeBSDProcessList.c87
-rw-r--r--freebsd/FreeBSDProcessList.h2
4 files changed, 10 insertions, 98 deletions
diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c
index c2c21af1..72e0b10f 100644
--- a/freebsd/FreeBSDProcess.c
+++ b/freebsd/FreeBSDProcess.c
@@ -26,7 +26,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
[PPID] = { .name = "PPID", .title = "PPID", .description = "Parent process ID", .flags = 0, .pidColumn = true, },
[PGRP] = { .name = "PGRP", .title = "PGRP", .description = "Process group ID", .flags = 0, .pidColumn = true, },
[SESSION] = { .name = "SESSION", .title = "SID", .description = "Process's session ID", .flags = 0, .pidColumn = true, },
- [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = PROCESS_FLAG_FREEBSD_TTY, },
+ [TTY] = { .name = "TTY", .title = "TTY ", .description = "Controlling terminal", .flags = 0, },
[TPGID] = { .name = "TPGID", .title = "TPGID", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, .pidColumn = true, },
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of copy-on-write faults", .flags = 0, .defaultSortDesc = true, },
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
@@ -74,16 +74,6 @@ static void FreeBSDProcess_writeField(const Process* this, RichString* str, Proc
case JAIL:
Process_printLeftAlignedField(str, attr, fp->jname ? fp->jname : "N/A", 11);
return;
- case TTY_NR:
- if (fp->ttyPath) {
- if (fp->ttyPath == nodevStr)
- attr = CRT_colors[PROCESS_SHADOW];
- xSnprintf(buffer, n, "%-8s", fp->ttyPath);
- } else {
- attr = CRT_colors[PROCESS_SHADOW];
- xSnprintf(buffer, n, "? ");
- }
- break;
default:
Process_writeField(this, str, field);
return;
@@ -101,8 +91,6 @@ static int FreeBSDProcess_compareByKey(const Process* v1, const Process* v2, Pro
return SPACESHIP_NUMBER(p1->jid, p2->jid);
case JAIL:
return SPACESHIP_NULLSTR(p1->jname, p2->jname);
- case TTY_NR:
- return SPACESHIP_NULLSTR(p1->ttyPath, p2->ttyPath);
default:
return Process_compareByKey_Base(v1, v2, key);
}
diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h
index 750e485e..5b6b4c66 100644
--- a/freebsd/FreeBSDProcess.h
+++ b/freebsd/FreeBSDProcess.h
@@ -14,16 +14,11 @@ in the source distribution for its full text.
#include "Settings.h"
-#define PROCESS_FLAG_FREEBSD_TTY 0x0100
-
-extern const char* const nodevStr;
-
typedef struct FreeBSDProcess_ {
Process super;
bool isKernelThread;
int jid;
char* jname;
- const char* ttyPath;
} FreeBSDProcess;
static inline bool Process_isKernelThread(const Process* this) {
diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c
index 2e937669..c5e8fd11 100644
--- a/freebsd/FreeBSDProcessList.c
+++ b/freebsd/FreeBSDProcessList.c
@@ -10,7 +10,6 @@ in the source distribution for its full text.
#include "FreeBSDProcessList.h"
#include <assert.h>
-#include <dirent.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
@@ -22,7 +21,6 @@ in the source distribution for its full text.
#include <sys/priority.h>
#include <sys/proc.h>
#include <sys/resource.h>
-#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -148,16 +146,12 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
CRT_fatalError("kvm_openfiles() failed");
}
- fpl->ttys = Hashtable_new(20, true);
-
return pl;
}
void ProcessList_delete(ProcessList* this) {
const FreeBSDProcessList* fpl = (FreeBSDProcessList*) this;
- Hashtable_delete(fpl->ttys);
-
if (fpl->kd) {
kvm_close(fpl->kd);
}
@@ -383,70 +377,6 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) {
pl->usedSwap *= pageSizeKb;
}
-static void FreeBSDProcessList_scanTTYs(ProcessList* pl) {
- FreeBSDProcessList* fpl = (FreeBSDProcessList*) pl;
-
- // scan /dev/tty*
- {
- DIR* dirPtr = opendir("/dev");
- if (!dirPtr)
- return;
-
- int dirFd = dirfd(dirPtr);
- if (dirFd < 0)
- goto err1;
-
- const struct dirent* entry;
- while ((entry = readdir(dirPtr))) {
- if (!String_startsWith(entry->d_name, "tty"))
- continue;
-
- struct stat info;
- if (Compat_fstatat(dirFd, "/dev", entry->d_name, &info, 0) < 0)
- continue;
-
- if (!S_ISCHR(info.st_mode))
- continue;
-
- if (!Hashtable_get(fpl->ttys, info.st_rdev))
- Hashtable_put(fpl->ttys, info.st_rdev, xStrdup(entry->d_name));
- }
-
-err1:
- closedir(dirPtr);
- }
-
- // scan /dev/pts/*
- {
- DIR* dirPtr = opendir("/dev/pts");
- if (!dirPtr)
- return;
-
- int dirFd = dirfd(dirPtr);
- if (dirFd < 0)
- goto err2;
-
- const struct dirent* entry;
- while ((entry = readdir(dirPtr))) {
- struct stat info;
- if (Compat_fstatat(dirFd, "/dev/pts", entry->d_name, &info, 0) < 0)
- continue;
-
- if (!S_ISCHR(info.st_mode))
- continue;
-
- if (!Hashtable_get(fpl->ttys, info.st_rdev)) {
- char* path;
- xAsprintf(&path, "pts/%s", entry->d_name);
- Hashtable_put(fpl->ttys, info.st_rdev, path);
- }
- }
-
-err2:
- closedir(dirPtr);
- }
-}
-
static char* FreeBSDProcessList_readProcessName(kvm_t* kd, const struct kinfo_proc* kproc, int* basenameEnd) {
char** argv = kvm_getargv(kd, kproc, 0);
if (!argv) {
@@ -512,10 +442,6 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
return;
}
- if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) {
- FreeBSDProcessList_scanTTYs(super);
- }
-
int count = 0;
const struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count);
@@ -543,6 +469,15 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
ProcessList_add(super, proc);
proc->comm = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset);
fp->jname = FreeBSDProcessList_readJailName(kproc);
+
+ proc->tty_nr = kproc->ki_tdev;
+ const char* name = (kproc->ki_tdev != NODEV) ? devname(kproc->ki_tdev, S_IFCHR) : NULL;
+ if (!name) {
+ free(proc->tty_name);
+ proc->tty_name = NULL;
+ } else {
+ free_and_xStrdup(&proc->tty_name, name);
+ }
} else {
if (fp->jid != kproc->ki_jid) {
// process can enter jail anytime
@@ -603,10 +538,6 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
default: proc->state = '?';
}
- if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) {
- fp->ttyPath = (kproc->ki_tdev == NODEV) ? nodevStr : Hashtable_get(fpl->ttys, kproc->ki_tdev);
- }
-
if (Process_isKernelThread(proc))
super->kernelThreads++;
diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h
index 398bb827..882345e8 100644
--- a/freebsd/FreeBSDProcessList.h
+++ b/freebsd/FreeBSDProcessList.h
@@ -39,8 +39,6 @@ typedef struct FreeBSDProcessList_ {
CPUData* cpus;
- Hashtable* ttys;
-
unsigned long* cp_time_o;
unsigned long* cp_time_n;

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