From: Sergey Kandaurov Date: Thu, 24 May 2018 17:32:09 +0000 (+0300) Subject: Using getrandom() libc interface. X-Git-Tag: 0.2.1~7 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=b52b11cc8566137b2e06455e93467028870f8590;p=njs.git Using getrandom() libc interface. Available since Glibc 2.25, and FreeBSD 12.0. --- diff --git a/nxt/auto/getrandom b/nxt/auto/getrandom index 00e85daf..e3fbc598 100644 --- a/nxt/auto/getrandom +++ b/nxt/auto/getrandom @@ -3,22 +3,45 @@ # Copyright (C) NGINX, Inc. -# Linux 3.17 getrandom(). +# getrandom(). nxt_feature="getrandom()" nxt_feature_name=NXT_HAVE_GETRANDOM -nxt_feature_run=no +nxt_feature_run=yes nxt_feature_incs= nxt_feature_libs= nxt_feature_test="#include - #include - #include + #include int main(void) { char buf[4]; - (void) syscall(SYS_getrandom, buf, 4, 0); + if (getrandom(buf, 4, 0) < 0) { + return 1; + } return 0; }" . ${NXT_AUTO}feature + +if [ $nxt_found = no ]; then + + # Linux 3.17 SYS_getrandom. + + nxt_feature="SYS_getrandom in Linux" + nxt_feature_name=NXT_HAVE_LINUX_SYS_GETRANDOM + nxt_feature_test="#include + #include + #include + + int main(void) { + char buf[4]; + + if (syscall(SYS_getrandom, buf, 4, 0) < 0) { + return 1; + } + + return 0; + }" + . ${NXT_AUTO}feature +fi diff --git a/nxt/nxt_random.c b/nxt/nxt_random.c index d9a8c03c..f99dee08 100644 --- a/nxt/nxt_random.c +++ b/nxt/nxt_random.c @@ -13,6 +13,8 @@ #include #include #if (NXT_HAVE_GETRANDOM) +#include +#elif (NXT_HAVE_LINUX_SYS_GETRANDOM) #include #include #endif @@ -66,7 +68,11 @@ nxt_random_stir(nxt_random_t *r, nxt_pid_t pid) #if (NXT_HAVE_GETRANDOM) - /* Linux 3.17 getrandom(), it is not available in Glibc. */ + n = getrandom(&key, NXT_RANDOM_KEY_SIZE, 0); + +#elif (NXT_HAVE_LINUX_SYS_GETRANDOM) + + /* Linux 3.17 SYS_getrandom, not available in Glibc prior to 2.25. */ n = syscall(SYS_getrandom, &key, NXT_RANDOM_KEY_SIZE, 0);