From: Emil Velikov <emil.l.velikov@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Emil Velikov <emil.velikov@collabora.com>
Subject: [PATCH BlueZ 5/8] bluetoothd: remove support for external plugins
Date: Tue, 16 Jan 2024 14:18:57 +0000 [thread overview]
Message-ID: <20240116-rm-ext-plugins-v1-5-62990fb07369@gmail.com> (raw)
In-Reply-To: <20240116-rm-ext-plugins-v1-0-62990fb07369@gmail.com>
From: Emil Velikov <emil.velikov@collabora.com>
With the final one converted to a builtin, we can drop the now dead
code. As follow-up this will allow us to stop exposing the internal API
of bluetoothd, reducing its size.
---
Makefile.am | 10 +--------
src/btd.h | 2 +-
src/plugin.c | 72 +++++-------------------------------------------------------
src/plugin.h | 14 ------------
4 files changed, 8 insertions(+), 90 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index ea51b25cc..4db3a2953 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,12 +51,6 @@ EXTRA_DIST += src/bluetooth.service.in 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 =
endif
@@ -337,9 +331,7 @@ src_bluetoothd_DEPENDENCIES = lib/libbluetooth-internal.la \
src/libshared-glib.la \
src/bluetooth.service
-src_bluetoothd_CPPFLAGS = $(AM_CPPFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \
- -DPLUGINDIR=\""$(build_plugindir)"\" \
- $(BACKTRACE_CFLAGS) $(builtin_cppflags)
+src_bluetoothd_CPPFLAGS = $(AM_CPPFLAGS) $(BACKTRACE_CFLAGS) $(builtin_cppflags)
src_bluetoothd_SHORTNAME = bluetoothd
builtin_files = src/builtin.h $(builtin_nodist)
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 80990f8c3..1631f201c 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -29,7 +29,6 @@
static GSList *plugins = NULL;
struct bluetooth_plugin {
- void *handle;
gboolean active;
struct bluetooth_plugin_desc *desc;
};
@@ -42,33 +41,30 @@ static int compare_priority(gconstpointer a, gconstpointer b)
return plugin2->desc->priority - plugin1->desc->priority;
}
-static gboolean add_plugin(void *handle, struct bluetooth_plugin_desc *desc)
+static void add_plugin(struct bluetooth_plugin_desc *desc)
{
struct bluetooth_plugin *plugin;
if (desc->init == NULL)
- return FALSE;
+ return;
if (g_str_equal(desc->version, VERSION) == FALSE) {
error("Version mismatch for %s", desc->name);
- return FALSE;
+ return;
}
DBG("Loading %s plugin", desc->name);
plugin = g_try_new0(struct bluetooth_plugin, 1);
if (plugin == NULL)
- return FALSE;
+ return;
- plugin->handle = handle;
plugin->active = FALSE;
plugin->desc = desc;
__btd_enable_debug(desc->debug_start, desc->debug_stop);
plugins = g_slist_insert_sorted(plugins, plugin, compare_priority);
-
- return TRUE;
}
static gboolean enable_plugin(const char *name, char **cli_enable,
@@ -99,11 +95,9 @@ static gboolean enable_plugin(const char *name, char **cli_enable,
#include "src/builtin.h"
-gboolean plugin_init(const char *enable, const char *disable)
+void plugin_init(const char *enable, const char *disable)
{
GSList *list;
- GDir *dir;
- const char *file;
char **cli_disabled, **cli_enabled;
unsigned int i;
@@ -128,58 +122,9 @@ gboolean plugin_init(const char *enable, const char *disable)
cli_disabled))
continue;
- add_plugin(NULL, __bluetooth_builtin[i]);
+ add_plugin(__bluetooth_builtin[i]);
}
- if (strlen(PLUGINDIR) == 0)
- goto start;
-
- DBG("Loading plugins %s", PLUGINDIR);
-
- dir = g_dir_open(PLUGINDIR, 0, NULL);
- if (!dir)
- goto start;
-
- while ((file = g_dir_read_name(dir)) != NULL) {
- struct bluetooth_plugin_desc *desc;
- void *handle;
- char *filename;
-
- if (g_str_has_prefix(file, "lib") == TRUE ||
- g_str_has_suffix(file, ".so") == FALSE)
- continue;
-
- filename = g_build_filename(PLUGINDIR, file, NULL);
-
- handle = dlopen(filename, RTLD_NOW);
- if (handle == NULL) {
- error("Can't load plugin %s: %s", filename,
- dlerror());
- g_free(filename);
- continue;
- }
-
- g_free(filename);
-
- desc = dlsym(handle, "bluetooth_plugin_desc");
- if (desc == NULL) {
- error("Can't load plugin description: %s", dlerror());
- dlclose(handle);
- continue;
- }
-
- if (!enable_plugin(desc->name, cli_enabled, cli_disabled)) {
- dlclose(handle);
- continue;
- }
-
- if (add_plugin(handle, desc) == FALSE)
- dlclose(handle);
- }
-
- g_dir_close(dir);
-
-start:
for (list = plugins; list; list = list->next) {
struct bluetooth_plugin *plugin = list->data;
int err;
@@ -200,8 +145,6 @@ start:
g_strfreev(cli_enabled);
g_strfreev(cli_disabled);
-
- return TRUE;
}
void plugin_cleanup(void)
@@ -216,9 +159,6 @@ void plugin_cleanup(void)
if (plugin->active == TRUE && plugin->desc->exit)
plugin->desc->exit();
- if (plugin->handle != NULL)
- dlclose(plugin->handle);
-
g_free(plugin);
}
diff --git a/src/plugin.h b/src/plugin.h
index a5f92a557..7ff55e796 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -21,21 +21,7 @@ struct bluetooth_plugin_desc {
void *debug_stop;
};
-#ifdef BLUETOOTH_PLUGIN_BUILTIN
#define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \
struct bluetooth_plugin_desc __bluetooth_builtin_ ## name = { \
#name, version, priority, init, exit \
};
-#else
-#define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \
- extern struct btd_debug_desc __start___debug[] \
- __attribute__ ((weak, visibility("hidden"))); \
- extern struct btd_debug_desc __stop___debug[] \
- __attribute__ ((weak, visibility("hidden"))); \
- extern struct bluetooth_plugin_desc bluetooth_plugin_desc \
- __attribute__ ((visibility("default"))); \
- struct bluetooth_plugin_desc bluetooth_plugin_desc = { \
- #name, version, priority, init, exit, \
- __start___debug, __stop___debug \
- };
-#endif
--
2.43.0
WARNING: multiple messages have this Message-ID (diff)
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 5/8] bluetoothd: remove support for external plugins
Date: Tue, 16 Jan 2024 14:18:57 +0000 [thread overview]
Message-ID: <20240116-rm-ext-plugins-v1-5-62990fb07369@gmail.com> (raw)
In-Reply-To: <20240116-rm-ext-plugins-v1-0-62990fb07369@gmail.com>
From: Emil Velikov <emil.velikov@collabora.com>
With the final one converted to a builtin, we can drop the now dead
code. As follow-up this will allow us to stop exposing the internal API
of bluetoothd, reducing its size.
---
Makefile.am | 10 +--------
src/btd.h | 2 +-
src/plugin.c | 72 +++++-------------------------------------------------------
src/plugin.h | 14 ------------
4 files changed, 8 insertions(+), 90 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index ea51b25cc..4db3a2953 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,12 +51,6 @@ EXTRA_DIST += src/bluetooth.service.in 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 =
endif
@@ -337,9 +331,7 @@ src_bluetoothd_DEPENDENCIES = lib/libbluetooth-internal.la \
src/libshared-glib.la \
src/bluetooth.service
-src_bluetoothd_CPPFLAGS = $(AM_CPPFLAGS) -DBLUETOOTH_PLUGIN_BUILTIN \
- -DPLUGINDIR=\""$(build_plugindir)"\" \
- $(BACKTRACE_CFLAGS) $(builtin_cppflags)
+src_bluetoothd_CPPFLAGS = $(AM_CPPFLAGS) $(BACKTRACE_CFLAGS) $(builtin_cppflags)
src_bluetoothd_SHORTNAME = bluetoothd
builtin_files = src/builtin.h $(builtin_nodist)
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 80990f8c3..1631f201c 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -29,7 +29,6 @@
static GSList *plugins = NULL;
struct bluetooth_plugin {
- void *handle;
gboolean active;
struct bluetooth_plugin_desc *desc;
};
@@ -42,33 +41,30 @@ static int compare_priority(gconstpointer a, gconstpointer b)
return plugin2->desc->priority - plugin1->desc->priority;
}
-static gboolean add_plugin(void *handle, struct bluetooth_plugin_desc *desc)
+static void add_plugin(struct bluetooth_plugin_desc *desc)
{
struct bluetooth_plugin *plugin;
if (desc->init == NULL)
- return FALSE;
+ return;
if (g_str_equal(desc->version, VERSION) == FALSE) {
error("Version mismatch for %s", desc->name);
- return FALSE;
+ return;
}
DBG("Loading %s plugin", desc->name);
plugin = g_try_new0(struct bluetooth_plugin, 1);
if (plugin == NULL)
- return FALSE;
+ return;
- plugin->handle = handle;
plugin->active = FALSE;
plugin->desc = desc;
__btd_enable_debug(desc->debug_start, desc->debug_stop);
plugins = g_slist_insert_sorted(plugins, plugin, compare_priority);
-
- return TRUE;
}
static gboolean enable_plugin(const char *name, char **cli_enable,
@@ -99,11 +95,9 @@ static gboolean enable_plugin(const char *name, char **cli_enable,
#include "src/builtin.h"
-gboolean plugin_init(const char *enable, const char *disable)
+void plugin_init(const char *enable, const char *disable)
{
GSList *list;
- GDir *dir;
- const char *file;
char **cli_disabled, **cli_enabled;
unsigned int i;
@@ -128,58 +122,9 @@ gboolean plugin_init(const char *enable, const char *disable)
cli_disabled))
continue;
- add_plugin(NULL, __bluetooth_builtin[i]);
+ add_plugin(__bluetooth_builtin[i]);
}
- if (strlen(PLUGINDIR) == 0)
- goto start;
-
- DBG("Loading plugins %s", PLUGINDIR);
-
- dir = g_dir_open(PLUGINDIR, 0, NULL);
- if (!dir)
- goto start;
-
- while ((file = g_dir_read_name(dir)) != NULL) {
- struct bluetooth_plugin_desc *desc;
- void *handle;
- char *filename;
-
- if (g_str_has_prefix(file, "lib") == TRUE ||
- g_str_has_suffix(file, ".so") == FALSE)
- continue;
-
- filename = g_build_filename(PLUGINDIR, file, NULL);
-
- handle = dlopen(filename, RTLD_NOW);
- if (handle == NULL) {
- error("Can't load plugin %s: %s", filename,
- dlerror());
- g_free(filename);
- continue;
- }
-
- g_free(filename);
-
- desc = dlsym(handle, "bluetooth_plugin_desc");
- if (desc == NULL) {
- error("Can't load plugin description: %s", dlerror());
- dlclose(handle);
- continue;
- }
-
- if (!enable_plugin(desc->name, cli_enabled, cli_disabled)) {
- dlclose(handle);
- continue;
- }
-
- if (add_plugin(handle, desc) == FALSE)
- dlclose(handle);
- }
-
- g_dir_close(dir);
-
-start:
for (list = plugins; list; list = list->next) {
struct bluetooth_plugin *plugin = list->data;
int err;
@@ -200,8 +145,6 @@ start:
g_strfreev(cli_enabled);
g_strfreev(cli_disabled);
-
- return TRUE;
}
void plugin_cleanup(void)
@@ -216,9 +159,6 @@ void plugin_cleanup(void)
if (plugin->active == TRUE && plugin->desc->exit)
plugin->desc->exit();
- if (plugin->handle != NULL)
- dlclose(plugin->handle);
-
g_free(plugin);
}
diff --git a/src/plugin.h b/src/plugin.h
index a5f92a557..7ff55e796 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -21,21 +21,7 @@ struct bluetooth_plugin_desc {
void *debug_stop;
};
-#ifdef BLUETOOTH_PLUGIN_BUILTIN
#define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \
struct bluetooth_plugin_desc __bluetooth_builtin_ ## name = { \
#name, version, priority, init, exit \
};
-#else
-#define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \
- extern struct btd_debug_desc __start___debug[] \
- __attribute__ ((weak, visibility("hidden"))); \
- extern struct btd_debug_desc __stop___debug[] \
- __attribute__ ((weak, visibility("hidden"))); \
- extern struct bluetooth_plugin_desc bluetooth_plugin_desc \
- __attribute__ ((visibility("default"))); \
- struct bluetooth_plugin_desc bluetooth_plugin_desc = { \
- #name, version, priority, init, exit, \
- __start___debug, __stop___debug \
- };
-#endif
--
2.43.0
next prev parent reply other threads:[~2024-01-16 14:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 14:18 [PATCH BlueZ 0/8] Remove support for external plugins Emil Velikov
2024-01-16 14:18 ` Emil Velikov via B4 Relay
2024-01-16 14:18 ` [PATCH BlueZ 1/8] obexd: remove " Emil Velikov
2024-01-16 14:18 ` Emil Velikov via B4 Relay
2024-01-16 16:47 ` Remove " bluez.test.bot
2024-01-16 14:18 ` [PATCH BlueZ 2/8] build: don't export internal obexd API Emil Velikov
2024-01-16 14:18 ` Emil Velikov via B4 Relay
2024-01-16 14:18 ` [PATCH BlueZ 3/8] plugins: remove external-dummy Emil Velikov
2024-01-16 14:18 ` Emil Velikov via B4 Relay
2024-01-16 14:18 ` [PATCH BlueZ 4/8] plugins: convert external sixaxis plugin to builtin Emil Velikov
2024-01-16 14:18 ` Emil Velikov via B4 Relay
2024-01-16 14:18 ` Emil Velikov [this message]
2024-01-16 14:18 ` [PATCH BlueZ 5/8] bluetoothd: remove support for external plugins Emil Velikov via B4 Relay
2024-01-16 14:18 ` [PATCH BlueZ 6/8] bluetoothd: remove debug " Emil Velikov
2024-01-16 14:18 ` Emil Velikov via B4 Relay
2024-01-16 14:18 ` [PATCH BlueZ 7/8] bluetoothd: don't export internal API Emil Velikov
2024-01-16 14:18 ` Emil Velikov via B4 Relay
2024-01-16 14:19 ` [PATCH BlueZ 8/8] android: export only (android) entrypoint from the modules Emil Velikov
2024-01-16 14:19 ` Emil Velikov via B4 Relay
2024-01-22 18:34 ` [PATCH BlueZ 0/8] Remove support for external plugins Luiz Augusto von Dentz
2024-01-23 13:54 ` Emil Velikov
2024-01-23 13:59 ` Luiz Augusto von Dentz
2024-01-23 15:09 ` Emil Velikov
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=20240116-rm-ext-plugins-v1-5-62990fb07369@gmail.com \
--to=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.