basic/random-util: add new header for getrandom()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Apr 2017 20:13:27 +0000 (16:13 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Apr 2017 16:05:55 +0000 (12:05 -0400)
There's some confusion: older man pages specify that linux/random.h
contains getrandom, but newer glibc has it in sys/random.h. Detect if
the newer header is available and include it. We still need the older
header for the flags.

configure.ac
src/basic/random-util.c

index 3436a9d..13e7583 100644 (file)
@@ -328,7 +328,6 @@ AC_CHECK_DECLS([
         pivot_root,
         name_to_handle_at,
         setns,
-        getrandom,
         renameat2,
         kcmp,
         keyctl,
@@ -343,6 +342,13 @@ AC_CHECK_DECLS([
 #include <sched.h>
 #include <string.h>
 #include <linux/loop.h>
+]])
+
+AC_CHECK_DECLS([getrandom],
+               [AC_DEFINE([USE_SYS_RANDOM_H], [], [sys/random.h is usable])],
+               [AC_CHECK_DECLS([getrandom], [], [], [[
+#include <sys/random.h>
+]])], [[
 #include <linux/random.h>
 ]])
 
index ad7b3ee..b216be5 100644 (file)
 #include <stdint.h>
 
 #ifdef HAVE_SYS_AUXV_H
-#include <sys/auxv.h>
+#  include <sys/auxv.h>
+#endif
+
+#ifdef USE_SYS_RANDOM_H
+#  include <sys/random.h>
+#else
+#  include <linux/random.h>
 #endif
 
 #include "fd-util.h"