From: Sergey Kandaurov Date: Mon, 16 Jul 2018 11:30:41 +0000 (+0300) Subject: Added getentropy() support. X-Git-Tag: 0.2.3~17 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=fc37921f59380c5ec66dd511d5fdf2274b1237d1;p=njs.git Added getentropy() support. --- diff --git a/nxt/auto/getrandom b/nxt/auto/getrandom index 09c52046..5e0e819e 100644 --- a/nxt/auto/getrandom +++ b/nxt/auto/getrandom @@ -46,3 +46,46 @@ if [ $nxt_found = no ]; then }" . ${NXT_AUTO}feature fi + + +if [ $nxt_found = no ]; then + + # OpenBSD 5.6 lacks . + + nxt_feature="getentropy()" + nxt_feature_name=NXT_HAVE_GETENTROPY + nxt_feature_test="#include + + 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 + #include + + int main(void) { + char buf[4]; + + if (getentropy(buf, 4) == -1) { + return 1; + } + + return 0; + }" + . ${NXT_AUTO}feature +fi diff --git a/nxt/nxt_random.c b/nxt/nxt_random.c index f99dee08..9e4b8654 100644 --- a/nxt/nxt_random.c +++ b/nxt/nxt_random.c @@ -17,6 +17,8 @@ #elif (NXT_HAVE_LINUX_SYS_GETRANDOM) #include #include +#elif (NXT_HAVE_GETENTROPY_SYS_RANDOM) +#include #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;