2022-02-14 16:09:57

by Fabrice Fontaine

[permalink] [raw]
Subject: [PATCH BlueZ v2] fix build with glibc < 2.25

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 <[email protected]>
---
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

diff --git a/Makefile.am b/Makefile.am
index 82125c482..d6c18fe0d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 \
diff --git a/configure.ac b/configure.ac
index 07d068a4d..441bd5f29 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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))
diff --git a/emulator/le.c b/emulator/le.c
index f8f313f2c..b3916d49b 100644
--- a/emulator/le.c
+++ b/emulator/le.c
@@ -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"
diff --git a/emulator/phy.c b/emulator/phy.c
index 44cace438..9cb6460d7 100644
--- a/emulator/phy.c
+++ b/emulator/phy.c
@@ -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"

diff --git a/peripheral/main.c b/peripheral/main.c
index 91adb45fc..e854bd14c 100644
--- a/peripheral/main.c
+++ b/peripheral/main.c
@@ -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"
diff --git a/plugins/autopair.c b/plugins/autopair.c
index a75ecebe4..6ce97672b 100644
--- a/plugins/autopair.c
+++ b/plugins/autopair.c
@@ -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"
diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
index 9d9d1e824..1e6e16fd2 100644
--- a/profiles/health/hdp.c
+++ b/profiles/health/hdp.c
@@ -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"
diff --git a/profiles/health/mcap.c b/profiles/health/mcap.c
index aad0a08a3..6b779c513 100644
--- a/profiles/health/mcap.c
+++ b/profiles/health/mcap.c
@@ -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"

diff --git a/src/missing.h b/src/missing.h
new file mode 100644
index 000000000..df8bd980a
--- /dev/null
+++ b/src/missing.h
@@ -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
diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c
index 15d49a464..30314f4ac 100644
--- a/tools/btgatt-server.c
+++ b/tools/btgatt-server.c
@@ -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"
--
2.34.1


2022-02-14 20:21:52

by bluez.test.bot

[permalink] [raw]
Subject: RE: [BlueZ,v2] fix build with glibc < 2.25

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=614152

---Test result---

Test Summary:
CheckPatch FAIL 1.54 seconds
GitLint FAIL 1.04 seconds
Prep - Setup ELL PASS 52.96 seconds
Build - Prep PASS 0.79 seconds
Build - Configure PASS 10.63 seconds
Build - Make PASS 1495.14 seconds
Make Check PASS 12.90 seconds
Make Check w/Valgrind PASS 534.49 seconds
Make Distcheck PASS 282.19 seconds
Build w/ext ELL - Configure PASS 10.76 seconds
Build w/ext ELL - Make PASS 1470.34 seconds
Incremental Build with patchesPASS 0.00 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf
Output:
[BlueZ,v2] fix build with glibc < 2.25
WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#81:
https://www.gnu.org/software/gnulib/manual/html_node/sys_002frandom_002eh.html

/github/workspace/src/12745735.patch total: 0 errors, 1 warnings, 161 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/12745735.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: GitLint - FAIL
Desc: Run gitlint with rule in .gitlint
Output:
[BlueZ,v2] fix build with glibc < 2.25
14: B1 Line exceeds max length (83>80): "https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/src/pipewire/utils.c"
17: B1 Line exceeds max length (82>80): " - http://autobuild.buildroot.org/results/6b8870d12e0804d6154230a7322c49416c1dc0e2"




---
Regards,
Linux Bluetooth

2022-02-14 21:03:54

by Fabrice Fontaine

[permalink] [raw]
Subject: Re: [PATCH BlueZ v2] fix build with glibc < 2.25

Hi Luiz,

