]> git.kaiwu.me - njs.git/commitdiff
Added getentropy() support.
authorSergey Kandaurov <pluknet@nginx.com>
Mon, 16 Jul 2018 11:30:41 +0000 (14:30 +0300)
committerSergey Kandaurov <pluknet@nginx.com>
Mon, 16 Jul 2018 11:30:41 +0000 (14:30 +0300)
nxt/auto/getrandom
nxt/nxt_random.c

index 09c52046e9d195636c48f6248be1a38ee706ef62..5e0e819e2966c63b6a7d9457534649df1d7225f2 100644 (file)
@@ -46,3 +46,46 @@ if [ $nxt_found = no ]; then
                       }"
     . ${NXT_AUTO}feature
 fi
+
+
+if [ $nxt_found = no ]; then
+
+    # OpenBSD 5.6 lacks <sys/random.h>.
+
+    nxt_feature="getentropy()"
+    nxt_feature_name=NXT_HAVE_GETENTROPY
+    nxt_feature_test="#include <unistd.h>
+
+                      int main(void) {
+                          char  buf[4];
+
+                          if (getentropy(buf, 4) == -1) {
+                              return 1;
+                          }
+
+                          return 0;
+                      }"
+    . ${NXT_AUTO}feature
+fi
+
+
+if [ $nxt_found = no ]; then
+
+    # macOS 10.12.
+
+    nxt_feature="getentropy() in sys/random.h"
+    nxt_feature_name=NXT_HAVE_GETENTROPY_SYS_RANDOM
+    nxt_feature_test="#include <unistd.h>
+                      #include <sys/random.h>
+
+                      int main(void) {
+                          char  buf[4];
+
+                          if (getentropy(buf, 4) == -1) {
+                              return 1;
+                          }
+
+                          return 0;
+                      }"
+    . ${NXT_AUTO}feature
+fi
index f99dee0894237f9c437433b9c349073793d19e93..9e4b8654aaed98814b1a1219045a440c56625529 100644 (file)
@@ -17,6 +17,8 @@
 #elif (NXT_HAVE_LINUX_SYS_GETRANDOM)
 #include <sys/syscall.h>
 #include <linux/random.h>
+#elif (NXT_HAVE_GETENTROPY_SYS_RANDOM)
+#include <sys/random.h>
 #endif
 
 
@@ -76,6 +78,14 @@ nxt_random_stir(nxt_random_t *r, nxt_pid_t pid)
 
     n = syscall(SYS_getrandom, &key, NXT_RANDOM_KEY_SIZE, 0);
 
+#elif (NXT_HAVE_GETENTROPY || NXT_HAVE_GETENTROPY_SYS_RANDOM)
+
+    n = 0;
+
+    if (getentropy(&key, NXT_RANDOM_KEY_SIZE) == 0) {
+        n = NXT_RANDOM_KEY_SIZE;
+    }
+
 #else
 
     n = 0;