@@ -299,6 +299,7 @@ pkglibexec_PROGRAMS += src/bluetoothd
src_bluetoothd_SOURCES = $(builtin_sources) \
$(attrib_sources) $(btio_sources) \
src/bluetooth.ver \
+ src/missing.h \
src/main.c src/log.h src/log.c \
src/backtrace.h src/backtrace.c \
src/rfkill.c src/btd.h src/sdpd.h \
@@ -54,6 +54,8 @@ AC_ARG_ENABLE(threads, AS_HELP_STRING([--enable-threads],
AC_CHECK_FUNCS(explicit_bzero)
+AC_CHECK_FUNCS(getrandom)
+
AC_CHECK_FUNCS(rawmemchr)
AC_CHECK_FUNC(signalfd, dummy=yes,
@@ -68,7 +70,7 @@ AC_CHECK_LIB(pthread, pthread_create, dummy=yes,
AC_CHECK_LIB(dl, dlopen, dummy=yes,
AC_MSG_ERROR(dynamic linking loader is required))
-AC_CHECK_HEADERS(linux/types.h linux/if_alg.h linux/uinput.h linux/uhid.h)
+AC_CHECK_HEADERS(linux/types.h linux/if_alg.h linux/uinput.h linux/uhid.h sys/random.h)
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.28, dummy=yes,
AC_MSG_ERROR(GLib >= 2.28 is required))
@@ -20,12 +20,15 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/uio.h>
+#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
+#endif
#include <time.h>
#include "lib/bluetooth.h"
#include "lib/hci.h"
+#include "src/missing.h"
#include "src/shared/util.h"
#include "src/shared/crypto.h"
#include "src/shared/ecc.h"
@@ -19,11 +19,14 @@
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
+#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
+#endif
#include <netinet/in.h>
#include <netinet/ip.h>
#include <time.h>
+#include "src/missing.h"
#include "src/shared/util.h"
#include "src/shared/mainloop.h"
@@ -25,12 +25,15 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
+#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
+#endif
#ifndef WAIT_ANY
#define WAIT_ANY (-1)
#endif
+#include "src/missing.h"
#include "src/shared/mainloop.h"
#include "peripheral/efivars.h"
#include "peripheral/attach.h"
@@ -17,13 +17,16 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
+#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
+#endif
#include <glib.h>
#include "lib/bluetooth.h"
#include "lib/sdp.h"
+#include "src/missing.h"
#include "src/plugin.h"
#include "src/adapter.h"
#include "src/device.h"
@@ -16,7 +16,9 @@
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
+#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
+#endif
#include <glib.h>
@@ -26,6 +28,7 @@
#include "gdbus/gdbus.h"
+#include "src/missing.h"
#include "src/dbus-common.h"
#include "src/log.h"
#include "src/error.h"
@@ -19,13 +19,16 @@
#include <errno.h>
#include <unistd.h>
#include <time.h>
+#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
+#endif
#include <glib.h>
#include "lib/bluetooth.h"
#include "bluetooth/l2cap.h"
#include "btio/btio.h"
+#include "src/missing.h"
#include "src/log.h"
#include "src/shared/timeout.h"
new file mode 100644
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: MIT
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2018 Wim Taymans
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef HAVE_GETRANDOM
+ssize_t getrandom(void *buf, size_t buflen, unsigned int flags)
+{
+ ssize_t bytes;
+ int fd;
+
+ fd = open("/dev/urandom", O_CLOEXEC);
+ if (fd < 0)
+ return -1;
+
+ bytes = read(fd, buf, buflen);
+ close(fd);
+
+ return bytes;
+}
+#endif
@@ -20,7 +20,9 @@
#include <getopt.h>
#include <unistd.h>
#include <errno.h>
+#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
+#endif
#include "lib/bluetooth.h"
#include "lib/hci.h"
@@ -28,6 +30,7 @@
#include "lib/l2cap.h"
#include "lib/uuid.h"
+#include "src/missing.h"
#include "src/shared/mainloop.h"
#include "src/shared/util.h"
#include "src/shared/att.h"
getrandom and sys/random.h are only available since glibc 2.25: https://www.gnu.org/software/gnulib/manual/html_node/sys_002frandom_002eh.html resulting in the following build failures since version 5.63 and https://git.kernel.org/pub/scm/bluetooth/bluez.git/log/?qt=grep&q=getrandom: plugins/autopair.c:20:24: fatal error: sys/random.h: No such file or directory #include <sys/random.h> ^ To fix this build failure, add a getrandom fallback borrowed from pipewire and licensed under MIT: https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/src/pipewire/utils.c Fixes: - http://autobuild.buildroot.org/results/6b8870d12e0804d6154230a7322c49416c1dc0e2 Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> --- Changes v1 -> v2 (after review of Marcel Holtmann): - Add a getrandom fallback in src/missing.h instead of adding ifdef Makefile.am | 1 + configure.ac | 4 +++- emulator/le.c | 3 +++ emulator/phy.c | 3 +++ peripheral/main.c | 3 +++ plugins/autopair.c | 3 +++ profiles/health/hdp.c | 3 +++ profiles/health/mcap.c | 3 +++ src/missing.h | 30 ++++++++++++++++++++++++++++++ tools/btgatt-server.c | 3 +++ 10 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/missing.h