From 7611294da945aab758e0895b4901a6eab46c2e76 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Sat, 15 Feb 2020 18:55:22 -0400 Subject: [PATCH] unix: fix uv_cpu_info always returning UV_ENOTDIR on OpenBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The wrong names and name sizes were being used with `sysctl(2)`, which in particular made the call to get the machine's CPU speed always fail with ENOTDIR. PR-URL: https://github.com/libuv/libuv/pull/2685 Reviewed-By: Ben Noordhuis Reviewed-By: Santiago Gimeno Reviewed-By: Saúl Ibarra Corretgé --- src/unix/openbsd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/unix/openbsd.c b/src/unix/openbsd.c index 5ba0db02..713b6c66 100644 --- a/src/unix/openbsd.c +++ b/src/unix/openbsd.c @@ -185,7 +185,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { char model[512]; int numcpus = 1; int which[] = {CTL_HW,HW_MODEL}; - int percpu[] = {CTL_HW,HW_CPUSPEED,0}; + int percpu[] = {CTL_KERN,KERN_CPTIME2,0}; size_t size; int i, j; uv_cpu_info_t* cpu_info; @@ -206,17 +206,15 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { i = 0; *count = numcpus; + which[1] = HW_CPUSPEED; size = sizeof(cpuspeed); - if (sysctl(which, ARRAY_SIZE(percpu), &cpuspeed, &size, NULL, 0)) + if (sysctl(which, ARRAY_SIZE(which), &cpuspeed, &size, NULL, 0)) goto error; size = sizeof(info); - percpu[0] = CTL_KERN; - percpu[1] = KERN_CPTIME2; for (i = 0; i < numcpus; i++) { percpu[2] = i; - size = sizeof(info); - if (sysctl(which, ARRAY_SIZE(percpu), &info, &size, NULL, 0)) + if (sysctl(percpu, ARRAY_SIZE(percpu), &info, &size, NULL, 0)) goto error; cpu_info = &(*cpu_infos)[i];