[PATCH bluez 1/2] obexd/bluetooth: Register profiles added after org.bluez appeared

From: Zijun Hu

Date: Wed Oct 28 2026 - 02:46:26 EST


Issue:
After boot on Debian, bluetoothd and obexd are both running but none of
the obexd server profiles (OPP, FTP, PBAP, ...) is registered.

Why:
A race between name_acquired() and bluetooth_start(). The profiles are
only registered if org.bluez appears after bluetooth_start() has added
them:
plugin_init()
1. bluetooth_init() start watching org.bluez
2. pbap_init(), irmc_init()
e_source_registry_new_sync()
sync call, fails on Debian
3. name_acquired() fired, but the profiles list is
empty, so nothing is registered
obex_server_init()
4. bluetooth_start() adds the profiles to the list,
but nothing registers them

Fix:
Register profiles in bluetooth_start() that name_acquired() did not
register, if org.bluez is already available.

Fixes: 23b28ab759ee ("obexd: Port bluetooth plugin to use external profile support")
Assisted-by: Claude:claude-sonnet-5-5
---
obexd/plugins/bluetooth.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/obexd/plugins/bluetooth.c b/obexd/plugins/bluetooth.c
index 3af1b504d591..b70090971119 100644
--- a/obexd/plugins/bluetooth.c
+++ b/obexd/plugins/bluetooth.c
@@ -45,16 +45,17 @@ struct bluetooth_profile {
const struct obex_service_driver *driver;
char *uuid;
char *path;
};

static GSList *profiles = NULL;

static DBusConnection *connection = NULL;
+static gboolean bluez_available = FALSE;

static DBusMessage *profile_release(DBusConnection *conn, DBusMessage *msg,
void *data)
{
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}

static void connect_event(GIOChannel *io, GError *err, void *user_data)
@@ -315,16 +316,18 @@ static const char *service2uuid(uint16_t service)
}

static void name_acquired(DBusConnection *conn, void *user_data)
{
GSList *l;

DBG("org.bluez appeared");

+ bluez_available = TRUE;
+
for (l = profiles; l; l = l->next) {
struct bluetooth_profile *profile = l->data;

if (profile->path != NULL)
continue;

if (register_profile(profile) < 0) {
error("bluetooth: Failed to register profile %s",
@@ -336,16 +339,18 @@ static void name_acquired(DBusConnection *conn, void *user_data)
}

static void name_released(DBusConnection *conn, void *user_data)
{
GSList *l;

DBG("org.bluez disappeared");

+ bluez_available = FALSE;
+
for (l = profiles; l; l = l->next) {
struct bluetooth_profile *profile = l->data;

if (profile->path == NULL)
continue;

unregister_profile(profile);
}
@@ -365,16 +370,25 @@ static void *bluetooth_start(struct obex_server *server, int *err)
continue;

profile = g_new0(struct bluetooth_profile, 1);
profile->driver = driver;
profile->server = server;
profile->uuid = g_strdup(uuid);

profiles = g_slist_prepend(profiles, profile);
+
+ /*
+ * This profile had not been added to the profiles list when
+ * name_acquired() ran, so it was not registered by that call.
+ * Register it here.
+ */
+ if (bluez_available && register_profile(profile) < 0)
+ error("bluetooth: Failed to register profile UUID %s",
+ profile->uuid);
}

return profiles;
}

static void bluetooth_stop(void *data)
{
g_slist_free_full(profiles, profile_free);
@@ -441,16 +455,17 @@ static int bluetooth_init_cb(gboolean at_register)
}

static void bluetooth_exit_cb(gboolean at_unregister)
{
GSList *l;
(void)at_unregister;

g_dbus_remove_watch(connection, listener_id);
+ bluez_available = FALSE;

for (l = profiles; l; l = l->next) {
struct bluetooth_profile *profile = l->data;

if (profile->path == NULL)
continue;

unregister_profile(profile);

--
2.34.1