diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-12-05 22:57:07 +0100 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2020-12-06 16:20:55 +0100 |
commit | 57d9ecc5519a44d4d08f1739ab4b741ccfc2d35a (patch) | |
tree | 9643df67c42db491a6c81fbf3121001216daed6d /openbsd/Platform.c | |
parent | 3d15ba51974827693ed7d34149290c812d652dd9 (diff) |
OpenBSD update
- compilation failures like `return &this->this;` -> `return &this->super;`
- iwyu update
- misc cleanup
Diffstat (limited to 'openbsd/Platform.c')
-rw-r--r-- | openbsd/Platform.c | 106 |
1 files changed, 33 insertions, 73 deletions
diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 38fbab67..dae80724 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -7,40 +7,39 @@ in the source distribution for its full text. */ #include "Platform.h" -#include "Macros.h" -#include "Meter.h" + +#include <errno.h> +#include <kvm.h> +#include <limits.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <sys/resource.h> +#include <sys/sensors.h> +#include <sys/sysctl.h> +#include <sys/time.h> +#include <sys/types.h> +#include <uvm/uvmexp.h> + #include "CPUMeter.h" -#include "MemoryMeter.h" -#include "SwapMeter.h" -#include "TasksMeter.h" -#include "LoadAverageMeter.h" -#include "UptimeMeter.h" #include "ClockMeter.h" #include "DateMeter.h" #include "DateTimeMeter.h" #include "HostnameMeter.h" -#include "SignalsPanel.h" +#include "LoadAverageMeter.h" +#include "Macros.h" +#include "MemoryMeter.h" +#include "Meter.h" #include "OpenBSDProcess.h" #include "OpenBSDProcessList.h" - -#include <sys/param.h> -#include <sys/sysctl.h> -#include <sys/sensors.h> -#include <sys/swap.h> - -#include <unistd.h> -#include <stdlib.h> -#include <stdint.h> -#include <string.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/resource.h> -#include <time.h> -#include <fcntl.h> -#include <kvm.h> -#include <limits.h> -#include <errno.h> -#include <math.h> +#include "ProcessList.h" +#include "Settings.h" +#include "SignalsPanel.h" +#include "SwapMeter.h" +#include "TasksMeter.h" +#include "UptimeMeter.h" +#include "XUtils.h" ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; @@ -131,10 +130,9 @@ void Platform_setBindings(Htop_Action* keys) { (void) keys; } -// preserved from FreeBSD port int Platform_getUptime() { struct timeval bootTime, currTime; - int mib[2] = { CTL_KERN, KERN_BOOTTIME }; + const int mib[2] = { CTL_KERN, KERN_BOOTTIME }; size_t size = sizeof(bootTime); int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); @@ -148,7 +146,7 @@ int Platform_getUptime() { void Platform_getLoadAverage(double* one, double* five, double* fifteen) { struct loadavg loadAverage; - int mib[2] = { CTL_VM, VM_LOADAVG }; + const int mib[2] = { CTL_VM, VM_LOADAVG }; size_t size = sizeof(loadAverage); int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0); @@ -164,12 +162,12 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { } int Platform_getMaxPid() { - // this is hard-coded in sys/sys/proc.h - no sysctl exists + // this is hard-coded in sys/proc.h - no sysctl exists return 99999; } double Platform_setCPUValues(Meter* this, int cpu) { - const OpenBSDProcessList* pl = (OpenBSDProcessList*) this->pl; + const OpenBSDProcessList* pl = (const OpenBSDProcessList*) this->pl; const CPUData* cpuData = &(pl->cpus[cpu]); double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod; double totalPercent; @@ -195,9 +193,6 @@ double Platform_setCPUValues(Meter* this, int cpu) { } totalPercent = CLAMP(totalPercent, 0.0, 100.0); - if (isnan(totalPercent)) { - totalPercent = 0.0; - } v[CPU_METER_TEMPERATURE] = NAN; @@ -216,45 +211,10 @@ void Platform_setMemoryValues(Meter* this) { this->values[2] = cachedMem; } -/* - * Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com> - * All rights reserved. - * - * Taken almost directly from OpenBSD's top(1) - */ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; - struct swapent* swdev; - unsigned long long int total, used; - int nswap, rnswap, i; - nswap = swapctl(SWAP_NSWAP, 0, 0); - if (nswap == 0) { - return; - } - - swdev = xCalloc(nswap, sizeof(*swdev)); - - rnswap = swapctl(SWAP_STATS, swdev, nswap); - if (rnswap == -1) { - free(swdev); - return; - } - - // if rnswap != nswap, then what? - - /* Total things up */ - total = used = 0; - for (i = 0; i < nswap; i++) { - if (swdev[i].se_flags & SWF_ENABLE) { - used += (swdev[i].se_inuse / (1024 / DEV_BSIZE)); - total += (swdev[i].se_nblks / (1024 / DEV_BSIZE)); - } - } - - this->total = pl->totalSwap = total; - this->values[0] = pl->usedSwap = used; - - free(swdev); + this->total = pl->totalSwap; + this->values[0] = pl->usedSwap; } char* Platform_getProcessEnv(pid_t pid) { @@ -350,7 +310,7 @@ static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, si } void Platform_getBattery(double* percent, ACPresence* isOnAC) { - static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0}; + int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0}; struct sensor s; size_t slen = sizeof(struct sensor); struct sensordev snsrdev; |