Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5811701pxb; Mon, 14 Feb 2022 08:09:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzPZq07LTy4ZQYvqE58YsghGDS0T8BRjT5DIRoLvN0TUKyYlMuSnYt45Xk1JjjWkcppnUw X-Received: by 2002:a17:906:5d0f:: with SMTP id g15mr215096ejt.169.1644854997648; Mon, 14 Feb 2022 08:09:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644854997; cv=none; d=google.com; s=arc-20160816; b=w077y6WYnOliLWsytFsGGDX9tNgLV59NRIt0nvsN3Mb+EGubd7E7ru6wvmhd4cULPQ Ds6x6e5pbaK5gRimE5+ERM6NoiJ7SZc0c8YobYVW2hEuhj1PVscVR4pg/hgwwOLhHKSx AoTY5GwvILVh7+/h5e6sEEcziHcHNbujfz1uYpZEXCaJyZnjzDE7rLPydh46kIT+h7Cu 6x3bj7gtINtf3dA5OoUMYG+az0DZR/LiOYxN/EY5UmhLFqyu0el9X5MQk2XoyWmhqP+y lnP0dvSDa3rqD7T1ZybSpUJw9ebDPELTP16N7A9qb5LeAGnQLaMAJMCk6IvWqzTKKW2R 0kGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=kSa3afVzplXZCB52Y82R8towdNcROlnb/dDih0ZNLFQ=; b=blLaKmv8lEv7A2h9cwvaJGkUZsH8dfva60eLjVpjqAQSzk+DD0b+HJ9W9uqy8Kvge+ tVGE9hU6iRFaITqJv8jtTjA3GL6zSramHLZBn9u1AfvqHHA0MC95e/n4XZ9ZHqcCd58p scNfouhxNs5MajBISQBA4kk/DKna7FvAX17FCIV5AoQZHEZ5PF4Apqz2XK1aLspuZfAt Q5MuwnNFwgp19WKOwHJOUyE1caB9xBizD0l3pzJci7cMp3ReNXipXDBrec4uSuhVNAsj IL+LyTXEQCMbnkz0j+AC1M80u6WQRMySJHUd6VoSYAYQZPM5VAO8EzWVNOmhZahD9bk/ XrFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=biaPEZrn; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz18si1542363ejc.322.2022.02.14.08.09.10; Mon, 14 Feb 2022 08:09:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=biaPEZrn; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344816AbiBNPbP (ORCPT + 99 others); Mon, 14 Feb 2022 10:31:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230360AbiBNPbO (ORCPT ); Mon, 14 Feb 2022 10:31:14 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D90F0C65 for ; Mon, 14 Feb 2022 07:31:02 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id bg21-20020a05600c3c9500b0035283e7a012so11144089wmb.0 for ; Mon, 14 Feb 2022 07:31:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kSa3afVzplXZCB52Y82R8towdNcROlnb/dDih0ZNLFQ=; b=biaPEZrn8mTGlA64i5LK0mg01JYrDvSfn1zI3IDloFRrsyewceW6fuQJGFwB8gJhRo Evf1vVvYYzryMXQbq6d3lUT+Bco7lMkzZ57Rq+f2siwisTfy90xMdxNxpk7EnK65006u YclxGdGfxi7xbM9LFNMbTryce0kmvDZivunCYffeAMH0nuAELC9oU/tzcaXqzfhth+Tc U9BeoTPeTmb4O4Y8y4PMbCSRwcT6/micUQwC+74E0gJuSlqHTW4UkD2lhfMmDu42CNiA qyLXB6I98RRojH5CJ8Rfpk6yrNWk7W9W/56kAu8cfSH5EKIlOuUICSJmlEDCwgV537E0 CXsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kSa3afVzplXZCB52Y82R8towdNcROlnb/dDih0ZNLFQ=; b=VBxauuZ0w+hvnvkbHFjhmF5HY7mogy4RMwTf76W8OVdNoGBiTX7fGLU+LKydqj5e65 spZGFu0jgjbK1TcE77lLS4IPB2shkltiOtKL+9/lOQdjCFecqRg0InZRuV+MqM62Ac72 74hIu3qqeV6eX/dmR45CYCpIR6S9LZZwd58o/MTbC6GhxUDyzBbLplDlV14kkuSZ3IuM D4/4UIvZ+eoyDp0nTTqXFm4L0h4RvJXeLjRgZNenjJ9cliBYsFIrLUkohjsLLSf/4+SF KkOXnbuqknVvfVCf0ARCTFG3/9ncVdvkJrnZI70Ibo0NIsGdFO/sOshwPWKrgvv2hoOz 2QOw== X-Gm-Message-State: AOAM533ZH+Uhx/9GTmuF1E1kd5wXriJlPs8l7rslyN6B83f0kzR/y3o9 FGlOFIbAe+mcIbUPJn4k+4WWfudYGyU= X-Received: by 2002:a05:600c:4ecd:: with SMTP id g13mr4059363wmq.148.1644852661077; Mon, 14 Feb 2022 07:31:01 -0800 (PST) Received: from kali.home (2a01cb088e0b5b002be75de2a1caa253.ipv6.abo.wanadoo.fr. [2a01:cb08:8e0b:5b00:2be7:5de2:a1ca:a253]) by smtp.gmail.com with ESMTPSA id k5sm17672311wrw.117.2022.02.14.07.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 07:31:00 -0800 (PST) From: Fabrice Fontaine To: linux-bluetooth@vger.kernel.org Cc: Fabrice Fontaine Subject: [PATCH BlueZ v2] fix build with glibc < 2.25 Date: Mon, 14 Feb 2022 16:31:05 +0100 Message-Id: <20220214153105.2862331-1-fontaine.fabrice@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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 ^ 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 --- 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 #include #include +#ifdef HAVE_SYS_RANDOM_H #include +#endif #include #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 #include #include +#ifdef HAVE_SYS_RANDOM_H #include +#endif #include #include #include +#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 #include #include +#ifdef HAVE_SYS_RANDOM_H #include +#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 #include #include +#ifdef HAVE_SYS_RANDOM_H #include +#endif #include #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 #include #include +#ifdef HAVE_SYS_RANDOM_H #include +#endif #include @@ -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 #include #include +#ifdef HAVE_SYS_RANDOM_H #include +#endif #include #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 +#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 #include #include +#ifdef HAVE_SYS_RANDOM_H #include +#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