aboutsummaryrefslogtreecommitdiffstats
path: root/freebsd
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2021-01-11 20:43:27 +0100
committerDaniel Lange <DLange@git.local>2021-01-11 20:43:27 +0100
commitc55320e9e2a8916e911bcd39ab37b79e3a7d03b2 (patch)
treed6be9a09fdf7d6dc155de3429a70697ee2bb43b0 /freebsd
parent65357c8c46154de4e4eca14075bfe5523bb5fc14 (diff)
downloaddebian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.tar.gz
debian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.tar.bz2
debian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.zip
New upstream version 3.0.5upstream/3.0.5
Diffstat (limited to 'freebsd')
-rw-r--r--freebsd/FreeBSDProcess.c66
-rw-r--r--freebsd/FreeBSDProcess.h11
-rw-r--r--freebsd/FreeBSDProcessList.c21
-rw-r--r--freebsd/Platform.c4
-rw-r--r--freebsd/Platform.h6
-rw-r--r--freebsd/ProcessField.h17
6 files changed, 49 insertions, 76 deletions
diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c
index d6d67b7..28d482e 100644
--- a/freebsd/FreeBSDProcess.c
+++ b/freebsd/FreeBSDProcess.c
@@ -18,16 +18,16 @@ in the source distribution for its full text.
const char* const nodevStr = "nodev";
-ProcessFieldData Process_fields[] = {
+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, },
+ [PID] = { .name = "PID", .title = "PID", .description = "Process/thread ID", .flags = 0, .pidColumn = true, },
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
- [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
- [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
- [SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
+ [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, },
- [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the 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, },
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
@@ -44,21 +44,9 @@ ProcessFieldData Process_fields[] = {
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
- [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
- [JID] = { .name = "JID", .title = " JID ", .description = "Jail prison ID", .flags = 0, },
+ [TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, .pidColumn = true, },
+ [JID] = { .name = "JID", .title = "JID", .description = "Jail prison ID", .flags = 0, .pidColumn = true, },
[JAIL] = { .name = "JAIL", .title = "JAIL ", .description = "Jail prison name", .flags = 0, },
- [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
-};
-
-ProcessPidColumn Process_pidColumns[] = {
- { .id = JID, .label = "JID" },
- { .id = PID, .label = "PID" },
- { .id = PPID, .label = "PPID" },
- { .id = TPGID, .label = "TPGID" },
- { .id = TGID, .label = "TGID" },
- { .id = PGRP, .label = "PGRP" },
- { .id = SESSION, .label = "SID" },
- { .id = 0, .label = NULL },
};
Process* FreeBSDProcess_new(const Settings* settings) {
@@ -80,17 +68,12 @@ static void FreeBSDProcess_writeField(const Process* this, RichString* str, Proc
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
int n = sizeof(buffer) - 1;
- switch ((int) field) {
+ switch (field) {
// add FreeBSD-specific fields here
- case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break;
- case JAIL: {
- xSnprintf(buffer, n, "%-11s ", fp->jname);
- if (buffer[11] != '\0') {
- buffer[11] = ' ';
- buffer[12] = '\0';
- }
- break;
- }
+ case JID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, fp->jid); break;
+ case JAIL:
+ Process_printLeftAlignedField(str, attr, fp->jname ? fp->jname : "N/A", 11);
+ return;
case TTY_NR:
if (fp->ttyPath) {
if (fp->ttyPath == nodevStr)
@@ -105,22 +88,14 @@ static void FreeBSDProcess_writeField(const Process* this, RichString* str, Proc
Process_writeField(this, str, field);
return;
}
- RichString_append(str, attr, buffer);
+ RichString_appendWide(str, attr, buffer);
}
-static long FreeBSDProcess_compare(const void* v1, const void* v2) {
- const FreeBSDProcess *p1, *p2;
- const Settings *settings = ((const Process*)v1)->settings;
-
- if (settings->direction == 1) {
- p1 = (const FreeBSDProcess*)v1;
- p2 = (const FreeBSDProcess*)v2;
- } else {
- p2 = (const FreeBSDProcess*)v1;
- p1 = (const FreeBSDProcess*)v2;
- }
+static int FreeBSDProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) {
+ const FreeBSDProcess* p1 = (const FreeBSDProcess*)v1;
+ const FreeBSDProcess* p2 = (const FreeBSDProcess*)v2;
- switch ((int) settings->sortKey) {
+ switch (key) {
// add FreeBSD-specific fields here
case JID:
return SPACESHIP_NUMBER(p1->jid, p2->jid);
@@ -129,7 +104,7 @@ static long FreeBSDProcess_compare(const void* v1, const void* v2) {
case TTY_NR:
return SPACESHIP_NULLSTR(p1->ttyPath, p2->ttyPath);
default:
- return Process_compare(v1, v2);
+ return Process_compareByKey_Base(v1, v2, key);
}
}
@@ -148,7 +123,8 @@ const ProcessClass FreeBSDProcess_class = {
.extends = Class(Process),
.display = Process_display,
.delete = Process_delete,
- .compare = FreeBSDProcess_compare
+ .compare = Process_compare
},
.writeField = FreeBSDProcess_writeField,
+ .compareByKey = FreeBSDProcess_compareByKey
};
diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h
index 8911976..6bf2c93 100644
--- a/freebsd/FreeBSDProcess.h
+++ b/freebsd/FreeBSDProcess.h
@@ -18,13 +18,6 @@ in the source distribution for its full text.
extern const char* const nodevStr;
-typedef enum FreeBSDProcessFields_ {
- // Add platform-specific fields here, with ids >= 100
- JID = 100,
- JAIL = 101,
- LAST_PROCESSFIELD = 102,
-} FreeBSDProcessField;
-
typedef struct FreeBSDProcess_ {
Process super;
int kernel;
@@ -43,9 +36,7 @@ static inline bool Process_isUserlandThread(const Process* this) {
extern const ProcessClass FreeBSDProcess_class;
-extern ProcessFieldData Process_fields[];
-
-extern ProcessPidColumn Process_pidColumns[];
+extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
Process* FreeBSDProcess_new(const Settings* settings);
diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c
index 9aaab5d..679f640 100644
--- a/freebsd/FreeBSDProcessList.c
+++ b/freebsd/FreeBSDProcessList.c
@@ -9,12 +9,10 @@ in the source distribution for its full text.
#include <assert.h>
#include <dirent.h>
-#include <err.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/_iovec.h>
-#include <sys/dirent.h>
#include <sys/errno.h>
#include <sys/param.h> // needs to be included before <sys/jail.h> for MAXPATHLEN
#include <sys/jail.h>
@@ -72,12 +70,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
len = 2; sysctlnametomib("hw.physmem", MIB_hw_physmem, &len);
len = sizeof(pageSize);
- if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) {
- pageSize = CRT_pageSize;
- pageSizeKb = CRT_pageSize;
- } else {
- pageSizeKb = pageSize / ONE_K;
- }
+ if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1)
+ CRT_fatalError("Cannot get pagesize by sysctl");
+ pageSizeKb = pageSize / ONE_K;
// usable page count vm.stats.vm.v_page_count
// actually usable memory : vm.stats.vm.v_page_count * vm.stats.vm.v_page_size
@@ -149,7 +144,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
fpl->kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf);
if (fpl->kd == NULL) {
- errx(1, "kvm_open: %s", errbuf);
+ CRT_fatalError("kvm_openfiles() failed");
}
fpl->ttys = Hashtable_new(20, true);
@@ -419,7 +414,7 @@ static char* FreeBSDProcessList_readJailName(const struct kinfo_proc* kproc) {
char* jname = NULL;
char jnamebuf[MAXHOSTNAMELEN];
- if (kproc->ki_jid != 0 ) {
+ if (kproc->ki_jid != 0) {
struct iovec jiov[6];
memset(jnamebuf, 0, sizeof(jnamebuf));
@@ -526,13 +521,13 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
}
// from FreeBSD source /src/usr.bin/top/machine.c
- proc->m_virt = kproc->ki_size / pageSize;
- proc->m_resident = kproc->ki_rssize;
+ proc->m_virt = kproc->ki_size / ONE_K;
+ proc->m_resident = kproc->ki_rssize * pageSizeKb;
proc->nlwp = kproc->ki_numthreads;
proc->time = (kproc->ki_runtime + 5000) / 10000;
proc->percent_cpu = 100.0 * ((double)kproc->ki_pctcpu / (double)kernelFScale);
- proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(super->totalMem);
+ proc->percent_mem = 100.0 * proc->m_resident / (double)(super->totalMem);
/*
* TODO
diff --git a/freebsd/Platform.c b/freebsd/Platform.c
index bc77cf4..c74ab6d 100644
--- a/freebsd/Platform.c
+++ b/freebsd/Platform.c
@@ -47,9 +47,7 @@ in the source distribution for its full text.
#include "zfs/ZfsCompressedArcMeter.h"
-ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
-
-int Platform_numberOfFields = LAST_PROCESSFIELD;
+const ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
const SignalItem Platform_signals[] = {
{ .name = " 0 Cancel", .number = 0 },
diff --git a/freebsd/Platform.h b/freebsd/Platform.h
index 5b3b019..36895b8 100644
--- a/freebsd/Platform.h
+++ b/freebsd/Platform.h
@@ -19,11 +19,7 @@ in the source distribution for its full text.
#include "SignalsPanel.h"
-extern ProcessFieldData Process_fields[];
-
-extern ProcessField Platform_defaultFields[];
-
-extern int Platform_numberOfFields;
+extern const ProcessField Platform_defaultFields[];
extern const SignalItem Platform_signals[];
diff --git a/freebsd/ProcessField.h b/freebsd/ProcessField.h
new file mode 100644
index 0000000..cc89282
--- /dev/null
+++ b/freebsd/ProcessField.h
@@ -0,0 +1,17 @@
+#ifndef HEADER_FreeBSDProcessField
+#define HEADER_FreeBSDProcessField
+/*
+htop - freebsd/ProcessField.h
+(C) 2020 htop dev team
+Released under the GNU GPLv2, see the COPYING file
+in the source distribution for its full text.
+*/
+
+
+#define PLATFORM_PROCESS_FIELDS \
+ JID = 100, \
+ JAIL = 101, \
+ // End of list
+
+
+#endif /* HEADER_FreeBSDProcessField */

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