fix build with glibc < 2.25
Subsystems (2)
PATCH v2 1/1 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
---
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
Makefile.am +1 -0
@@ -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 \
configure.ac +3 -1
@@ -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))
emulator/le.c +3 -0
@@ -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"
emulator/phy.c +3 -0
@@ -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"
peripheral/main.c +3 -0
@@ -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"
plugins/autopair.c +3 -0
@@ -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"
profiles/health/hdp.c +3 -0
@@ -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"
profiles/health/mcap.c +3 -0
@@ -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"
src/missing.h new file +30 -0
@@ -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
tools/btgatt-server.c +3 -0
@@ -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"
Signature · 1 line
2.34.1
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
Luiz Augusto von Dentz
maintainerHi Fabrice,
Quoted 218 lines · Fabrice Fontaine
getrandom and
sys/random.hare 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.cFixes:
- http://autobuild.buildroot.org/results/6b8870d12e0804d6154230a7322c49416c1dc0e2Signed-off-by Fabrice Fontaine <[email protected]>---
Changes v1 -> v2 (after review of Marcel Holtmann):
- Add a getrandom fallback insrc/missing.hinstead of adding ifdefMakefile.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.hMakefile.am +1
-0@@ -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 \configure.ac +3
-1@@ -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))emulator/le.c +3
-0@@ -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" emulator/phy.c +3
-0@@ -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" peripheral/main.c +3
-0@@ -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" plugins/autopair.c +3
-0@@ -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" profiles/health/hdp.c +3
-0@@ -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" profiles/health/mcap.c +3
-0@@ -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" src/missing.h new file +20
-0@@ -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; +
src/missing.h line 30
Quoted 10 lines
src/missing.h new file +10
-0+ 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
Quoted 25 lines
tools/btgatt-server.c +3
-1@@ -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
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 229 lines · Luiz Augusto von Dentz
Hi Fabrice,
Quoted 224 lines · Fabrice Fontaine
getrandom and
sys/random.hare 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.cFixes:
- http://autobuild.buildroot.org/results/6b8870d12e0804d6154230a7322c49416c1dc0e2Signed-off-by Fabrice Fontaine <[email protected]>---
Changes v1 -> v2 (after review of Marcel Holtmann):
- Add a getrandom fallback insrc/missing.hinstead of adding ifdefMakefile.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.hMakefile.am +1
-0@@ -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 \configure.ac +3
-1@@ -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))emulator/le.c +3
-0@@ -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" emulator/phy.c +3
-0@@ -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" peripheral/main.c +3
-0@@ -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" plugins/autopair.c +3
-0@@ -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" profiles/health/hdp.c +3
-0@@ -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" profiles/health/mcap.c +3
-0@@ -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" src/missing.h new file +26
-0@@ -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);
Quoted 8 lines
src/missing.h line 30
Quoted 4 lines
src/missing.h new file +4
-0+ + return bytes; +} +#endif How about having this under
src/shared/util.h, name itutil_getrandomand 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.
Quoted 19 lines
Quoted 19 lines
tools/btgatt-server.c +2
-0@@ -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"
Quoted 11 lines
Quoted 7 lines
tools/btgatt-server.c +1
-1+#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