OpenBSD fixes and updates

I forgot how awful the process name logic was. It was an initial hack to
get it running, and I forgot to clean it up.

I also had to change a few includes and error function uses.
This commit is contained in:
Michael McConville 2016-01-02 11:57:53 -05:00
parent fd5dd6605a
commit 22cfda6332
2 changed files with 27 additions and 28 deletions

View File

@ -12,6 +12,7 @@ in the source distribution for its full text.
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
@ -59,7 +60,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
size = sizeof(fscale); size = sizeof(fscale);
if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0) if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0)
CRT_fatalError("fscale sysctl call failed"); errx(1, "fscale sysctl call failed");
for (i = 0; i < pl->cpuCount; i++) { for (i = 0; i < pl->cpuCount; i++) {
fpl->cpus[i].totalTime = 1; fpl->cpus[i].totalTime = 1;
@ -89,7 +90,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
size_t size = sizeof(uvmexp); size_t size = sizeof(uvmexp);
if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) { if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) < 0) {
CRT_fatalError("uvmexp sysctl call failed"); errx(1, "uvmexp sysctl call failed");
} }
//kb_pagesize = uvmexp.pagesize / 1024; //kb_pagesize = uvmexp.pagesize / 1024;
@ -125,34 +126,31 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
} }
char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) {
char *str, *buf, **argv; char *s, *buf, **arg;
size_t cpsz; size_t cpsz, len = 0, n;
size_t len = 500; int i;
argv = kvm_getargv(kd, kproc, 500); arg = kvm_getargv(kd, kproc, 500);
if (arg == NULL) {
if (argv == NULL) return "[zombie]";
CRT_fatalError("kvm call failed"); // the FreeBSD port uses ki_comm, but we don't have it
//return strndup(kproc->ki_comm);
str = buf = malloc(len+1); }
if (str == NULL) for (i = 0; arg[i] != NULL; i++) {
CRT_fatalError("out of memory"); len += strlen(arg[i]) + 1;
}
while (*argv != NULL) { buf = s = malloc(len);
cpsz = MIN(len, strlen(*argv)); for (i = 0; arg[i] != NULL; i++) {
strncpy(buf, *argv, cpsz); n = strlcpy(buf, arg[i], (s + len) - buf);
buf += cpsz; buf += n;
len -= cpsz; if (i == 0) {
argv++; *basenameEnd = n;
if (len > 0) { }
*buf = ' ';
buf++; buf++;
len--; *buf = ' ';
} }
} *(buf - 1) = '\0';
return s;
*buf = '\0';
return str;
} }
/* /*

View File

@ -11,6 +11,7 @@ in the source distribution for its full text.
*/ */
#include "Action.h" #include "Action.h"
#include "SignalsPanel.h"
#include "BatteryMeter.h" #include "BatteryMeter.h"
extern ProcessFieldData Process_fields[]; extern ProcessFieldData Process_fields[];