summaryrefslogtreecommitdiff
path: root/src/SimpleRandomizer.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2015-10-03 17:59:39 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2015-10-03 17:59:39 +0900
commitc81b1321122e8509b55c94c0cbca0d8d6d319f0c (patch)
treef24b49dd9cceb006172dbd09da4e5f5d3371241b /src/SimpleRandomizer.cc
parentc63fc414c389c893c80022669a7d75f3c6869c7e (diff)
parent85faafcaf233855042aead1cc522375fa7955d7e (diff)
Merge branch 'master' into random-webseeding
Diffstat (limited to 'src/SimpleRandomizer.cc')
-rw-r--r--src/SimpleRandomizer.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/SimpleRandomizer.cc b/src/SimpleRandomizer.cc
index 31784c3e..6170bee6 100644
--- a/src/SimpleRandomizer.cc
+++ b/src/SimpleRandomizer.cc
@@ -46,6 +46,8 @@
#include "fmt.h"
#ifdef HAVE_GETRANDOM_INTERFACE
+# include <errno.h>
+# include <linux/errno.h>
# include "getrandom_linux.h"
#endif
@@ -95,10 +97,19 @@ void SimpleRandomizer::getRandomBytes(unsigned char* buf, size_t len)
static bool have_random_support = true;
if (have_random_support) {
auto rv = getrandom_linux(buf, len);
- if (rv != -1 || errno != ENOSYS) {
+ if (rv != -1
+#ifdef ENOSYS
+ /* If the system does not know ENOSYS at this point, just leave the
+ * check out. If the call failed, we'll not take this branch at all
+ * and disable support below.
+ */
+ || errno != ENOSYS
+#endif
+ ) {
if (rv < -1) {
A2_LOG_ERROR(fmt("Failed to produce randomness: %d", errno));
}
+ // getrandom is not supposed to fail, ever, so, we want to assert here.
assert(rv >= 0 && (size_t)rv == len);
return;
}