netbsd: add more robust error handling for sysctl HW_IOSTATS

This commit is contained in:
nia 2021-08-09 08:57:14 +02:00 committed by BenBE
parent 5b8654d341
commit 324f9d048d
1 changed files with 16 additions and 8 deletions

View File

@ -335,17 +335,25 @@ bool Platform_getDiskIO(DiskIOData* data) {
struct io_sysctl *iostats = NULL; struct io_sysctl *iostats = NULL;
size_t size = 0; size_t size = 0;
for (int retry = 3; retry > 0; retry--) {
/* get the size of the IO statistic array */ /* get the size of the IO statistic array */
(void)sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0); if (sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0) < 0)
if (size == 0) CRT_fatalError("Unable to get size of io_sysctl");
return false;
iostats = xMalloc(size); if (size == 0) {
if (sysctl(mib, __arraycount(mib), iostats, &size, NULL, 0) < 0) {
free(iostats); free(iostats);
return false; 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; uint64_t bytesReadSum = 0;
uint64_t bytesWriteSum = 0; uint64_t bytesWriteSum = 0;
uint64_t busyTimeSum = 0; uint64_t busyTimeSum = 0;