From f70f5dd367d485c3e89afe329cd5a681e06c5790 Mon Sep 17 00:00:00 2001 From: Bosko Milekic Date: Sat, 23 Jun 2001 17:04:17 +0000 Subject: [PATCH] - Fix space allocation for mbstat structure - Make sure to try hw.ncpu if kern.smp.cpus doesn't exist (i.e. on UP) to get number of CPUs. --- usr.bin/netstat/mbuf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c index e7de17e5cd4..9cf319b8f15 100644 --- a/usr.bin/netstat/mbuf.c +++ b/usr.bin/netstat/mbuf.c @@ -138,7 +138,7 @@ mbpr(u_long mbaddr, u_long mbtaddr, u_long nmbcaddr, u_long nmbufaddr, } #endif - mlen = sizeof mbstat; + mlen = sizeof *mbstat; if ((mbstat = malloc(mlen)) == NULL) { warn("malloc: cannot allocate memory for mbstat"); goto err; @@ -190,6 +190,7 @@ mbpr(u_long mbaddr, u_long mbtaddr, u_long nmbcaddr, u_long nmbufaddr, warn("sysctl: retrieving mb_statpcpu"); goto err; } + mlen = sizeof *mbstat; if (sysctlbyname("kern.ipc.mbstat", mbstat, &mlen, NULL, 0) < 0) { warn("sysctl: retrieving mbstat"); @@ -227,8 +228,9 @@ mbpr(u_long mbaddr, u_long mbtaddr, u_long nmbcaddr, u_long nmbufaddr, goto err; } mlen = sizeof(int); - if (sysctlbyname("kern.smp.cpus", &ncpu, &mlen, NULL, 0) < 0) { - warn("sysctl: retrieving kern.smp.cpus"); + if (sysctlbyname("kern.smp.cpus", &ncpu, &mlen, NULL, 0) < 0 && + sysctlbyname("hw.ncpu", &ncpu, &mlen, NULL, 0) < 0) { + warn("sysctl: retrieving number of cpus"); goto err; } mlen = sizeof(int);