aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-03-19 15:23:12 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-03-19 15:23:51 +0100
commit3d3d834324f313328ca1465f28e47e5569721c82 (patch)
tree9a8de73672628137317f14ef3057084e231a8f55
parent67de1ee8bc18afff0f2f9f203803467a2274bfc1 (diff)
parente90e3e684ffa7b25f0dfb5b45e70bb0c358261fb (diff)
downloadbitcoin-3d3d834324f313328ca1465f28e47e5569721c82.tar.xz
Merge #18359: build: fix sysctl() detection on macOS
e90e3e684ffa7b25f0dfb5b45e70bb0c358261fb build: fix sysctl() detection on macOS (fanquake) Pull request description: [`sysctl()` on *BSD](https://www.unix.com/man-page/FreeBSD/3/sysctl/) takes a "const int *name", whereas [`sysctl()` on macOS](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sysctl.3.html) 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); ``` The simplest change seems to be to change the param to a "int *name", which will work during configure on macOS and *BSD systems. For consistency I've changed both calls, but note that macOS doesn't have `KERN_ARND`, so that check will always fail regardless. We can revert/add documentation if preferred. ACKs for top commit: laanwj: Re-ACK e90e3e684ffa7b25f0dfb5b45e70bb0c358261fb Tree-SHA512: 29e9348136fc72882f63079bf10d2490e845d7656aae2c003e282bea49dd2778204a7776a67086bd88c2852af9a07dd04ba358eede7e37029e1c10f73c85d6a5
-rw-r--r--configure.ac10
-rw-r--r--src/random.cpp4
2 files changed, 8 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index 758d31192b..23a6417a1a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -935,11 +935,10 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
AC_MSG_CHECKING(for sysctl)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <sys/sysctl.h>]],
- [[ static const int name[2] = {CTL_KERN, KERN_VERSION};
- #ifdef __linux__
+ [[ #ifdef __linux__
#error "Don't use sysctl on Linux, it's deprecated even when it works"
#endif
- sysctl(name, 2, nullptr, nullptr, nullptr, 0); ]])],
+ sysctl(nullptr, 2, nullptr, nullptr, nullptr, 0); ]])],
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL, 1,[Define this symbol if the BSD sysctl() is available]) ],
[ AC_MSG_RESULT(no)]
)
@@ -947,7 +946,10 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
AC_MSG_CHECKING(for sysctl KERN_ARND)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <sys/sysctl.h>]],
- [[ static const int name[2] = {CTL_KERN, KERN_ARND};
+ [[ #ifdef __linux__
+ #error "Don't use sysctl on Linux, it's deprecated even when it works"
+ #endif
+ static int name[2] = {CTL_KERN, KERN_ARND};
sysctl(name, 2, nullptr, nullptr, nullptr, 0); ]])],
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL_ARND, 1,[Define this symbol if the BSD sysctl(KERN_ARND) is available]) ],
[ AC_MSG_RESULT(no)]
diff --git a/src/random.cpp b/src/random.cpp
index f7f3dd9de3..2a27e6ba0d 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -321,10 +321,10 @@ void GetOSRand(unsigned char *ent32)
RandFailure();
}
#elif defined(HAVE_SYSCTL_ARND)
- /* FreeBSD and similar. It is possible for the call to return less
+ /* FreeBSD, NetBSD and similar. It is possible for the call to return less
* bytes than requested, so need to read in a loop.
*/
- static const int name[2] = {CTL_KERN, KERN_ARND};
+ static int name[2] = {CTL_KERN, KERN_ARND};
int have = 0;
do {
size_t len = NUM_OS_RANDOM_BYTES - have;