diff options
author | Michael Klein <michael.klein@puffin.lb.shuttle.de> | 2016-01-06 22:39:57 +0100 |
---|---|---|
committer | Michael Klein <michael.klein@puffin.lb.shuttle.de> | 2016-01-06 22:39:57 +0100 |
commit | b10e54cdee3d964ae8c1962989bc9bc0e804f19b (patch) | |
tree | 1af98b120f75583459e83ff8c281fa348c30ff1c /openbsd | |
parent | cc23d13f87e74d4dc2cc781da28ddc07f3860b63 (diff) | |
parent | fc4c9757b01676e7cc16a50f04a3be25c00abbf0 (diff) |
Merge remote-tracking branch 'upstream/master' into envscreen
Diffstat (limited to 'openbsd')
-rw-r--r-- | openbsd/OpenBSDCRT.c | 2 | ||||
-rw-r--r-- | openbsd/OpenBSDProcessList.c | 106 | ||||
-rw-r--r-- | openbsd/Platform.h | 1 |
3 files changed, 61 insertions, 48 deletions
diff --git a/openbsd/OpenBSDCRT.c b/openbsd/OpenBSDCRT.c index 552ca30d..c5dcec4a 100644 --- a/openbsd/OpenBSDCRT.c +++ b/openbsd/OpenBSDCRT.c @@ -16,7 +16,7 @@ void CRT_handleSIGSEGV(int sgn) { CRT_done(); fprintf(stderr, "\n\nhtop " VERSION " aborting.\n"); fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); - fprintf(stderr, "\nPlease contact your platform package mantainer!\n\n"); + fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); abort(); } diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 210328aa..6da38efc 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -12,6 +12,7 @@ in the source distribution for its full text. #include <unistd.h> #include <stdlib.h> +#include <err.h> #include <errno.h> #include <sys/types.h> #include <sys/param.h> @@ -47,37 +48,41 @@ static long fscale; ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { int mib[] = { CTL_HW, HW_NCPU }; int fmib[] = { CTL_KERN, KERN_FSCALE }; - int i; - OpenBSDProcessList* fpl = calloc(1, sizeof(OpenBSDProcessList)); - ProcessList* pl = (ProcessList*) fpl; + int i, e; + OpenBSDProcessList* opl = calloc(1, sizeof(OpenBSDProcessList)); + ProcessList* pl = (ProcessList*) opl; 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); - fpl->cpus = realloc(fpl->cpus, pl->cpuCount * sizeof(CPUData)); + e = sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0); + if (e == -1 || pl->cpuCount < 1) { + pl->cpuCount = 1; + } + opl->cpus = realloc(opl->cpus, pl->cpuCount * sizeof(CPUData)); size = sizeof(fscale); if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) - CRT_fatalError("fscale sysctl call failed"); + err(1, "fscale sysctl call failed"); for (i = 0; i < pl->cpuCount; i++) { - fpl->cpus[i].totalTime = 1; - fpl->cpus[i].totalPeriod = 1; + opl->cpus[i].totalTime = 1; + opl->cpus[i].totalPeriod = 1; } pageSizeKb = PAGE_SIZE_KB; // XXX: last arg should eventually be an errbuf - fpl->kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL); - assert(fpl->kd); + opl->kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL); + assert(opl->kd); return pl; } void ProcessList_delete(ProcessList* this) { - const OpenBSDProcessList* fpl = (OpenBSDProcessList*) this; - if (fpl->kd) kvm_close(fpl->kd); + const OpenBSDProcessList* opl = (OpenBSDProcessList*) this; + if (opl->kd) kvm_close(opl->kd); + + free(opl->cpus); ProcessList_done(this); free(this); @@ -89,7 +94,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { size_t size = sizeof(uvmexp); if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) { - CRT_fatalError("uvmexp sysctl call failed"); + err(1, "uvmexp sysctl call failed"); } //kb_pagesize = uvmexp.pagesize / 1024; @@ -97,7 +102,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { pl->totalMem = uvmexp.npages * pageSizeKb; /* - const OpenBSDProcessList* fpl = (OpenBSDProcessList*) pl; + const OpenBSDProcessList* opl = (OpenBSDProcessList*) pl; size_t len = sizeof(pl->totalMem); sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0); @@ -109,7 +114,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { pl->cachedMem *= pageSizeKb; struct kvm_swap swap[16]; - int nswap = kvm_getswapinfo(fpl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0); + int nswap = kvm_getswapinfo(opl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0); pl->totalSwap = 0; pl->usedSwap = 0; for (int i = 0; i < nswap; i++) { @@ -125,34 +130,41 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { } char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { - char *str, *buf, **argv; - size_t cpsz; - size_t len = 500; - - argv = kvm_getargv(kd, kproc, 500); - - if (argv == NULL) - CRT_fatalError("kvm call failed"); - - str = buf = malloc(len+1); - if (str == NULL) - CRT_fatalError("out of memory"); - - while (*argv != NULL) { - cpsz = MIN(len, strlen(*argv)); - strncpy(buf, *argv, cpsz); - buf += cpsz; - len -= cpsz; - argv++; - if (len > 0) { - *buf = ' '; - buf++; - len--; - } - } + char *s, *buf, **arg; + size_t cpsz, len = 0, n; + int i; - *buf = '\0'; - return str; + /* + * We attempt to fall back to just the command name (argv[0]) if we + * fail to construct the full command at any point. + */ + arg = kvm_getargv(kd, kproc, 500); + if (arg == NULL) { + if ((s = strdup(kproc->p_comm)) == NULL) { + err(1, NULL); + } + return s; + } + for (i = 0; arg[i] != NULL; i++) { + len += strlen(arg[i]) + 1; + } + if ((buf = s = malloc(len)) == NULL) { + if ((s = strdup(kproc->p_comm)) == NULL) { + err(1, NULL); + } + return s; + } + for (i = 0; arg[i] != NULL; i++) { + n = strlcpy(buf, arg[i], (s + len) - buf); + buf += n; + if (i == 0) { + *basenameEnd = n; + } + *buf = ' '; + buf++; + } + *(buf - 1) = '\0'; + return s; } /* @@ -168,7 +180,7 @@ double getpcpu(const struct kinfo_proc *kp) { } void ProcessList_goThroughEntries(ProcessList* this) { - OpenBSDProcessList* fpl = (OpenBSDProcessList*) this; + OpenBSDProcessList* opl = (OpenBSDProcessList*) this; Settings* settings = this->settings; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; @@ -182,7 +194,7 @@ void ProcessList_goThroughEntries(ProcessList* this) { 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 = kvm_getprocs(opl->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++) { @@ -206,11 +218,11 @@ void ProcessList_goThroughEntries(ProcessList* this) { proc->starttime_ctime = kproc->p_ustart_sec; proc->user = UsersTable_getRef(this->usersTable, proc->st_uid); ProcessList_add((ProcessList*)this, proc); - proc->comm = OpenBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset); + proc->comm = OpenBSDProcessList_readProcessName(opl->kd, kproc, &proc->basenameOffset); } else { if (settings->updateProcessNames) { free(proc->comm); - proc->comm = OpenBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset); + proc->comm = OpenBSDProcessList_readProcessName(opl->kd, kproc, &proc->basenameOffset); } } diff --git a/openbsd/Platform.h b/openbsd/Platform.h index a59d2ef5..d8dea1b1 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -11,6 +11,7 @@ in the source distribution for its full text. */ #include "Action.h" +#include "SignalsPanel.h" #include "BatteryMeter.h" extern ProcessFieldData Process_fields[]; |