From patchwork Mon Jan 29 14:44:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 767655 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B4C266B40 for ; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; cv=none; b=qWooKvu9bqQF64hothf/ktMp+c4t4Y42jQx8UDy1TzyLOTmdtW77rVgW0D0LTTfRPoaS03wTDi5Dvbu0Ni1jAwMzuotV18W5NYmvaBAvFXGUdUG7cLJlus2Tc06iCBz/BiBCi6g/uMkDorI57iBRYVPONgrHBtzGVirJ7TsxnMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; c=relaxed/simple; bh=T41AqRzZ9anzy8KgZAVF0U4kwCqsFRwAQlKY9yqeluE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PZ/YhtJUdUsmhStKA1KeTkR1zTbESSiRBfllfXBlGxbNTEJ0vXGruAGpGte0rVPrg5+Q6gS2rZL5/7kVM7zpfrO9XqacjitRlyYdIaQc8oyTGsjRfqdIoRX78pQCv2Ko5WzOw5/g3IaOFxg6xBe1vO6hXe/njiKQKF4WctgMWlM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HoXbC1v8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HoXbC1v8" Received: by smtp.kernel.org (Postfix) with ESMTPS id D1071C433C7; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706539456; bh=T41AqRzZ9anzy8KgZAVF0U4kwCqsFRwAQlKY9yqeluE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=HoXbC1v80x9bs4MgtcoQrj0Z6zMsG2BpDpX7gwWSSCy9WhhCOin2R7ddkw03BkSVU jxvwL2yUiBQQNBoMovqypxaQvVGuq2TgzVCUKiDo5XcZ6OO7274niLwPROPu5qtWbM cVj4++wNZl9DDnUmtJLYCZDRDr9polqV5DBeFE1FT+cJ+lG0lHzeDAbn+x+fY/2OfV JwaBkIOWTToeFx3Pr6VgYpvYBn3EVQp5QaWRX53IHYTfTVegUnu2kIRCUC1mEDAyUI bf94F2NPKHN15urjT5TpY3974OZrlxTbvbJtiZZQbeMxqSYEJeH9AB36XkCrI5NwX4 G0kOVG0iaM2ow== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5581C47DDF; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 29 Jan 2024 14:44:15 +0000 Subject: [PATCH BlueZ v4 1/8] configure, README: introduce --enable-external-plugins Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240129-rm-ext-plugins-v4-1-bfd1e08c7f99@gmail.com> References: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706539455; l=2129; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=TURnkD96L8lhhZthFxY3kbYoSxFEDANByCVJaEdcrOg=; b=OfKLp3lmunDbO7SjD7ptcG7Qsp0A7Ef092N5KC4EjC4bBBcdkUFQCFyaIcEUTotTlBf02WBHn 7UV3hCvEGk6CYNaD3JY5SPTRt1b06qFnO4HHESYYrIJybQz3D97ktHG X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov As the README chunk says, disabled by default, since they rely on internal API/ABI and can break at any point. Instead everyone affected should work and upstream their plugin into the bluez project. --- README | 13 +++++++++++++ configure.ac | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/README b/README index 7de7045a8..6c0777046 100644 --- a/README +++ b/README @@ -249,6 +249,19 @@ For a working system, certain configuration options need to be enabled: systems. The behavior of the deprecated tools may be unstable or simply don't work anymore. + --enable-external-plugins + + Enable support for external plugins + + By default external plugins for bluetoothd and obexd are not + supported and thus disabled. + + External plugins require access to internal, undocumented and + unversioned API in said daemons. As such they can break at any + time. If you have such plugins, enable this option and work + actively with the community to make said plugin part of the + upstream bluez project. + --enable-nfc This option enable NFC pairing support. diff --git a/configure.ac b/configure.ac index b4d362494..5eb7ee0e0 100644 --- a/configure.ac +++ b/configure.ac @@ -364,6 +364,16 @@ AC_ARG_ENABLE(deprecated, AS_HELP_STRING([--enable-deprecated], [enable_deprecated=${enableval}]) AM_CONDITIONAL(DEPRECATED, test "${enable_deprecated}" = "yes") +AC_ARG_ENABLE(external-plugsin, AS_HELP_STRING([--enable-external-plugins], + [enable support for external plugins]), + [enable_external_plugins=${enableval}]) +AM_CONDITIONAL(EXTERNAL_PLUGINS, test "${enable_external_plugins}" = "yes") +if (test "${enable_external_plugins}" = "yes"); then + AC_DEFINE(EXTERNAL_PLUGINS, 1, [Define if external plugin support is required]) +else + AC_DEFINE(EXTERNAL_PLUGINS, 0, [Define if external plugin support is required]) +fi + AC_ARG_ENABLE(sixaxis, AS_HELP_STRING([--enable-sixaxis], [enable sixaxis plugin]), [enable_sixaxis=${enableval}]) AM_CONDITIONAL(SIXAXIS, test "${enable_sixaxis}" = "yes" && From patchwork Mon Jan 29 14:44:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 768596 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B3A15B1FE for ; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; cv=none; b=oB08OcsAF/rkVg509Z7+HRUu6pLR8BDFlKfMEIiCUJAea3G1FwzUaZ4ou4dU5yGAnC1Nvq70odfUbXLmA9cnK67xOaTKzxq6tLch/HbA9/KK8zLjjUZ4neNv2fsAPl9LKf6feKrmtHAcJt5rX94p/GSmwQwNWCR/eL+yS4ABNtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; c=relaxed/simple; bh=z2zwOAIJdLbSH5OWauqgK8n/AiJg9/e9ESmn51K3eGE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ghSFXbXeA+shLBcCeW8wI11gzg2hapLZjot5d2gXahCMPnuRqXJPGMl/OPPWvICAsaEToVBqpMfCzs7gaWyu95fKBQoioyXgEfLNpMh3kHJArOMZ008Rl9rbAbl5p75UQ+VcXhFVccYo0Ne7+Hab6aBViwKVf7Ws+jwLH3htNYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cy2KltPE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cy2KltPE" Received: by smtp.kernel.org (Postfix) with ESMTPS id D98A4C43390; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706539456; bh=z2zwOAIJdLbSH5OWauqgK8n/AiJg9/e9ESmn51K3eGE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Cy2KltPE/cL43bD1hv2wqUdior3sEGLlt2II+kGJM91jtprj9aI8IIGXEz+U+esjU LvODii3VpxI1pGp/ExzsiSntPRuOI2d2czV41YK4BntfLpKA4L09KWlZmkecEaka4R xiq+e1B+8q9hM6tQTk6D1F1SBEd7jr9yongCq6OUcGvKYNbZRlTVnxE4Cxd96DmKS3 hSzg1+QTpyD1E0lMOclcadwrNr4Wj2LY7V4M5axg9qkcWadoOmi9sMkIY3uHK9iPU5 IAab71IsEYnJmN1V3u0XJHSeVD+GWt5xYYWzV2qxcler6ryOKLBpcH5npk+GyssX1D vtVw/vKTO0asg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C173EC47DB3; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 29 Jan 2024 14:44:16 +0000 Subject: [PATCH BlueZ v4 2/8] obexd: factor out external plugin support Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240129-rm-ext-plugins-v4-2-bfd1e08c7f99@gmail.com> References: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706539455; l=5559; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=cIMdx6HXhTyyf9nrZXFXunU9oNAXB+a/bweqZhHYUuc=; b=tYiy9kcFNgVL5ypyASR6SaY9uxeukDmHzK39nDhlEwqseYQpcqk33MTilzvMk93Mm72x0ICuz RY6eKf0hOF3AAk3nF+sxQPZ6QZwTHPe0DNqvbJreudK3uwq/bCg42uE X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov As a whole all plugins should be built-in, otherwise they would be using internal, undocumented, unversioned, unstable API. Flesh out the external plugin support into a few blocks and simplify the normal path. Guard the external plugin support behind a runtime check, which will be dead-code eliminated in the default case. Hide the internal API (omit export-dynamic) when built without external plugins. --- Makefile.obexd | 2 ++ obexd/src/obexd.h | 2 +- obexd/src/plugin.c | 89 ++++++++++++++++++++++++++++++++++++------------------ obexd/src/plugin.h | 4 +++ 4 files changed, 66 insertions(+), 31 deletions(-) diff --git a/Makefile.obexd b/Makefile.obexd index 363295d0e..0e50b1fa4 100644 --- a/Makefile.obexd +++ b/Makefile.obexd @@ -92,7 +92,9 @@ obexd_src_obexd_LDADD = lib/libbluetooth-internal.la \ $(ICAL_LIBS) $(DBUS_LIBS) $(LIBEBOOK_LIBS) \ $(LIBEDATASERVER_LIBS) $(GLIB_LIBS) -ldl +if EXTERNAL_PLUGINS obexd_src_obexd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic +endif obexd_src_obexd_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) \ $(ICAL_CFLAGS) -DOBEX_PLUGIN_BUILTIN \ diff --git a/obexd/src/obexd.h b/obexd/src/obexd.h index fe312a65b..af5265da5 100644 --- a/obexd/src/obexd.h +++ b/obexd/src/obexd.h @@ -18,7 +18,7 @@ #define OBEX_MAS (1 << 8) #define OBEX_MNS (1 << 9) -gboolean plugin_init(const char *pattern, const char *exclude); +void plugin_init(const char *pattern, const char *exclude); void plugin_cleanup(void); gboolean manager_init(void); diff --git a/obexd/src/plugin.c b/obexd/src/plugin.c index a3eb24753..14327782d 100644 --- a/obexd/src/plugin.c +++ b/obexd/src/plugin.c @@ -34,6 +34,8 @@ #define PLUGINFLAG (RTLD_NOW) #endif +#define IS_ENABLED(x) (x) + static GSList *plugins = NULL; struct obex_plugin { @@ -41,7 +43,8 @@ struct obex_plugin { const struct obex_plugin_desc *desc; }; -static gboolean add_plugin(void *handle, const struct obex_plugin_desc *desc) +static gboolean add_external_plugin(void *handle, + const struct obex_plugin_desc *desc) { struct obex_plugin *plugin; @@ -66,6 +69,25 @@ static gboolean add_plugin(void *handle, const struct obex_plugin_desc *desc) return TRUE; } +static void add_plugin(const struct obex_plugin_desc *desc) +{ + struct obex_plugin *plugin; + + plugin = g_try_new0(struct obex_plugin, 1); + if (plugin == NULL) + return; + + plugin->desc = desc; + + if (desc->init() < 0) { + g_free(plugin); + return; + } + + plugins = g_slist_append(plugins, plugin); + DBG("Plugin %s loaded", desc->name); +} + static gboolean check_plugin(const struct obex_plugin_desc *desc, char **patterns, char **excludes) { @@ -93,42 +115,22 @@ static gboolean check_plugin(const struct obex_plugin_desc *desc, } -#include "builtin.h" - -gboolean plugin_init(const char *pattern, const char *exclude) +static void external_plugin_init(char **patterns, char **excludes) { - char **patterns = NULL; - char **excludes = NULL; GDir *dir; const char *file; - unsigned int i; - if (strlen(PLUGINDIR) == 0) - return FALSE; + info("Using external plugins is not officially supported.\n"); + info("Consider upstreaming your plugins into the BlueZ project."); - if (pattern) - patterns = g_strsplit_set(pattern, ":, ", -1); - - if (exclude) - excludes = g_strsplit_set(exclude, ":, ", -1); - - DBG("Loading builtin plugins"); - - for (i = 0; __obex_builtin[i]; i++) { - if (check_plugin(__obex_builtin[i], - patterns, excludes) == FALSE) - continue; - - add_plugin(NULL, __obex_builtin[i]); - } + if (strlen(PLUGINDIR) == 0) + return; DBG("Loading plugins %s", PLUGINDIR); dir = g_dir_open(PLUGINDIR, 0, NULL); if (!dir) { - g_strfreev(patterns); - g_strfreev(excludes); - return FALSE; + return; } while ((file = g_dir_read_name(dir)) != NULL) { @@ -164,15 +166,42 @@ gboolean plugin_init(const char *pattern, const char *exclude) continue; } - if (add_plugin(handle, desc) == FALSE) + if (add_external_plugin(handle, desc) == FALSE) dlclose(handle); } g_dir_close(dir); +} + +#include "builtin.h" + +void plugin_init(const char *pattern, const char *exclude) +{ + char **patterns = NULL; + char **excludes = NULL; + unsigned int i; + + if (pattern) + patterns = g_strsplit_set(pattern, ":, ", -1); + + if (exclude) + excludes = g_strsplit_set(exclude, ":, ", -1); + + DBG("Loading builtin plugins"); + + for (i = 0; __obex_builtin[i]; i++) { + if (check_plugin(__obex_builtin[i], + patterns, excludes) == FALSE) + continue; + + add_plugin(__obex_builtin[i]); + } + + if IS_ENABLED(EXTERNAL_PLUGINS) + external_plugin_init(patterns, excludes); + g_strfreev(patterns); g_strfreev(excludes); - - return TRUE; } void plugin_cleanup(void) diff --git a/obexd/src/plugin.h b/obexd/src/plugin.h index a91746cbc..e1756b9bf 100644 --- a/obexd/src/plugin.h +++ b/obexd/src/plugin.h @@ -20,10 +20,14 @@ struct obex_plugin_desc { #name, init, exit \ }; #else +#if EXTERNAL_PLUGINS #define OBEX_PLUGIN_DEFINE(name,init,exit) \ extern struct obex_plugin_desc obex_plugin_desc \ __attribute__ ((visibility("default"))); \ const struct obex_plugin_desc obex_plugin_desc = { \ #name, init, exit \ }; +#else +#error "Requested non built-in plugin, while external plugins is disabled" +#endif #endif From patchwork Mon Jan 29 14:44:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 768595 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B476664DE for ; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; cv=none; b=CIPQytmK9AoyHExnI0dvnwaFKMBasnhZeqANqm4DvzOEYt1BgG7Qe9E286VSFqinQgpk0oCSkdZYolKOciOB8iU53zf3p5NjNSaPJd6TgWsImw4yjvNLG3OJE5At2XlpmViUKRyLEDJX8wJ6UgzcGoKuRvKJ0lX03f+uz4pjKjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; c=relaxed/simple; bh=XLSO3l0XdIpPwkgoc4l1xpQ1HRftjj49icAZy3iAi/0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D9VQlLQSefKTt3PPCIwYKoZ1ipShgd6P+hlErajOVpXSm9EbDlh/661bB4Ioff2++4o8WgchgdAJ+CY9Ga5v5l8/atjsdY26Hu5PYKBwmcyNC4lTuvNLU7e68r2v6w2ihn5ObTGRpGvKeMgb11toDCVTnsCBuSNtph5SW+mA2jk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dYpFA0jO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dYpFA0jO" Received: by smtp.kernel.org (Postfix) with ESMTPS id E62F7C43394; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706539456; bh=XLSO3l0XdIpPwkgoc4l1xpQ1HRftjj49icAZy3iAi/0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=dYpFA0jO3qxS6mlvqOrtJxwYYUPS9uwtVqe0RX+/67nGiSB5ztG9WFzOOiejX0ajF WmshwIOSMIkAVha2/OjZSA+EVsfMR9jlyFIwtU9NKeFCXrlGBt0BU7eDfEKILOZ7HI OtCxAhL8tEGJrNEPCG7sN4/GCfJSG1BAtwpwrQpV/r2FnY8x55ARj+Sdg7klPncllo Evy3sXrRupxffhO5OEzB9S3G03hR8Hbau8zrp7hzwAzfj/nibYFLNSttwU4k3kS9VB i6jHH4tRyyGHGsFKe2DQnc5mV5733ou9z5P2jPsO343mlaTU0Q7kxO5kfm16lPUk+z 9KGFnoXHoAu2w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id CED37C4828C; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 29 Jan 2024 14:44:17 +0000 Subject: [PATCH BlueZ v4 3/8] bluetoothd: remove external-dummy plugin Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240129-rm-ext-plugins-v4-3-bfd1e08c7f99@gmail.com> References: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706539455; l=1499; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=Qkz58Z8cPMkE6Ps/NGmx2S8bmRGDQE2Anw+Id8KSNeI=; b=80WqH9lZJW+58Gc8dcVjtF+auOhXuPiXyTvdcxmGnkuuWl6QuaghsRHkdZ0Ph6AYI9i5Ey+0Z 5JYEfcrBOAMALIC1hmXRR3m12ZZy2KeS9AyoWpk2N7gqoetO9I6izGG X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov The external plugins infra is getting deprecated and disabled by default. Remove this dummy plugin. --- Makefile.am | 8 -------- plugins/external-dummy.c | 28 ---------------------------- 2 files changed, 36 deletions(-) diff --git a/Makefile.am b/Makefile.am index 59603a0b7..9e35d7fd9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -289,14 +289,6 @@ builtin_ldadd = include Makefile.plugins -if MAINTAINER_MODE -plugin_LTLIBRARIES += plugins/external-dummy.la -plugins_external_dummy_la_SOURCES = plugins/external-dummy.c -plugins_external_dummy_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \ - -no-undefined -plugins_external_dummy_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden -endif - pkglibexec_PROGRAMS += src/bluetoothd src_bluetoothd_SOURCES = $(builtin_sources) \ diff --git a/plugins/external-dummy.c b/plugins/external-dummy.c deleted file mode 100644 index 1c209e8b7..000000000 --- a/plugins/external-dummy.c +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * - * BlueZ - Bluetooth protocol stack for Linux - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "src/plugin.h" -#include "src/log.h" - -static int dummy_init(void) -{ - DBG(""); - - return 0; -} - -static void dummy_exit(void) -{ - DBG(""); -} - -BLUETOOTH_PLUGIN_DEFINE(external_dummy, VERSION, - BLUETOOTH_PLUGIN_PRIORITY_LOW, dummy_init, dummy_exit) From patchwork Mon Jan 29 14:44:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 767656 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B3D7657DB for ; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; cv=none; b=qJOZGMGZdLLsguSTggsPfVTQ/mgEVlfRQMXTC/D2/BHFOIL4rLK7nxDztD0ON0L8MKFA3DpiUuZyNFhgJfGenY7b7yFSP/vzU0Ocex4qZHnMdNqmYOYXkXA4C5qaFmzk4/lZMPQwzrgZB86TSsi1/H1LltB6hZF2/SNW34Dymlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; c=relaxed/simple; bh=OzzMlvRUPsVuxo2uwdVZjdw1XvEQcNHqU3yi1nNQhrA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M8qDSXdoXbIuJ4bK8gRk1jZg99uM+iEKf+kX0JLAjHfuGQrgRevuxbXZFFtVpoS7PCqrGsXpoW7zq9jjPlklEzhKcGNhCAIrFHITd+DdqYSr3kDT3QWlXh9p0RIKfMPfM4Kr2GIPCjFASUitwOzpaK0zLktvjOn/PavyBRCYpPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jD7rkTCM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jD7rkTCM" Received: by smtp.kernel.org (Postfix) with ESMTPS id EC49AC43399; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706539457; bh=OzzMlvRUPsVuxo2uwdVZjdw1XvEQcNHqU3yi1nNQhrA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=jD7rkTCMzLlTJqYSZqD/EcK01NtMEQoyJiai8pXo1P8wnvueGh7LYTQE3kEtSv7Fn 3IHU+AlFQmFWJSvIKhDEPxCYBga4I6Sy5rhm8SiS4fy+IZcPb8Kdea3iz2Ci4FfYlB PRubrsej++GSP8TulXhasNN9XYmBysB3epTc3vBu75HASyI3ShfJoe84hu8VRi+JwR Y53vi+yzHSXobSwSFeyqX8KYAjvMNBWrK37ey8D2/O0qSmrPLrq3ly0u/xFVvpyRWe 2dc5zBah9lkW25CEztV1JoVOfl9pFSl3ZoyTgC4rho6Pbs6cEHJNdkEiG9jLtjE7dc t/DBmmh7G/OHw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBAE8C47DDB; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 29 Jan 2024 14:44:18 +0000 Subject: [PATCH BlueZ v4 4/8] bluetoothd: convert external sixaxis plugin to builtin Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240129-rm-ext-plugins-v4-4-bfd1e08c7f99@gmail.com> References: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706539455; l=1169; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=rf/DV6bb4eocv72jDKDqDG7KvOMIubc6ZBWpK2UcaNg=; b=LpvifZ947TFhdMkhkLq+ZXA8o8W3kZb21ATZ17SDCuUgnVWqd4paSy/5mpAv3u1kzhsOGvnpN C8/kIVmsFuPC3kAiI0VPn/dbRvRdlqjpGugOEqDstFFL54DvhCgt2z0 X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov Convert the only known external plugin to built-in. It's a tiny 20K binary that distros ship a separate package for. Make it a builtin, which allows distros to drop the separate package, it also enables us to compile out support for external modules - both in terms of extra code and hide the internal bluetoothd API. This means that libudev.so is pulled in, which is fine since its ABI has been stable for over a decade. --- Makefile.plugins | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile.plugins b/Makefile.plugins index 5880ed0df..7cf66fd59 100644 --- a/Makefile.plugins +++ b/Makefile.plugins @@ -110,11 +110,9 @@ builtin_modules += battery builtin_sources += profiles/battery/battery.c if SIXAXIS -plugin_LTLIBRARIES += plugins/sixaxis.la -plugins_sixaxis_la_SOURCES = plugins/sixaxis.c -plugins_sixaxis_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version -plugins_sixaxis_la_LIBADD = $(UDEV_LIBS) -plugins_sixaxis_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden +builtin_modules += sixaxis +builtin_sources += plugins/sixaxis.c +builtin_ldadd += $(UDEV_LIBS) endif if BAP From patchwork Mon Jan 29 14:44:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 767654 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82F81152DF6 for ; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; cv=none; b=mySB+G2IW8U0PaTwownHRxC2N71YTRWh1sga9P1YQ+qAUaTbBfli06Za41OcEobccVAC1s9hGL/KJRfsHw2gsgnstZAT42bZXjdDDk2dupzX7p656qJDK10wqzuFp7ZSN9Al8vKkhsKmlQ9Zf4zy3PDg4M59O2iR/KC7R4pgjNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; c=relaxed/simple; bh=IcBNTPe5Nry9T4IsmqBEi0l0KqWwonBMGdJED+difIQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H5G1ppwLc5fTiya4ZF7wifX8KPJsZAuXeG8bG2Y2M2oYqxHYdp/0qgXEWuu/eLO1czaYTbZ19fA9R4vLEy7hQB+2dDCz16cznS/yYTWlsj0Z1JEKDTL2uv13VrYc8vzB+1C+Zka1xrz8VhHNsH3Gk6kbURtjtdPDJb72gC0HwsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=udemDfIC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="udemDfIC" Received: by smtp.kernel.org (Postfix) with ESMTPS id 02E3DC433A6; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706539457; bh=IcBNTPe5Nry9T4IsmqBEi0l0KqWwonBMGdJED+difIQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=udemDfICcVX07gW++d1O8rU0qtLRjZC91nK73IwfSEhKM2R54Pw3k5rc8kpQvUDJT hZ1OQhs+p+/Vr/8iKWlclUQzzZ4fBLithAU4UCzUE47ZLTWMnfjTO+IiVxhoOlqYKD OmSUeNxXu5fB33FhXsWEohk1cCRThTb1DhKENLulhQ/XogJHHRtpvXli1a3Ebq/mDS j02o5HPzg5e+swrAYaiT8yUCujOXPNWt70gA/aT1NZ/py/U1JfvalpBzMgHwV618dU Js/NwzoSCGy+PiGg7WC1zI+lBd7FL/2C0xpzL2fbElIrLYpkFjvjpqzNEGKfFTP+FW lZSNfFGUZ2xqQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7A6CC47DDF; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 29 Jan 2024 14:44:19 +0000 Subject: [PATCH BlueZ v4 5/8] bluetoothd: factor out external plugin support Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240129-rm-ext-plugins-v4-5-bfd1e08c7f99@gmail.com> References: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706539455; l=5822; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=TV/c7UPogYHUQWh6xBi+E6A5A9BeHU9R8RK05/SU01E=; b=kbOZBCoJhH8McwIsGHw75mC7Xpx4NnITS/MYyjA3668CBoiitd/82ELFvKgkLnqmo7kPRCwmO J1Or9fR7NYODuuZnEa5z3/6DojYTGN9xkHv7kQx635mBUtndZkevO1r X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov As a whole all plugins should be built-in, otherwise they would be using internal, undocumented, unversioned, unstable API. Flesh out the external plugin support and simplify the normal path. Guard the external plugin support behind a runtime check, which will be dead-code eliminated in the default case. --- Makefile.am | 4 --- src/btd.h | 2 +- src/plugin.c | 92 +++++++++++++++++++++++++++++++++++++----------------------- src/plugin.h | 4 +++ 4 files changed, 62 insertions(+), 40 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9e35d7fd9..2d5650ced 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,11 +51,7 @@ EXTRA_DIST += src/org.bluez.service plugindir = $(libdir)/bluetooth/plugins -if MAINTAINER_MODE -build_plugindir = $(abs_top_srcdir)/plugins/.libs -else build_plugindir = $(plugindir) -endif if MANPAGES man_MANS = diff --git a/src/btd.h b/src/btd.h index b7e7ebd61..7166e2168 100644 --- a/src/btd.h +++ b/src/btd.h @@ -155,7 +155,7 @@ struct btd_opts { extern struct btd_opts btd_opts; -gboolean plugin_init(const char *enable, const char *disable); +void plugin_init(const char *enable, const char *disable); void plugin_cleanup(void); void rfkill_init(void); diff --git a/src/plugin.c b/src/plugin.c index 2a29a888e..b6a84299a 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -26,6 +26,8 @@ #include "src/log.h" #include "src/btd.h" +#define IS_ENABLED(x) (x) + static GSList *plugins = NULL; struct bluetooth_plugin { @@ -42,7 +44,7 @@ static int compare_priority(gconstpointer a, gconstpointer b) return plugin2->desc->priority - plugin1->desc->priority; } -static gboolean add_plugin(void *handle, +static gboolean add_external_plugin(void *handle, const struct bluetooth_plugin_desc *desc) { struct bluetooth_plugin *plugin; @@ -72,6 +74,21 @@ static gboolean add_plugin(void *handle, return TRUE; } +static void add_plugin(const struct bluetooth_plugin_desc *desc) +{ + struct bluetooth_plugin *plugin; + + DBG("Loading %s plugin", desc->name); + + plugin = g_try_new0(struct bluetooth_plugin, 1); + if (plugin == NULL) + return; + + plugin->desc = desc; + + plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); +} + static gboolean enable_plugin(const char *name, char **cli_enable, char **cli_disable) { @@ -98,48 +115,23 @@ static gboolean enable_plugin(const char *name, char **cli_enable, return TRUE; } -#include "src/builtin.h" -gboolean plugin_init(const char *enable, const char *disable) +static void external_plugin_init(char **cli_disabled, char **cli_enabled) { - GSList *list; GDir *dir; const char *file; - char **cli_disabled, **cli_enabled; - unsigned int i; - - /* Make a call to BtIO API so its symbols got resolved before the - * plugins are loaded. */ - bt_io_error_quark(); - - if (enable) - cli_enabled = g_strsplit_set(enable, ", ", -1); - else - cli_enabled = NULL; - - if (disable) - cli_disabled = g_strsplit_set(disable, ", ", -1); - else - cli_disabled = NULL; - - DBG("Loading builtin plugins"); - - for (i = 0; __bluetooth_builtin[i]; i++) { - if (!enable_plugin(__bluetooth_builtin[i]->name, cli_enabled, - cli_disabled)) - continue; - add_plugin(NULL, __bluetooth_builtin[i]); - } + info("Using external plugins is not officially supported.\n"); + info("Consider upstreaming your plugins into the BlueZ project."); if (strlen(PLUGINDIR) == 0) - goto start; + return; DBG("Loading plugins %s", PLUGINDIR); dir = g_dir_open(PLUGINDIR, 0, NULL); if (!dir) - goto start; + return; while ((file = g_dir_read_name(dir)) != NULL) { const struct bluetooth_plugin_desc *desc; @@ -174,13 +166,45 @@ gboolean plugin_init(const char *enable, const char *disable) continue; } - if (add_plugin(handle, desc) == FALSE) + if (add_external_plugin(handle, desc) == FALSE) dlclose(handle); } g_dir_close(dir); +} + +#include "src/builtin.h" + +void plugin_init(const char *enable, const char *disable) +{ + GSList *list; + char **cli_disabled = NULL; + char **cli_enabled = NULL; + unsigned int i; + + /* Make a call to BtIO API so its symbols got resolved before the + * plugins are loaded. */ + bt_io_error_quark(); + + if (enable) + cli_enabled = g_strsplit_set(enable, ", ", -1); + + if (disable) + cli_disabled = g_strsplit_set(disable, ", ", -1); + + DBG("Loading builtin plugins"); + + for (i = 0; __bluetooth_builtin[i]; i++) { + if (!enable_plugin(__bluetooth_builtin[i]->name, cli_enabled, + cli_disabled)) + continue; + + add_plugin(__bluetooth_builtin[i]); + } + + if IS_ENABLED(EXTERNAL_PLUGINS) + external_plugin_init(cli_enabled, cli_disabled); -start: for (list = plugins; list; list = list->next) { struct bluetooth_plugin *plugin = list->data; int err; @@ -201,8 +225,6 @@ start: g_strfreev(cli_enabled); g_strfreev(cli_disabled); - - return TRUE; } void plugin_cleanup(void) diff --git a/src/plugin.h b/src/plugin.h index 8d0903f2d..b484ed378 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -28,6 +28,7 @@ struct bluetooth_plugin_desc { #name, version, priority, init, exit \ }; #else +#if EXTERNAL_PLUGINS #define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \ extern struct btd_debug_desc __start___debug[] \ __attribute__ ((weak, visibility("hidden"))); \ @@ -40,4 +41,7 @@ struct bluetooth_plugin_desc { #name, version, priority, init, exit, \ __start___debug, __stop___debug \ }; +#else +#error "Requested non built-in plugin, while external plugins is disabled" +#endif #endif From patchwork Mon Jan 29 14:44:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 768593 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83019152DFC for ; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; cv=none; b=ljos/ljdAsnZcXoj+NxB6TfxYUgVzMRuSQFAHleue92gcYLDinFyhb4tpS13etv7c532moJeOGyrheMZvDT98KiIdlKGnOSFkPosSryc/K1m+F/UhfPh+pKkD98wBpRjVgLLZjZuyLK/gTd5TOjtGzwF3PgudDJHgHJk/G+RvsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; c=relaxed/simple; bh=Qzw6fgFGlrKG70QEp7wKH52CmWymYEBdfMM/XdHZ8hY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t6KLB8h7mVtrUukETh6pXefQC+K2Spn9BLOCQ2Yc1071bm/aARvcjz2QKqCnqCBb3CW4dxnerOzvizHGNKIzKlzci9Ft22z6pwTM3jKPOpZy8t5Q0cd0UK+eIy6GIp10v9BsuWybnCQR3q+u2V2GyY+lyq0zYYsvJnr+8+iIu3o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gNITHlbG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gNITHlbG" Received: by smtp.kernel.org (Postfix) with ESMTPS id 109D5C433B2; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706539457; bh=Qzw6fgFGlrKG70QEp7wKH52CmWymYEBdfMM/XdHZ8hY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gNITHlbGiTdCPrrOk9yVI5olgTZjL4tXhCtcwqSQ8jVs/JsuXnQ5vwzUFqIPdrPLH pYMLZqrTBVQWmH9dJKRe9AHnGMy2MfWUmfTpQhsIBaKNyTgVJ5jdF5vJaTVc5BOumO 7uGJ4x/Zt1S6IPgKJKboQKYAlNuekYmSo1bxWq2doJEYn7gbf34du1K2/JeqDZS2Ew 9Axh0Le92tEjY1sU3Q3EE08d/m3s/BmbaIzjx7jd2XTQj6ekeGx46Wpr/15uG0WTdN B81uX9ypYnc5v1H/bbfpRWcqpJP0qGrrYYwtTSLupFj17DmjTvJyBt5vLCHMEmFJw7 ko4ES4oQUtLMQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F27A6C47DB3; Mon, 29 Jan 2024 14:44:16 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 29 Jan 2024 14:44:20 +0000 Subject: [PATCH BlueZ v4 6/8] bluetoothd: don't export internal API Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240129-rm-ext-plugins-v4-6-bfd1e08c7f99@gmail.com> References: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706539455; l=1054; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=IzZa7BlZN0VGepZt+klnK6SKKS7pzNjz9SN5DmTUpUs=; b=FkuQqYebrVC3b9/ftLnlmF9PMnQDHOMAKSIc87QoJM2RED78ClpGc+9WOTf1J3hgEvSBTs2FN l42ytNeTFhJBhAonQLcyM3MPlHnqgUP+OB2hBhw0ZzwHJbz4WKooeYZ X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov ... when building without external plugins. --- Makefile.am | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 2d5650ced..2b1b9acdf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -289,7 +289,6 @@ pkglibexec_PROGRAMS += src/bluetoothd src_bluetoothd_SOURCES = $(builtin_sources) \ $(attrib_sources) $(btio_sources) \ - src/bluetooth.ver \ src/main.c src/log.h src/log.c \ src/backtrace.h src/backtrace.c \ src/rfkill.c src/btd.h src/sdpd.h \ @@ -321,8 +320,12 @@ src_bluetoothd_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la \ $(BACKTRACE_LIBS) $(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt \ $(builtin_ldadd) + +if EXTERNAL_PLUGINS +src_bluetoothd_SOURCES += src/bluetooth.ver src_bluetoothd_LDFLAGS = $(AM_LDFLAGS) -Wl,--export-dynamic \ -Wl,--version-script=$(srcdir)/src/bluetooth.ver +endif src_bluetoothd_CPPFLAGS = $(AM_CPPFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \ -DPLUGINDIR=\""$(build_plugindir)"\" \ From patchwork Mon Jan 29 14:44:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 767653 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8308F152DFE for ; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; cv=none; b=nXWyWheGbrSaJ8EOx/5NPC59tpPqAmG/LPF2qn/omP0BrnBeLunsetjuganLcEGiX380uYyBcCTZgQa0VJvdIDF3kbMPR7POVDLdsDbJgwFJno3+4Y2XwaNi0ejNX0h2SfkfctdzSbDocgu9gOPg64v6UM2RWiYzs8wyeQx0KSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; c=relaxed/simple; bh=LGatdnqgDfRAq/Xk+lReqIqM4ymIrHHXvVHxoeqEusI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ng9jR6zGX5tjbVKVf2ojW8UE99ghwkEsCzp94NMJie/KIAfgfVUi7mJJrYzHgZijBfPLxlmKIFblmCCIcIs8xxpZgK9OOoVAl3o6gXd6p9e+jXOiplRS/GEITt5uLQWa6+GLFDW//8e28tRxKJgt+LEizdPsCLgI0GsO1+MVaNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pmkjXXRT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pmkjXXRT" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1A54FC433B1; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706539457; bh=LGatdnqgDfRAq/Xk+lReqIqM4ymIrHHXvVHxoeqEusI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pmkjXXRTY5S+40fhhYW7sBEoe/IMpDsfRLWyiCb35jEkbOQrEv5Du5qykPh2Wl9ma uU+YSJuKAaUmyq7s5/RSaI4EA0wlfFzTZKHODB2RSfwmGvN6s2I2KNotbMmHGWXpNl bcCqN2ymtuKG0031HfBcNioZbTf0jX9KeTeByIEAsn6YR/7RbJol6cxEcdfbV8Ab1o afUxi70d1gqLU3aA8CyzUazXGSygVl0r/I8F87fER1cyG0O+viL+qGGEOVn3E/8XiQ dENru1FlLHo2EK481ysX9rs9seYu9jrFTEhlk5cCWBQYdU+4AXQkZ4+0UYorEa6E1Q 8QjOH/y2bu5CQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08A15C48286; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 29 Jan 2024 14:44:21 +0000 Subject: [PATCH BlueZ v4 7/8] bluetoothd: change plugin loading alike obexd Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240129-rm-ext-plugins-v4-7-bfd1e08c7f99@gmail.com> References: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706539455; l=3497; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=DL7N7DwKctcZBFQW2V1+S1oTVHffRx+jI1FmauTGk9w=; b=yQ9Y89mRKZzqYkaOBPfK9oBPwzeLplN3zqrA/LUvnTzNvOcxDS+Ay5UX8gKHzdz4tatbzWoxX RAJXPy7BeHvAxi4QJyM6ckkD0hSVwjRLjIs0k0Y12txXwZhLQTDLh/1 X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov Currently, we print "Loading foobar" for every plugin, before we try the respective init() callback. Instead we handle the latter in a bunch, at the end of the process. Do the init() call early, print "Loaded" once it's actually successful and drop the no-longer "active" tracking. --- src/plugin.c | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index b6a84299a..e6d05be4c 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -32,7 +32,6 @@ static GSList *plugins = NULL; struct bluetooth_plugin { void *handle; - gboolean active; const struct bluetooth_plugin_desc *desc; }; @@ -44,6 +43,22 @@ static int compare_priority(gconstpointer a, gconstpointer b) return plugin2->desc->priority - plugin1->desc->priority; } +static int init_plugin(const struct bluetooth_plugin_desc *desc) +{ + int err; + + err = desc->init(); + if (err < 0) { + if (err == -ENOSYS || err == -ENOTSUP) + warn("System does not support %s plugin", + desc->name); + else + error("Failed to init %s plugin", + desc->name); + } + return err; +} + static gboolean add_external_plugin(void *handle, const struct bluetooth_plugin_desc *desc) { @@ -57,19 +72,22 @@ static gboolean add_external_plugin(void *handle, return FALSE; } - DBG("Loading %s plugin", desc->name); - plugin = g_try_new0(struct bluetooth_plugin, 1); if (plugin == NULL) return FALSE; plugin->handle = handle; - plugin->active = FALSE; plugin->desc = desc; + if (init_plugin(desc) < 0) { + g_free(plugin); + return FALSE; + } + __btd_enable_debug(desc->debug_start, desc->debug_stop); plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); + DBG("Plugin %s loaded", desc->name); return TRUE; } @@ -86,7 +104,13 @@ static void add_plugin(const struct bluetooth_plugin_desc *desc) plugin->desc = desc; + if (init_plugin(desc) < 0) { + g_free(plugin); + return; + } + plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); + DBG("Plugin %s loaded", desc->name); } static gboolean enable_plugin(const char *name, char **cli_enable, @@ -177,7 +201,6 @@ static void external_plugin_init(char **cli_disabled, char **cli_enabled) void plugin_init(const char *enable, const char *disable) { - GSList *list; char **cli_disabled = NULL; char **cli_enabled = NULL; unsigned int i; @@ -205,24 +228,6 @@ void plugin_init(const char *enable, const char *disable) if IS_ENABLED(EXTERNAL_PLUGINS) external_plugin_init(cli_enabled, cli_disabled); - for (list = plugins; list; list = list->next) { - struct bluetooth_plugin *plugin = list->data; - int err; - - err = plugin->desc->init(); - if (err < 0) { - if (err == -ENOSYS || err == -ENOTSUP) - warn("System does not support %s plugin", - plugin->desc->name); - else - error("Failed to init %s plugin", - plugin->desc->name); - continue; - } - - plugin->active = TRUE; - } - g_strfreev(cli_enabled); g_strfreev(cli_disabled); } @@ -236,7 +241,7 @@ void plugin_cleanup(void) for (list = plugins; list; list = list->next) { struct bluetooth_plugin *plugin = list->data; - if (plugin->active == TRUE && plugin->desc->exit) + if (plugin->desc->exit) plugin->desc->exit(); if (plugin->handle != NULL) From patchwork Mon Jan 29 14:44:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via B4 Relay X-Patchwork-Id: 768594 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82FB8152DF8 for ; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; cv=none; b=CKwfRuBdQZta6UZWpRkqq5az5XPdgc+SwPy7m+o7TI383m2znh/9ghQoQ9WyXCKIy9Lt/URwAoCJzyIFZHwD0DXBBGT0sQOKMSqbhiSD6Bdv4JIQoqCiMH5tHOt9ZelcpmyaR1mV9jcHXCw7W5gG/ePi/RMFVbxW63voMLcnoDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706539457; c=relaxed/simple; bh=mb3vibSeCho7dxgk/hsygvpcHcp9zzLKyD4RpuB1Dx8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RBasCbcfIr+UXlCAbSsjTsRuxDoUdHj7kPoRAjXiBko1HDR06M6Wc8tPDon7zhmFQwDSiRwnX1vjJaEYJduhYo+fyzCpmLNg/Xp++5JgbUUTJKXH3d0arxqgePOsYwZrVK6XfiYIj8Io+b/du1bb49R7nGig/PqIWjjgaVSO41Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hquQLg2J; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hquQLg2J" Received: by smtp.kernel.org (Postfix) with ESMTPS id 22A59C43601; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706539457; bh=mb3vibSeCho7dxgk/hsygvpcHcp9zzLKyD4RpuB1Dx8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hquQLg2J3Xr5ZqIP/iNSdbU8AqopGCuS4Cwmz+02dxdDwiWDxCkf7OpdM+zvVO3SK lGpVPNNj1EnUg2c5OHoVF6G2tpeMBnZXKI181RXyMSiIL6PuBbSJKUTEuXVV7ggftV v4Da3Cf0JtWsszL8QGilbpSzUhwzkMukKoSr88XRncZVtOvf/7wIZEc06DqVuMebb+ wwzyARtjRtdGplf8i+YFY9O5O1k6S0oF6h2h9q2Ebali6ivCvhAG+IbBwWIsk/0c6j NAOo4r/3cZwDUsmp4rbnTJ+iEg+BAXo3YkCQUgcvibXMs1HqZPcIria3/wOzetkXL8 e34rFOhFoCISw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12DC6C47DDB; Mon, 29 Jan 2024 14:44:17 +0000 (UTC) From: Emil Velikov via B4 Relay Date: Mon, 29 Jan 2024 14:44:22 +0000 Subject: [PATCH BlueZ v4 8/8] android: export only (android) entrypoint from the modules Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240129-rm-ext-plugins-v4-8-bfd1e08c7f99@gmail.com> References: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com> To: linux-bluetooth@vger.kernel.org Cc: Emil Velikov X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706539455; l=3016; i=emil.l.velikov@gmail.com; s=20230301; h=from:subject:message-id; bh=A9wt+5pbCxd+p0NIbARFNH3H5ujiQXTs0z8giNMkb3Y=; b=K76VOkTcnUI3PuCqNvoo+6kvKl0OiLlo1ASE+yYAnkjP5r9Rj//Yh7YSN/e0O+h4rIxOR315X gnD3Z6uYd5zCwHWjTq7ONZyMD3J1jzH8lXv82vqReehAVxtDA8bk/WS X-Developer-Key: i=emil.l.velikov@gmail.com; a=ed25519; pk=qeUTVTNyI3rcR2CfNNWsloTihgzmtbZo98GdxwZKCkY= X-Endpoint-Received: by B4 Relay for emil.l.velikov@gmail.com/20230301 with auth_id=35 X-Original-From: Emil Velikov Reply-To: From: Emil Velikov The android specific modules, have a designated HMI entrypoint. Hide everything else with -fvisibility=hidden. --- android/Makefile.am | 3 +++ android/hal-audio.c | 1 + android/hal-bluetooth.c | 1 + android/hal-sco.c | 1 + 4 files changed, 6 insertions(+) diff --git a/android/Makefile.am b/android/Makefile.am index 309910147..e3756e89c 100644 --- a/android/Makefile.am +++ b/android/Makefile.am @@ -96,6 +96,7 @@ android_bluetooth_default_la_SOURCES = android/hal.h android/hal-bluetooth.c \ android/hal-log.h \ android/hal-ipc.h android/hal-ipc.c \ android/hal-utils.h android/hal-utils.c +android_bluetooth_default_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden android_bluetooth_default_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/android android_bluetooth_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \ -no-undefined @@ -195,6 +196,7 @@ android_audio_a2dp_default_la_SOURCES = android/audio-msg.h \ android/hardware/audio_effect.h \ android/hardware/hardware.h \ android/system/audio.h +android_audio_a2dp_default_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden android_audio_a2dp_default_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/android \ $(SBC_CFLAGS) android_audio_a2dp_default_la_LIBADD = $(SBC_LIBS) -lrt @@ -212,6 +214,7 @@ android_audio_sco_default_la_SOURCES = android/hal-log.h \ android/audio_utils/resampler.c \ android/audio_utils/resampler.h \ android/system/audio.h +android_audio_sco_default_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden android_audio_sco_default_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/android android_audio_sco_default_la_LIBADD = $(SPEEXDSP_LIBS) -lrt android_audio_sco_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \ diff --git a/android/hal-audio.c b/android/hal-audio.c index d37d6098c..f3d9b40a6 100644 --- a/android/hal-audio.c +++ b/android/hal-audio.c @@ -1618,6 +1618,7 @@ static struct hw_module_methods_t hal_module_methods = { .open = audio_open, }; +__attribute__ ((visibility("default"))) struct audio_module HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG, diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c index d4442e620..7d1e5ac63 100644 --- a/android/hal-bluetooth.c +++ b/android/hal-bluetooth.c @@ -1117,6 +1117,7 @@ static struct hw_module_methods_t bluetooth_module_methods = { .open = open_bluetooth, }; +__attribute__ ((visibility("default"))) struct hw_module_t HAL_MODULE_INFO_SYM = { .tag = HARDWARE_MODULE_TAG, .version_major = 1, diff --git a/android/hal-sco.c b/android/hal-sco.c index d7c08a68b..3d66ad357 100644 --- a/android/hal-sco.c +++ b/android/hal-sco.c @@ -1507,6 +1507,7 @@ static struct hw_module_methods_t hal_module_methods = { .open = sco_open, }; +__attribute__ ((visibility("default"))) struct audio_module HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG,