summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornia <nia@NetBSD.org>2021-08-09 08:57:14 +0200
committerBenBE <BenBE@geshi.org>2021-08-09 09:08:37 +0200
commit324f9d048d2866dbdd74451ee988ec608d6677a8 (patch)
tree2f541dcb411ffe8e02b79553c5e6d106748a9a12
parent5b8654d3419e8d369be031f212c48d111309b8c7 (diff)
netbsd: add more robust error handling for sysctl HW_IOSTATS
-rw-r--r--netbsd/Platform.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/netbsd/Platform.c b/netbsd/Platform.c
index 0d717e9d..c0783518 100644
--- a/netbsd/Platform.c
+++ b/netbsd/Platform.c
@@ -335,15 +335,23 @@ bool Platform_getDiskIO(DiskIOData* data) {
struct io_sysctl *iostats = NULL;
size_t size = 0;
- /* get the size of the IO statistic array */
- (void)sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0);
- if (size == 0)
- return false;
-
- iostats = xMalloc(size);
- if (sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0) < 0) {
- free(iostats);
- return false;
+ for (int retry = 3; retry > 0; retry--) {
+ /* get the size of the IO statistic array */
+ if (sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0) < 0)
+ CRT_fatalError("Unable to get size of io_sysctl");
+
+ if (size == 0) {
+ free(iostats);
+ return false;
+ }
+
+ iostats = xRealloc(iostats, size);
+
+ if (sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0) == 0)
+ break;
+
+ if (errno != ENOMEM)
+ CRT_fatalError("Unable to get disk IO statistics");
}
uint64_t bytesReadSum = 0;

© 2014-2024 Faster IT GmbH | imprint | privacy policy