From 56f9b096322f82081133597ec2f884a90e2e0a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Thu, 11 Dec 2003 07:46:08 +0000 Subject: [PATCH] Revert part of revision 1.74 after bde reminded me of a detail I'd forgotten about how sysctl works. This removes a potential (though not very likely) race that 1.74 introduced. --- usr.bin/vmstat/vmstat.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 3255e7be6e39..e034911fd1ed 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -852,10 +852,13 @@ dointr(void) kread(X_INTRCNT, intrcnt, intrcntlen); kread(X_INTRNAMES, intrname, inamlen); } else { - mysysctl("hw.intrcnt", NULL, &intrcntlen, NULL, 0); - if ((intrcnt = malloc(intrcntlen)) == NULL) - err(1, "calloc()"); - mysysctl("hw.intrcnt", intrcnt, &intrcntlen, NULL, 0); + for (intrcnt = NULL, intrcntlen = 1024; ; intrcntlen *= 2) { + if ((intrcnt = reallocf(intrcnt, intrcntlen)) == NULL) + err(1, "reallocf()"); + if (mysysctl("hw.intrcnt", + intrcnt, &intrcntlen, NULL, 0) == 0) + break; + } for (intrname = NULL, inamlen = 1024; ; inamlen *= 2) { if ((intrname = reallocf(intrname, inamlen)) == NULL) err(1, "reallocf()");