diff --git a/openbsd/OpenBSDMachine.c b/openbsd/OpenBSDMachine.c index e8ff92320..0edb90be9 100644 --- a/openbsd/OpenBSDMachine.c +++ b/openbsd/OpenBSDMachine.c @@ -6,6 +6,8 @@ Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "openbsd/OpenBSDMachine.h" #include @@ -96,10 +98,10 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) { Machine_init(super, usersTable, userId); - OpenBSDProcessList_updateCPUcount(this); + OpenBSDProcessTable_updateCPUcount(this); size = sizeof(this->fscale); - if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0) { + if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0 || this->fscale <= 0) { CRT_fatalError("fscale sysctl call failed"); } @@ -129,7 +131,7 @@ void Machine_delete(Machine* super) { } static void OpenBSDMachine_scanMemoryInfo(OpenBSDMachine* this) { - Machine* host = &this->super; + Machine* super = &this->super; const int uvmexp_mib[] = { CTL_VM, VM_UVMEXP }; struct uvmexp uvmexp; size_t size_uvmexp = sizeof(uvmexp); @@ -230,7 +232,7 @@ static void kernelCPUTimesToHtop(const u_int64_t* times, CPUData* cpu) { } static void OpenBSDMachine_scanCPUTime(OpenBSDMachine* this) { - Machine* host = &this->super; + Machine* super = &this->super; u_int64_t kernelTimes[CPUSTATES] = {0}; u_int64_t avg[CPUSTATES] = {0}; diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index 0875dc00f..681d516d9 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -6,6 +6,8 @@ Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "openbsd/OpenBSDProcess.h" #include @@ -217,17 +219,20 @@ void Process_delete(Object* cast) { free(this); } -static void OpenBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { - //const OpenBSDProcess* op = (const OpenBSDProcess*) this; +static void OpenBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) { + const OpenBSDProcess* op = (const OpenBSDProcess*) super; + char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; - //int n = sizeof(buffer) - 1; + //size_t n = sizeof(buffer) - 1; + switch (field) { // add OpenBSD-specific fields here default: - Process_writeField(this, str, field); + Process_writeField(&op->super, str, field); return; } + RichString_appendWide(str, attr, buffer); } @@ -247,11 +252,18 @@ static int OpenBSDProcess_compareByKey(const Process* v1, const Process* v2, Pro const ProcessClass OpenBSDProcess_class = { .super = { - .extends = Class(Process), - .display = Process_display, - .delete = Process_delete, - .compare = Process_compare + .super = { + .extends = Class(Process), + .display = Row_display, + .delete = Process_delete, + .compare = Process_compare + }, + .isHighlighted = Process_rowIsHighlighted, + .isVisible = Process_rowIsVisible, + .matchesFilter = Process_rowMatchesFilter, + .compareByParent = Process_compareByParent, + .sortKeyString = Process_rowGetSortKey, + .writeField = OpenBSDProcess_rowWriteField }, - .writeField = OpenBSDProcess_writeField, .compareByKey = OpenBSDProcess_compareByKey }; diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessTable.c similarity index 77% rename from openbsd/OpenBSDProcessList.c rename to openbsd/OpenBSDProcessTable.c index 84c833c3c..26c6c52b6 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessTable.c @@ -1,12 +1,14 @@ /* -htop - OpenBSDProcessList.c +htop - OpenBSDProcessTable.c (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ -#include "openbsd/OpenBSDProcessList.h" +#include "config.h" // IWYU pragma: keep + +#include "openbsd/OpenBSDProcessTable.h" #include #include @@ -25,30 +27,30 @@ in the source distribution for its full text. #include "Macros.h" #include "Object.h" #include "Process.h" -#include "ProcessList.h" +#include "ProcessTable.h" #include "Settings.h" #include "XUtils.h" #include "openbsd/OpenBSDMachine.h" #include "openbsd/OpenBSDProcess.h" -ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList) { - OpenBSDProcessList* this = xCalloc(1, sizeof(OpenBSDProcessList)); - ProcessList* super = (ProcessList*) this; +ProcessTable* ProcessTable_new(Machine* host, Hashtable* pidMatchList) { + OpenBSDProcessTable* this = xCalloc(1, sizeof(OpenBSDProcessTable)); + Object_setClass(this, Class(ProcessTable)); - ProcessList_init(super, Class(OpenBSDProcess), host, pidMatchList); + ProcessTable* super = &this->super; + ProcessTable_init(super, Class(OpenBSDProcess), host, pidMatchList); return this; } -void ProcessList_delete(ProcessList* super) { - OpenBSDProcessList* this = (OpenBSDProcessList*) super; - - ProcessList_done(super); +void ProcessTable_delete(Object* cast) { + OpenBSDProcessTable* this = (OpenBSDProcessTable*) super; + ProcessTable_done(&this->super); free(this); } -static void OpenBSDProcessList_updateCwd(const struct kinfo_proc* kproc, Process* proc) { +static void OpenBSDProcessTable_updateCwd(const struct kinfo_proc* kproc, Process* proc) { const int mib[] = { CTL_KERN, KERN_PROC_CWD, kproc->p_pid }; char buffer[2048]; size_t size = sizeof(buffer); @@ -68,7 +70,7 @@ static void OpenBSDProcessList_updateCwd(const struct kinfo_proc* kproc, Process free_and_xStrdup(&proc->procCwd, buffer); } -static void OpenBSDProcessList_updateProcessName(kvm_t* kd, const struct kinfo_proc* kproc, Process* proc) { +static void OpenBSDProcessTable_updateProcessName(kvm_t* kd, const struct kinfo_proc* kproc, Process* proc) { Process_updateComm(proc, kproc->p_comm); /* @@ -127,7 +129,7 @@ static double getpcpu(const OpenBSDMachine* ohost, const struct kinfo_proc* kp) return 100.0 * (double)kp->p_pctcpu / ohost->fscale; } -static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { +static void OpenBSDProcessTable_scanProcs(OpenBSDProcessTable* this) { Machine* host = this->super.host; OpenBSDMachine* ohost = (OpenBSDMachine*) host; const Settings* settings = host->settings; @@ -142,7 +144,7 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { /* Ignore main threads */ if (kproc->p_tid != -1) { - Process* containingProcess = ProcessList_findProcess(&this->super, kproc->p_pid); + Process* containingProcess = ProcessTable_findProcess(&this->super, kproc->p_pid); if (containingProcess) { if (((OpenBSDProcess*)containingProcess)->addr == kproc->p_addr) continue; @@ -152,25 +154,25 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { } bool preExisting = false; - Process* proc = ProcessList_getProcess(&this->super, (kproc->p_tid == -1) ? kproc->p_pid : kproc->p_tid, &preExisting, OpenBSDProcess_new); + Process* proc = ProcessTable_getProcess(&this->super, (kproc->p_tid == -1) ? kproc->p_pid : kproc->p_tid, &preExisting, OpenBSDProcess_new); OpenBSDProcess* op = (OpenBSDProcess*) proc; if (!preExisting) { - proc->ppid = kproc->p_ppid; + Process_setParent(proc, kproc->p_ppid); + Process_setThreadGroup(proc, kproc->p_pid); proc->tpgid = kproc->p_tpgid; - proc->tgid = kproc->p_pid; proc->session = kproc->p_sid; proc->pgrp = kproc->p__pgid; proc->isKernelThread = proc->pgrp == 0; proc->isUserlandThread = kproc->p_tid != -1; proc->starttime_ctime = kproc->p_ustart_sec; Process_fillStarttimeBuffer(proc); - ProcessList_add(&this->super, proc); + ProcessTable_add(&this->super, proc); - OpenBSDProcessList_updateProcessName(ohost->kd, kproc, proc); + OpenBSDProcessTable_updateProcessName(ohost->kd, kproc, proc); if (settings->ss->flags & PROCESS_FLAG_CWD) { - OpenBSDProcessList_updateCwd(kproc, proc); + OpenBSDProcessTable_updateCwd(kproc, proc); } proc->tty_nr = kproc->p_tdev; @@ -183,7 +185,7 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { } } else { if (settings->updateProcessNames) { - OpenBSDProcessList_updateProcessName(ohost->kd, kproc, proc); + OpenBSDProcessTable_updateProcessName(ohost->kd, kproc, proc); } } @@ -231,13 +233,13 @@ static void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { this->super.runningTasks++; } - proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); - proc->updated = true; + proc->super.show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); + proc->super.updated = true; } } -void ProcessList_goThroughEntries(ProcessList* super) { - OpenBSDProcessList* this = (OpenBSDProcessList*) super; +void ProcessTable_goThroughEntries(ProcessTable* super) { + OpenBSDProcessTable* this = (OpenBSDProcessTable*) super; - OpenBSDProcessList_scanProcs(this); + OpenBSDProcessTable_scanProcs(this); } diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessTable.h similarity index 50% rename from openbsd/OpenBSDProcessList.h rename to openbsd/OpenBSDProcessTable.h index 8a03fecb8..f911a10be 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessTable.h @@ -1,7 +1,7 @@ -#ifndef HEADER_OpenBSDProcessList -#define HEADER_OpenBSDProcessList +#ifndef HEADER_OpenBSDProcessTable +#define HEADER_OpenBSDProcessTable /* -htop - OpenBSDProcessList.h +htop - OpenBSDProcessTable.h (C) 2014 Hisham H. Muhammad (C) 2015 Michael McConville Released under the GNU GPLv2+, see the COPYING file @@ -11,11 +11,11 @@ in the source distribution for its full text. #include #include -#include "ProcessList.h" +#include "ProcessTable.h" -typedef struct OpenBSDProcessList_ { - ProcessList super; -} OpenBSDProcessList; +typedef struct OpenBSDProcessTable_ { + ProcessTable super; +} OpenBSDProcessTable; #endif diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 065940892..a8b5d212d 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -6,6 +6,8 @@ Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "openbsd/Platform.h" #include @@ -175,7 +177,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale; } -int Platform_getMaxPid(void) { +pid_t Platform_getMaxPid(void) { return 2 * THREAD_PID_OFFSET; } @@ -229,9 +231,9 @@ void Platform_setMemoryValues(Meter* this) { usedMem -= buffersMem + cachedMem; this->total = host->totalMem; this->values[MEMORY_METER_USED] = usedMem; - this->values[MEMORY_METER_BUFFERS] = buffersMem; // this->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" + this->values[MEMORY_METER_BUFFERS] = buffersMem; this->values[MEMORY_METER_CACHE] = cachedMem; // this->values[MEMORY_METER_AVAILABLE] = "available memory" } diff --git a/openbsd/Platform.h b/openbsd/Platform.h index f357006cc..339616c11 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -47,7 +47,7 @@ int Platform_getUptime(void); void Platform_getLoadAverage(double* one, double* five, double* fifteen); -int Platform_getMaxPid(void); +pid_t Platform_getMaxPid(void); double Platform_setCPUValues(Meter* this, unsigned int cpu); @@ -109,7 +109,7 @@ static inline Hashtable* Platform_dynamicColumns(void) { static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { } -static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) { +static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) { return NULL; } @@ -117,4 +117,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p return false; } +static inline Hashtable* Platform_dynamicScreens(void) { + return NULL; +} + +static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { } + +static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { } + +static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { } + +static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { } + #endif