Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6024791pxb; Mon, 14 Feb 2022 13:23:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxEmKwXN4fpk70mj4AkCIuiHpFPEupr2XU2xdGndF6xkF9SwnOUmUYMNCRz0ZbZg4CowvB3 X-Received: by 2002:a05:6a00:27a4:: with SMTP id bd36mr1073291pfb.12.1644873784030; Mon, 14 Feb 2022 13:23:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644873784; cv=none; d=google.com; s=arc-20160816; b=yYPDfsEhRUUb+WX9er7logNOmerjMIUMKoNB15K0DRLI4wTrdkIcrLILn4R7NNU0ZO iCUXMOJ10AhVTmN1KZyktVYVs20dc8KMu7ruaCB4lNHXz4R1wwrDTUhvhEoxPcXBoKle ycZCVAubEhISSWBSyexv3BRNgww2rk7bmUeNSkGkPbBNKuWE+NHceudnSfOVxTq3+LA1 sQqI2AhRnPEaqqluGeLHUZQdN6rSzydZQhwbNf5K2HGe/od6AijF+QZD+WQIo5hmRWag 2N38P1OA1SPBVIy6RXK78asULowB7UG7Z9pJtNFz7Ue4j5Bm0LqJO9MLdyjaIV1FaTw+ bmWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=A3IDWsr7pQasCgLof1uuYvu23ASiDLQs21jzN8ILbD8=; b=0gus3Kh/mpv7OphtMs4Xl8EjvOAburCiCW+JyNHhwyNPjfka3PmwyAuPe2fYOgllqN WCljkdQdsaUdqQbAh4WxIUigQ36ZhzBq46azXJ9Cp7SraK6r2VrwYaos+d4F7UgDXC1u 8jc1dUB8MjSiQhjlYpR6Wio4Tts48HZ5oLf9q5WEUDRX7R1Fm5DMYfspRv1EE0oRgtkU P5pPnxilb7TW+kc3O92q1/Ix/ysyjxy4c7wJdZEDt0p7CEZyof3ROZdwV82pH1NeRxIh RCYf2nYUgX5n/XjV3Nj5NO5lwgsvrw9iq48Cj1/fQCsiji42gOBYW8IAAhKiN4SWt6XB XDPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nd0v8trH; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g130si781642pgc.171.2022.02.14.13.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:23:04 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nd0v8trH; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EB4EB1AF048; Mon, 14 Feb 2022 12:39:36 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348827AbiBNSjZ (ORCPT + 99 others); Mon, 14 Feb 2022 13:39:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232272AbiBNSjZ (ORCPT ); Mon, 14 Feb 2022 13:39:25 -0500 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6E7065418 for ; Mon, 14 Feb 2022 10:39:13 -0800 (PST) Received: by mail-yb1-xb30.google.com with SMTP id bt13so49000219ybb.2 for ; Mon, 14 Feb 2022 10:39:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=A3IDWsr7pQasCgLof1uuYvu23ASiDLQs21jzN8ILbD8=; b=nd0v8trHoBHqpoOJgAJL7om1Belj33I7+KN11bH2m0JXmYWMio2voWkBHZHYLHkgkk 0+hIp+/PKJi/kG9cykv74z6NDtH2/3NpSqkSSdoNYnj4QJVrQ3f1RAiWAeKRdusqgRiE 4jLQkpU17qsNjatjUQ74WgjfF22umcnAI1NGVQ2TfkBSkZXWMkuBTJncz88CE5v5+GC1 yK0iXzmQfskj5XPIG+f9NxwH1/wF9HiumcRI4xFU2JfSQDqVC9zSVuEwL0pFJjw0edGk CyNHz16/hS5RBiVKF/sE8/ltY7cWGrwK5TzJRTqSGrNTfqPwdTWq82MJuu+OI9TLXgm0 FBhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A3IDWsr7pQasCgLof1uuYvu23ASiDLQs21jzN8ILbD8=; b=WMO+QHp+gFL4ZWFaxv+rRsZz/rlCNM1usQN3FKABmSyT7rHEs6uYEiz9EQtyxQmNXc nhOqW3LIaGVkFNFvVNz914kOZeoK6TUjjV1zGG5UYSUfz7UPX1bWD5jNf+py1C2syNUg d7nxzezRn64giUSI8tj3deN2gHm3O0iRhy39uD7bAp9vJ77dwvfAc4C3yBGbhPydF4lv zUXD6ze3zyFFnNFC5CdKvhCUYMB82x1XpOfoQA5wfuxZwnX6STw0al3iRF4vBleSFsHD ojv5gqWW7eXD0Q6RH8iUsHISG3jSflyD5o2CnC9ZSMCVtP7fT40YER4ZcZmo+dMEO8/k RRxA== X-Gm-Message-State: AOAM531V2I3wB8Vek208hhPDmZ39kZgyIlPu3YqAknw7J+zrVA+q9ciQ qJisweuZf3k6EqIaYzFUGfggVVpw9wKAU+2wBHOIsXDtqzY= X-Received: by 2002:a81:4005:: with SMTP id l5mr6021ywn.317.1644863952894; Mon, 14 Feb 2022 10:39:12 -0800 (PST) MIME-Version: 1.0 References: <20220214153105.2862331-1-fontaine.fabrice@gmail.com> In-Reply-To: <20220214153105.2862331-1-fontaine.fabrice@gmail.com> From: Luiz Augusto von Dentz Date: Mon, 14 Feb 2022 10:39:02 -0800 Message-ID: Subject: Re: [PATCH BlueZ v2] fix build with glibc < 2.25 To: Fabrice Fontaine Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi Fabrice, On Mon, Feb 14, 2022 at 8:09 AM Fabrice Fontaine 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 > ^ > > 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 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 > #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 > -- Luiz Augusto von Dentz