diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2015-11-02 08:46:40 -0500 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-11-02 08:46:40 -0500 |
commit | fd5dd6605adfa15c28eb16c9081e1df977724c78 (patch) | |
tree | 378d459d02164efff71e3bef02869b34d8502048 /openbsd | |
parent | b669540e4e5b62f639146f6c373c131319631e6e (diff) | |
parent | cd3d2337f839c496e98ebc8633c1c0c0b961bb66 (diff) |
Merge pull request #299 from mmcco/master
OpenBSD port updates and error exit improvements
Diffstat (limited to 'openbsd')
-rw-r--r-- | openbsd/OpenBSDProcessList.c | 33 | ||||
-rw-r--r-- | openbsd/Platform.c | 10 |
2 files changed, 21 insertions, 22 deletions
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 10ba2d62..210328aa 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -13,7 +13,6 @@ in the source distribution for its full text. #include <unistd.h> #include <stdlib.h> #include <errno.h> -#include <err.h> #include <sys/types.h> #include <sys/param.h> #include <sys/proc.h> @@ -52,7 +51,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui OpenBSDProcessList* fpl = calloc(1, sizeof(OpenBSDProcessList)); ProcessList* pl = (ProcessList*) fpl; size_t size = sizeof(pl->cpuCount); - + ProcessList_init(pl, Class(OpenBSDProcess), usersTable, pidWhiteList, userId); pl->cpuCount = 1; // default to 1 on sysctl() error (void)sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0); @@ -60,13 +59,13 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, 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"); for (i = 0; i < pl->cpuCount; i++) { fpl->cpus[i].totalTime = 1; fpl->cpus[i].totalPeriod = 1; } - + pageSizeKb = PAGE_SIZE_KB; // XXX: last arg should eventually be an errbuf @@ -79,7 +78,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui void ProcessList_delete(ProcessList* this) { const OpenBSDProcessList* fpl = (OpenBSDProcessList*) this; if (fpl->kd) kvm_close(fpl->kd); - + ProcessList_done(this); free(this); } @@ -90,7 +89,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { size_t size = sizeof(uvmexp); if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) { - err(1, "uvmexp sysctl call failed"); + CRT_fatalError("uvmexp sysctl call failed"); } //kb_pagesize = uvmexp.pagesize / 1024; @@ -99,7 +98,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { /* const OpenBSDProcessList* fpl = (OpenBSDProcessList*) pl; - + size_t len = sizeof(pl->totalMem); sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0); pl->totalMem /= 1024; @@ -108,7 +107,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { pl->freeMem = pl->totalMem - pl->usedMem; sysctl(MIB_vm_stats_vm_v_cache_count, 4, &(pl->cachedMem), &len, NULL, 0); pl->cachedMem *= pageSizeKb; - + struct kvm_swap swap[16]; int nswap = kvm_getswapinfo(fpl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0); pl->totalSwap = 0; @@ -119,7 +118,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { } pl->totalSwap *= pageSizeKb; pl->usedSwap *= pageSizeKb; - + pl->sharedMem = 0; // currently unused pl->buffersMem = 0; // not exposed to userspace */ @@ -133,11 +132,11 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in argv = kvm_getargv(kd, kproc, 500); if (argv == NULL) - err(1, "kvm call failed"); + CRT_fatalError("kvm call failed"); str = buf = malloc(len+1); if (str == NULL) - err(1, "out of memory"); + CRT_fatalError("out of memory"); while (*argv != NULL) { cpsz = MIN(len, strlen(*argv)); @@ -179,23 +178,23 @@ void ProcessList_goThroughEntries(ProcessList* this) { OpenBSDProcess* fp; int count = 0; int i; - + OpenBSDProcessList_scanMemoryInfo(this); - + // use KERN_PROC_KTHREAD to also include kernel threads struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count); //struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count); - + for (i = 0; i < count; i++) { kproc = &kprocs[i]; - + preExisting = false; proc = ProcessList_getProcess(this, kproc->p_pid, &preExisting, (Process_New) OpenBSDProcess_new); fp = (OpenBSDProcess*) proc; proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); - + if (!preExisting) { proc->ppid = kproc->p_ppid; proc->tpgid = kproc->p_tpgid; @@ -240,7 +239,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { if (Process_isKernelThread(proc)) { this->kernelThreads++; } - + this->totalTasks++; // SRUN ('R') means runnable, not running if (proc->state == 'P') { diff --git a/openbsd/Platform.c b/openbsd/Platform.c index a961c77e..7114d941 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -38,6 +38,7 @@ in the source distribution for its full text. /*{ #include "Action.h" #include "BatteryMeter.h" +#include "SignalsPanel.h" extern ProcessFieldData Process_fields[]; @@ -167,7 +168,7 @@ int Platform_getUptime() { struct timeval bootTime, currTime; int mib[2] = { CTL_KERN, KERN_BOOTTIME }; size_t size = sizeof(bootTime); - + int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); if (err) { return -1; @@ -181,7 +182,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { struct loadavg loadAverage; int mib[2] = { CTL_VM, VM_LOADAVG }; size_t size = sizeof(loadAverage); - + int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0); if (err) { *one = 0; @@ -210,8 +211,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { size_t size = sizeof(double) * CPUSTATES; int mib[] = { CTL_KERN, KERN_CPTIME2, cpu-1 }; if (sysctl(mib, 3, new_v, &size, NULL, 0) == -1) { - puts("err!"); - //return 0.; + return 0.; } // XXX: why? @@ -232,7 +232,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { if (perc <= 100. && perc >= 0.) { return perc; } else { - return 12.34; + return 0.; } } |