Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Fix libuv on OpenBSD. struct kproc2 doesn't exist any more.
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 authored and bnoordhuis committed Feb 14, 2012
1 parent 783753e commit e197249
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/unix/openbsd.c
Expand Up @@ -18,13 +18,20 @@
* IN THE SOFTWARE.
*/

#include "uv.h"
#include "internal.h"

#include <sys/types.h>
#include <sys/param.h>
#include <sys/resource.h>
#include <sys/sched.h>
#include <sys/time.h>
#include <sys/sysctl.h>

#include <errno.h>
#include <fcntl.h>
#include <kvm.h>
#include <paths.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -159,17 +166,17 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) {

uv_err_t uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL;
struct kinfo_proc2 *kinfo = NULL;
struct kinfo_proc *kinfo = NULL;
pid_t pid;
int nprocs, max_size = sizeof(struct kinfo_proc2);
int nprocs, max_size = sizeof(struct kinfo_proc);
size_t page_size = getpagesize();

pid = getpid();

kd = kvm_open(NULL, _PATH_MEM, NULL, O_RDONLY, "kvm_open");
if (kd == NULL) goto error;

kinfo = kvm_getproc2(kd, KERN_PROC_PID, pid, max_size, &nprocs);
kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, max_size, &nprocs);
if (kinfo == NULL) goto error;

*rss = kinfo->p_vm_rssize * page_size;
Expand Down Expand Up @@ -207,18 +214,18 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uint64_t info[CPUSTATES];
char model[512];
int numcpus = 1;
static int which[] = {CTL_HW, HW_MODEL, NULL};
static int which[] = {CTL_HW,HW_MODEL,0};
size_t size;
uv_cpu_info_t* cpu_info;

size = sizeof(model);
if (sysctl(which, 2, &model, &size, NULL, 0) < 0) {
return -1;
return uv__new_sys_error(errno);
}
which[1] = HW_NCPU;
size = sizeof(numcpus);
if (sysctl(which, 2, &numcpus, &size, NULL, 0) < 0) {
return -1;
return uv__new_sys_error(errno);
}

*cpu_infos = (uv_cpu_info_t*)malloc(numcpus * sizeof(uv_cpu_info_t));
Expand Down Expand Up @@ -248,11 +255,11 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {

cpu_info = &(*cpu_infos)[i];

cpu_info->cpu_times.user = (uint64_t)(info[CP_USER]) * multiplier);
cpu_info->cpu_times.nice = ((uint64_t)(info[CP_NICE]) * multiplier);
cpu_info->cpu_times.sys = (uint64_t)(info[CP_SYS]) * multiplier));
cpu_info->cpu_times.idle = (uint64_t)(info[CP_IDLE]) * multiplier));
cpu_info->cpu_times.irq = (uint64_t)(info[CP_INTR]) * multiplier));
cpu_info->cpu_times.user = (uint64_t)(info[CP_USER]) * multiplier;
cpu_info->cpu_times.nice = (uint64_t)(info[CP_NICE]) * multiplier;
cpu_info->cpu_times.sys = (uint64_t)(info[CP_SYS]) * multiplier;
cpu_info->cpu_times.idle = (uint64_t)(info[CP_IDLE]) * multiplier;
cpu_info->cpu_times.irq = (uint64_t)(info[CP_INTR]) * multiplier;

cpu_info->model = strdup(model);
cpu_info->speed = cpuspeed;
Expand All @@ -266,7 +273,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
int i;

for (i = 0; i < count; i++) {
free(cpu_infos[i].brand);
free(cpu_infos[i].model);
}

free(cpu_infos);
Expand Down

0 comments on commit e197249

Please sign in to comment.