Skip to content

Commit e90e3e6

Browse files
committed
build: fix sysctl() detection on macOS
sysctl() on *BSD takes a "const int *name", whereas sysctl() on macOS it takes an "int *name". So our configure check and sysctl() detection on macOS currently fails: ```bash /usr/include/sys/sysctl.h:759:9: note: candidate function not viable: no known conversion from 'const int [2]' to 'int *' for 1st argument int sysctl(int *, u_int, void *, size_t *, void *, size_t); ``` This change removes the name argument from the sysctl() detection check, meaning we will detect correctly on macOS and *BSD. For consistency we also switch to using the more generic, non-const version of the name parameter in the rest of our usage.
1 parent a421e0a commit e90e3e6

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

configure.ac

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,19 +935,21 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
935935
AC_MSG_CHECKING(for sysctl)
936936
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
937937
#include <sys/sysctl.h>]],
938-
[[ static const int name[2] = {CTL_KERN, KERN_VERSION};
939-
#ifdef __linux__
938+
[[ #ifdef __linux__
940939
#error "Don't use sysctl on Linux, it's deprecated even when it works"
941940
#endif
942-
sysctl(name, 2, nullptr, nullptr, nullptr, 0); ]])],
941+
sysctl(nullptr, 2, nullptr, nullptr, nullptr, 0); ]])],
943942
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL, 1,[Define this symbol if the BSD sysctl() is available]) ],
944943
[ AC_MSG_RESULT(no)]
945944
)
946945

947946
AC_MSG_CHECKING(for sysctl KERN_ARND)
948947
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
949948
#include <sys/sysctl.h>]],
950-
[[ static const int name[2] = {CTL_KERN, KERN_ARND};
949+
[[ #ifdef __linux__
950+
#error "Don't use sysctl on Linux, it's deprecated even when it works"
951+
#endif
952+
static int name[2] = {CTL_KERN, KERN_ARND};
951953
sysctl(name, 2, nullptr, nullptr, nullptr, 0); ]])],
952954
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL_ARND, 1,[Define this symbol if the BSD sysctl(KERN_ARND) is available]) ],
953955
[ AC_MSG_RESULT(no)]

src/random.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ void GetOSRand(unsigned char *ent32)
321321
RandFailure();
322322
}
323323
#elif defined(HAVE_SYSCTL_ARND)
324-
/* FreeBSD and similar. It is possible for the call to return less
324+
/* FreeBSD, NetBSD and similar. It is possible for the call to return less
325325
* bytes than requested, so need to read in a loop.
326326
*/
327-
static const int name[2] = {CTL_KERN, KERN_ARND};
327+
static int name[2] = {CTL_KERN, KERN_ARND};
328328
int have = 0;
329329
do {
330330
size_t len = NUM_OS_RANDOM_BYTES - have;

0 commit comments

Comments
 (0)