Le lun. 14 févr. 2022 à 19:39, Luiz Augusto von Dentz
<[email protected]> a écrit :
>
> Hi Fabrice,
>
> On Mon, Feb 14, 2022 at 8:09 AM Fabrice Fontaine
> <[email protected]> wrote:
> >
> > 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 <[email protected]>
> > ---
> > 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
> >
> > diff --git a/Makefile.am b/Makefile.am
> > index 82125c482..d6c18fe0d 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -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 \
> > diff --git a/configure.ac b/configure.ac
> > index 07d068a4d..441bd5f29 100644
> > --- a/configure.ac
> > +++ b/configure.ac
> > @@ -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))
> > diff --git a/emulator/le.c b/emulator/le.c
> > index f8f313f2c..b3916d49b 100644
> > --- a/emulator/le.c
> > +++ b/emulator/le.c
> > @@ -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"
> > diff --git a/emulator/phy.c b/emulator/phy.c
> > index 44cace438..9cb6460d7 100644
> > --- a/emulator/phy.c
> > +++ b/emulator/phy.c
> > @@ -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"
> >
> > diff --git a/peripheral/main.c b/peripheral/main.c
> > index 91adb45fc..e854bd14c 100644
> > --- a/peripheral/main.c
> > +++ b/peripheral/main.c
> > @@ -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"
> > diff --git a/plugins/autopair.c b/plugins/autopair.c
> > index a75ecebe4..6ce97672b 100644
> > --- a/plugins/autopair.c
> > +++ b/plugins/autopair.c
> > @@ -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"
> > diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
> > index 9d9d1e824..1e6e16fd2 100644
> > --- a/profiles/health/hdp.c
> > +++ b/profiles/health/hdp.c
> > @@ -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"
> > diff --git a/profiles/health/mcap.c b/profiles/health/mcap.c
> > index aad0a08a3..6b779c513 100644
> > --- a/profiles/health/mcap.c
> > +++ b/profiles/health/mcap.c
> > @@ -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"
> >
> > diff --git a/src/missing.h b/src/missing.h
> > new file mode 100644
> > index 000000000..df8bd980a
> > --- /dev/null
> > +++ b/src/missing.h
> > @@ -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
>
> How about having this under src/shared/util.h, name it util_getrandom
> and don't bother with glibc otherwise this really gets messy
> maintaining it over time

OK, I'll send a v3 that adds util_getrandom in src/shared/util.h.
However, I'll keep calling getrandom if it is available as the
fallback is ignoring the flags argument.
As a result, the fallback is always using /dev/urandom.
This is probably more future proof even if all getrandom calls in
BlueZ are currently setting the flags to 0.

>
> > diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c
> > index 15d49a464..30314f4ac 100644
> > --- a/tools/btgatt-server.c
> > +++ b/tools/btgatt-server.c
> > @@ -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"
> > --
> > 2.34.1
> >
>
>
> --
> Luiz Augusto von Dentz
Best Regards,

Fabrice

2022-02-14 21:23:04

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ v2] fix build with glibc < 2.25

Hi Fabrice,

On Mon, Feb 14, 2022 at 8:09 AM Fabrice Fontaine
<[email protected]> wrote:
>
> 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 <[email protected]>
> ---
> 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
>
> diff --git a/Makefile.am b/Makefile.am
> index 82125c482..d6c18fe0d 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -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 \
> diff --git a/configure.ac b/configure.ac
> index 07d068a4d..441bd5f29 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -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))
> diff --git a/emulator/le.c b/emulator/le.c
> index f8f313f2c..b3916d49b 100644
> --- a/emulator/le.c
> +++ b/emulator/le.c
> @@ -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"
> diff --git a/emulator/phy.c b/emulator/phy.c
> index 44cace438..9cb6460d7 100644
> --- a/emulator/phy.c
> +++ b/emulator/phy.c
> @@ -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"
>
> diff --git a/peripheral/main.c b/peripheral/main.c
> index 91adb45fc..e854bd14c 100644
> --- a/peripheral/main.c
> +++ b/peripheral/main.c
> @@ -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"
> diff --git a/plugins/autopair.c b/plugins/autopair.c
> index a75ecebe4..6ce97672b 100644
> --- a/plugins/autopair.c
> +++ b/plugins/autopair.c
> @@ -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"
> diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
> index 9d9d1e824..1e6e16fd2 100644
> --- a/profiles/health/hdp.c
> +++ b/profiles/health/hdp.c
> @@ -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"
> diff --git a/profiles/health/mcap.c b/profiles/health/mcap.c
> index aad0a08a3..6b779c513 100644
> --- a/profiles/health/mcap.c
> +++ b/profiles/health/mcap.c
> @@ -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"
>
> diff --git a/src/missing.h b/src/missing.h
> new file mode 100644
> index 000000000..df8bd980a
> --- /dev/null
> +++ b/src/missing.h
> @@ -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

How about having this under src/shared/util.h, name it util_getrandom
and don't bother with glibc otherwise this really gets messy
maintaining it over time

> diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c
> index 15d49a464..30314f4ac 100644
> --- a/tools/btgatt-server.c
> +++ b/tools/btgatt-server.c
> @@ -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"
> --
> 2.34.1
>


--
Luiz Augusto von Dentz