# 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 <unistd.h>
- #include <sys/syscall.h>
- #include <linux/random.h>
+ #include <sys/random.h>
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 <unistd.h>
+ #include <sys/syscall.h>
+ #include <linux/random.h>
+
+ int main(void) {
+ char buf[4];
+
+ if (syscall(SYS_getrandom, buf, 4, 0) < 0) {
+ return 1;
+ }
+
+ return 0;
+ }"
+ . ${NXT_AUTO}feature
+fi
#include <sys/time.h>
#include <unistd.h>
#if (NXT_HAVE_GETRANDOM)
+#include <sys/random.h>
+#elif (NXT_HAVE_LINUX_SYS_GETRANDOM)
#include <sys/syscall.h>
#include <linux/random.h>
#endif
#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);