Skip to content

Commit 165659e

Browse files
committed
dispatch_workqueue: check for bad syscall
Adding a check to verify that `syscltbyname` didn't fail. If it did, it likely indicates that the `hw.activecpu` syscall doesn't exist. If the call fails, return zero, indicating that we don't know how many cpus are available.
1 parent f1ca39a commit 165659e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tests/dispatch_workqueue.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ activecpu(void)
5555
activecpu = si.dwNumberOfProcessors;
5656
#else
5757
size_t s = sizeof(activecpu);
58-
sysctlbyname("hw.activecpu", &activecpu, &s, NULL, 0);
58+
if (sysctlbyname("hw.activecpu", &activecpu, &s, NULL, 0) != 0)
59+
return 0;
5960
#endif
6061
return activecpu;
6162
}
@@ -66,6 +67,7 @@ int
6667
main(void)
6768
{
6869
uint32_t ncpu = activecpu();
70+
test_uint32_not("Failed to get CPU count", ncpu, 0);
6971

7072
dispatch_test_start("Dispatch workqueue");
7173

0 commit comments

Comments
 (0)