From: Emil Velikov via B4 Relay <devnull+emil.l.velikov.gmail.com@kernel.org>
To: linux-bluetooth@vger.kernel.org
Cc: Emil Velikov <emil.velikov@collabora.com>
Subject: [PATCH BlueZ v4 7/8] bluetoothd: change plugin loading alike obexd
Date: Mon, 29 Jan 2024 14:44:21 +0000 [thread overview]
Message-ID: <20240129-rm-ext-plugins-v4-7-bfd1e08c7f99@gmail.com> (raw)
In-Reply-To: <20240129-rm-ext-plugins-v4-0-bfd1e08c7f99@gmail.com>
From: Emil Velikov <emil.velikov@collabora.com>
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)
--
2.43.0
next prev parent reply other threads:[~2024-01-29 14:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-29 14:44 [PATCH BlueZ v4 0/8] Remove support for external plugins Emil Velikov via B4 Relay
2024-01-29 14:44 ` [PATCH BlueZ v4 1/8] configure, README: introduce --enable-external-plugins Emil Velikov via B4 Relay
2024-01-29 17:27 ` Remove support for external plugins bluez.test.bot
2024-01-29 14:44 ` [PATCH BlueZ v4 2/8] obexd: factor out external plugin support Emil Velikov via B4 Relay
2024-01-29 14:44 ` [PATCH BlueZ v4 3/8] bluetoothd: remove external-dummy plugin Emil Velikov via B4 Relay
2024-01-29 14:44 ` [PATCH BlueZ v4 4/8] bluetoothd: convert external sixaxis plugin to builtin Emil Velikov via B4 Relay
2024-01-29 14:44 ` [PATCH BlueZ v4 5/8] bluetoothd: factor out external plugin support Emil Velikov via B4 Relay
2024-01-29 14:44 ` [PATCH BlueZ v4 6/8] bluetoothd: don't export internal API Emil Velikov via B4 Relay
2024-01-29 14:44 ` Emil Velikov via B4 Relay [this message]
2024-01-29 15:37 ` [PATCH BlueZ v4 7/8] bluetoothd: change plugin loading alike obexd Paul Menzel
2024-01-29 16:22 ` Luiz Augusto von Dentz
2024-01-29 17:47 ` Emil Velikov
2024-01-29 14:44 ` [PATCH BlueZ v4 8/8] android: export only (android) entrypoint from the modules Emil Velikov via B4 Relay
2024-01-29 15:38 ` Paul Menzel
2024-01-29 19:00 ` [PATCH BlueZ v4 0/8] Remove support for external plugins patchwork-bot+bluetooth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240129-rm-ext-plugins-v4-7-bfd1e08c7f99@gmail.com \
--to=devnull+emil.l.velikov.gmail.com@kernel.org \
--cc=emil.l.velikov@gmail.com \
--cc=emil.velikov@collabora.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).