diff options
author | bmilekic <bmilekic@FreeBSD.org> | 2001-06-23 17:04:17 +0000 |
---|---|---|
committer | bmilekic <bmilekic@FreeBSD.org> | 2001-06-23 17:04:17 +0000 |
commit | 7a5abc2b295aefc7e571ca74c0bcde2bb789544d (patch) | |
tree | c272422667212fb8f484644b57433dc0227224a0 /usr.bin/netstat/mbuf.c | |
parent | 17bb3c6612a856845e46b803c6f424ef3609e806 (diff) | |
download | FreeBSD-src-7a5abc2b295aefc7e571ca74c0bcde2bb789544d.zip FreeBSD-src-7a5abc2b295aefc7e571ca74c0bcde2bb789544d.tar.gz |
- 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.
Diffstat (limited to 'usr.bin/netstat/mbuf.c')
-rw-r--r-- | usr.bin/netstat/mbuf.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c index e7de17e..9cf319b 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); |