aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2019-12-24 14:01:42 -0800
committerGarrett D'Amore <garrett@damore.org>2019-12-24 14:07:25 -0800
commit252ea41be8bab992dadabec0e4f1d77650949f4c (patch)
tree14e87f34b3137745cd2dd8c519070b3319330c3d
parent20dfa3c924dabf20bedf6f82969e7e1467e799af (diff)
downloadnng-252ea41be8bab992dadabec0e4f1d77650949f4c.tar.gz
nng-252ea41be8bab992dadabec0e4f1d77650949f4c.tar.bz2
nng-252ea41be8bab992dadabec0e4f1d77650949f4c.zip
fixes #1038 Linux should use getentropy or getrandom
-rw-r--r--CMakeLists.txt3
-rw-r--r--src/platform/posix/posix_config.h16
-rw-r--r--tests/testutil.c2
3 files changed, 17 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa3bac8b..abe6586b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -327,6 +327,9 @@ else ()
nng_check_func(lockf NNG_HAVE_LOCKF)
nng_check_func(flock NNG_HAVE_FLOCK)
+ nng_check_func(getentropy NNG_HAVE_GETENTROPY)
+ nng_check_func(getrandom NNG_HAVE_GETRANDOM)
+ nng_check_func(arc4random_buf NNG_HAVE_ARC4RANDOM)
nng_check_lib(rt clock_gettime NNG_HAVE_CLOCK_GETTIME)
nng_check_lib(pthread sem_wait NNG_HAVE_SEMAPHORE_PTHREAD)
diff --git a/src/platform/posix/posix_config.h b/src/platform/posix/posix_config.h
index 9afa70c8..2abe51b4 100644
--- a/src/platform/posix/posix_config.h
+++ b/src/platform/posix/posix_config.h
@@ -1,5 +1,5 @@
//
-// Copyright 2016 Garrett D'Amore <garrett@damore.org>
+// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -36,20 +36,30 @@
// #define NNG_USE_GETENTROPY
// #define NNG_USE_ARC4RANDOM
// #define NNG_USE_DEVURANDOM
-// Thesse are options for obtaining entropy to seed the pRNG.
+// These are options for obtaining entropy to seed the pRNG.
// All known modern UNIX variants can support NNG_USE_DEVURANDOM,
// but the other options are better still, but not portable.
#include <time.h>
#ifdef NNG_PLATFORM_POSIX
-
+#if !defined(NNG_USE_DEVURANDOM) && !defined(NNG_USE_GETENTROPY) && \
+ !defined(NNG_USE_GETRANDOM) && !defined(NNG_USE_ARC4RANDOM)
+#if defined(NNG_HAVE_GETENTROPY)
+#define NNG_USE_GETENTROPY 1
+#elif defined(NNG_HAVE_GETRANDOM)
+#define NNG_USE_GETRANDOM 1
+#elif defined(NNG_HAVE_ARC4RANDOM)
+#define NNG_USE_ARC4RANDOM
+#else
// It should never hurt to use DEVURANDOM, since if the device does not
// exist then we won't open it. (Provided: it would be bad if the device
// exists but has somehow very very different semantics. We don't know
// of any such concerns.) This won't be used if any of the other options
// are defined and work.
#define NNG_USE_DEVURANDOM 1
+#endif
+#endif
#define NNG_USE_CLOCKID CLOCK_REALTIME
#ifndef CLOCK_REALTIME
diff --git a/tests/testutil.c b/tests/testutil.c
index 77b985a3..ef748b99 100644
--- a/tests/testutil.c
+++ b/tests/testutil.c
@@ -203,7 +203,7 @@ testutil_next_port(void)
(void) UnlockFileEx(h, 0, MAXDWORD, MAXDWORD, &olp);
#else
fseek(f, 0, SEEK_SET);
- ftruncate(fileno(f), 0);
+ (void) ftruncate(fileno(f), 0);
(void) fprintf(f, "%u", port);
(void) lockf(fileno(f), 0, F_ULOCK);