details: http://hg.nginx.org/njs/rev/04dc301f7d5a branches: changeset: 558:04dc301f7d5a user: Sergey Kandaurov <pluk...@nginx.com> date: Mon Jul 16 14:30:41 2018 +0300 description: Added getentropy() support.
diffstat: nxt/auto/getrandom | 43 +++++++++++++++++++++++++++++++++++++++++++ nxt/nxt_random.c | 10 ++++++++++ 2 files changed, 53 insertions(+), 0 deletions(-) diffs (77 lines): diff -r e9d93bfd7714 -r 04dc301f7d5a nxt/auto/getrandom --- a/nxt/auto/getrandom Mon Jul 16 14:21:09 2018 +0300 +++ b/nxt/auto/getrandom Mon Jul 16 14:30:41 2018 +0300 @@ -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 diff -r e9d93bfd7714 -r 04dc301f7d5a nxt/nxt_random.c --- a/nxt/nxt_random.c Mon Jul 16 14:21:09 2018 +0300 +++ b/nxt/nxt_random.c Mon Jul 16 14:30:41 2018 +0300 @@ -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 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; _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel