aboutsummaryrefslogtreecommitdiffstats
path: root/openbsd
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 /openbsd
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 'openbsd')
-rw-r--r--openbsd/OpenBSDProcess.c59
-rw-r--r--openbsd/OpenBSDProcess.h9
-rw-r--r--openbsd/OpenBSDProcessList.c27
-rw-r--r--openbsd/Platform.c4
-rw-r--r--openbsd/Platform.h6
-rw-r--r--openbsd/ProcessField.h15
6 files changed, 55 insertions, 65 deletions
diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c
index df5002a..00aea63 100644
--- a/openbsd/OpenBSDProcess.c
+++ b/openbsd/OpenBSDProcess.c
@@ -16,7 +16,7 @@ in the source distribution for its full text.
#include "XUtils.h"
-ProcessFieldData Process_fields[] = {
+const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
[0] = {
.name = "",
.title = NULL,
@@ -25,9 +25,10 @@ ProcessFieldData Process_fields[] = {
},
[PID] = {
.name = "PID",
- .title = " PID ",
+ .title = "PID",
.description = "Process/thread ID",
.flags = 0,
+ .pidColumn = true,
},
[COMM] = {
.name = "Command",
@@ -43,21 +44,24 @@ ProcessFieldData Process_fields[] = {
},
[PPID] = {
.name = "PPID",
- .title = " PPID ",
+ .title = "PPID",
.description = "Parent process ID",
.flags = 0,
+ .pidColumn = true,
},
[PGRP] = {
.name = "PGRP",
- .title = " PGRP ",
+ .title = "PGRP",
.description = "Process group ID",
.flags = 0,
+ .pidColumn = true,
},
[SESSION] = {
.name = "SESSION",
- .title = " SESN ",
+ .title = "SESN",
.description = "Process's session ID",
.flags = 0,
+ .pidColumn = true,
},
[TTY_NR] = {
.name = "TTY_NR",
@@ -67,9 +71,10 @@ ProcessFieldData Process_fields[] = {
},
[TPGID] = {
.name = "TPGID",
- .title = " TPGID ",
+ .title = "TPGID",
.description = "Process ID of the fg process group of the controlling terminal",
.flags = 0,
+ .pidColumn = true,
},
[MINFLT] = {
.name = "MINFLT",
@@ -163,28 +168,13 @@ ProcessFieldData Process_fields[] = {
},
[TGID] = {
.name = "TGID",
- .title = " TGID ",
+ .title = "TGID",
.description = "Thread group ID (i.e. process ID)",
.flags = 0,
- },
- [LAST_PROCESSFIELD] = {
- .name = "*** report bug! ***",
- .title = NULL,
- .description = NULL,
- .flags = 0,
+ .pidColumn = true,
},
};
-ProcessPidColumn Process_pidColumns[] = {
- { .id = PID, .label = "PID" },
- { .id = PPID, .label = "PPID" },
- { .id = TPGID, .label = "TPGID" },
- { .id = TGID, .label = "TGID" },
- { .id = PGRP, .label = "PGRP" },
- { .id = SESSION, .label = "SESN" },
- { .id = 0, .label = NULL },
-};
-
Process* OpenBSDProcess_new(const Settings* settings) {
OpenBSDProcess* this = xCalloc(sizeof(OpenBSDProcess), 1);
Object_setClass(this, Class(OpenBSDProcess));
@@ -209,28 +199,20 @@ static void OpenBSDProcess_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 OpenBSDProcess_compare(const void* v1, const void* v2) {
- const OpenBSDProcess *p1, *p2;
- const Settings *settings = ((const Process*)v1)->settings;
-
- if (settings->direction == 1) {
- p1 = (const OpenBSDProcess*)v1;
- p2 = (const OpenBSDProcess*)v2;
- } else {
- p2 = (const OpenBSDProcess*)v1;
- p1 = (const OpenBSDProcess*)v2;
- }
+static int OpenBSDProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) {
+ const OpenBSDProcess* p1 = (const OpenBSDProcess*)v1;
+ const OpenBSDProcess* p2 = (const OpenBSDProcess*)v2;
// remove if actually used
(void)p1; (void)p2;
- switch (settings->sortKey) {
+ switch (key) {
// add OpenBSD-specific fields here
default:
- return Process_compare(v1, v2);
+ return Process_compareByKey_Base(v1, v2, key);
}
}
@@ -239,9 +221,10 @@ const ProcessClass OpenBSDProcess_class = {
.extends = Class(Process),
.display = Process_display,
.delete = Process_delete,
- .compare = OpenBSDProcess_compare
+ .compare = Process_compare
},
.writeField = OpenBSDProcess_writeField,
+ .compareByKey = OpenBSDProcess_compareByKey
};
bool Process_isThread(const Process* this) {
diff --git a/openbsd/OpenBSDProcess.h b/openbsd/OpenBSDProcess.h
index 2d01513..6aab29a 100644
--- a/openbsd/OpenBSDProcess.h
+++ b/openbsd/OpenBSDProcess.h
@@ -15,11 +15,6 @@ in the source distribution for its full text.
#include "Settings.h"
-typedef enum OpenBSDProcessFields_ {
- // Add platform-specific fields here, with ids >= 100
- LAST_PROCESSFIELD = 100,
-} OpenBSDProcessField;
-
typedef struct OpenBSDProcess_ {
Process super;
} OpenBSDProcess;
@@ -30,9 +25,7 @@ typedef struct OpenBSDProcess_ {
extern const ProcessClass OpenBSDProcess_class;
-extern ProcessFieldData Process_fields[];
-
-extern ProcessPidColumn Process_pidColumns[];
+extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
Process* OpenBSDProcess_new(const Settings* settings);
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c
index 5412030..ff5c927 100644
--- a/openbsd/OpenBSDProcessList.c
+++ b/openbsd/OpenBSDProcessList.c
@@ -8,7 +8,6 @@ in the source distribution for its full text.
#include "OpenBSDProcessList.h"
-#include <err.h>
#include <kvm.h>
#include <limits.h>
#include <stdlib.h>
@@ -34,6 +33,8 @@ in the source distribution for its full text.
static long fscale;
+static int pageSize;
+static int pageSizeKB;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
const int mib[] = { CTL_HW, HW_NCPU };
@@ -55,9 +56,13 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
size = sizeof(fscale);
if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) {
- err(1, "fscale sysctl call failed");
+ CRT_fatalError("fscale sysctl call failed");
}
+ if ((pageSize = sysconf(_SC_PAGESIZE)) == -1)
+ CRT_fatalError("pagesize sysconf call failed");
+ pageSizeKB = pageSize / ONE_K;
+
for (int i = 0; i <= pl->cpuCount; i++) {
CPUData* d = opl->cpus + i;
d->totalTime = 1;
@@ -66,7 +71,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui
opl->kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
if (opl->kd == NULL) {
- errx(1, "kvm_open: %s", errbuf);
+ CRT_fatalError("kvm_openfiles() failed");
}
return pl;
@@ -91,11 +96,11 @@ static void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
size_t size_uvmexp = sizeof(uvmexp);
if (sysctl(uvmexp_mib, 2, &uvmexp, &size_uvmexp, NULL, 0) < 0) {
- err(1, "uvmexp sysctl call failed");
+ CRT_fatalError("uvmexp sysctl call failed");
}
- pl->totalMem = uvmexp.npages * CRT_pageSizeKB;
- pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * CRT_pageSizeKB;
+ pl->totalMem = uvmexp.npages * pageSizeKB;
+ pl->usedMem = (uvmexp.npages - uvmexp.free - uvmexp.paging) * pageSizeKB;
// Taken from OpenBSD systat/iostat.c, top/machine.c and uvm_sysctl(9)
const int bcache_mib[] = { CTL_VFS, VFS_GENERIC, VFS_BCACHESTAT };
@@ -103,10 +108,10 @@ static void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
size_t size_bcstats = sizeof(bcstats);
if (sysctl(bcache_mib, 3, &bcstats, &size_bcstats, NULL, 0) < 0) {
- err(1, "cannot get vfs.bcachestat");
+ CRT_fatalError("cannot get vfs.bcachestat");
}
- pl->cachedMem = bcstats.numbufpages * CRT_pageSizeKB;
+ pl->cachedMem = bcstats.numbufpages * pageSizeKB;
/*
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -222,9 +227,9 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
}
}
- proc->m_virt = kproc->p_vm_dsize;
- proc->m_resident = kproc->p_vm_rssize;
- proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(this->super.totalMem) * 100.0;
+ proc->m_virt = kproc->p_vm_dsize * pageSizeKB;
+ proc->m_resident = kproc->p_vm_rssize * pageSizeKB;
+ proc->percent_mem = proc->m_resident / (double)(this->super.totalMem) * 100.0;
proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount * 100.0);
//proc->nlwp = kproc->p_numthreads;
proc->nice = kproc->p_nice - 20;
diff --git a/openbsd/Platform.c b/openbsd/Platform.c
index dae8072..8ee8141 100644
--- a/openbsd/Platform.c
+++ b/openbsd/Platform.c
@@ -42,9 +42,7 @@ in the source distribution for its full text.
#include "XUtils.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 };
/*
* See /usr/include/sys/signal.h
diff --git a/openbsd/Platform.h b/openbsd/Platform.h
index 0e2d435..e7a5966 100644
--- a/openbsd/Platform.h
+++ b/openbsd/Platform.h
@@ -20,11 +20,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[];
/* see /usr/include/sys/signal.h */
extern const SignalItem Platform_signals[];
diff --git a/openbsd/ProcessField.h b/openbsd/ProcessField.h
new file mode 100644
index 0000000..be4e51e
--- /dev/null
+++ b/openbsd/ProcessField.h
@@ -0,0 +1,15 @@
+#ifndef HEADER_OpenBSDProcessField
+#define HEADER_OpenBSDProcessField
+/*
+htop - openbsd/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 \
+ // End of list
+
+
+#endif /* HEADER_OpenBSDProcessField */

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