From: Andrew Sayers <kernel.org@pileofstuff.org>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.dentz@gmail.com, pav@iki.fi,
Andrew Sayers <kernel.org@pileofstuff.org>
Subject: [PATCH BlueZ 2/4] obexd/bluetooth: Support calling bluetooth_init() after bluetooth_exit()
Date: Wed, 23 Apr 2025 17:33:24 +0100 [thread overview]
Message-ID: <20250423163343.4160595-3-kernel.org@pileofstuff.org> (raw)
In-Reply-To: <20250423163343.4160595-1-kernel.org@pileofstuff.org>
bluetooth_exit() didn't previously unregister itself thoroughly. That
was fine if it was only called when the service was about to exit,
because everything was implicitly unregistered when the process ended.
But we need to be more scrupulous if this can be called throughout
the program's lifecycle.
Send UnregisterProfile messages directly from bluetooth_exit(),
then call unregister_profile(profile).
The UnregisterProfile message can't be sent directly from
unregister_profile(), because that also needs to be called when
register_profile() fails halfway through.
Do not free profiles in bluetooth_exit() - profiles are needed
by a future call to bluetooth_init(), or will be freed by
bluetooth_stop() if necessary.
Signed-off-by: Andrew Sayers <kernel.org@pileofstuff.org>
---
obexd/plugins/bluetooth.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/obexd/plugins/bluetooth.c b/obexd/plugins/bluetooth.c
index afb2215bd..bcaf19bae 100644
--- a/obexd/plugins/bluetooth.c
+++ b/obexd/plugins/bluetooth.c
@@ -440,12 +440,38 @@ static int bluetooth_init(void)
static void bluetooth_exit(void)
{
+ DBusMessage *msg;
+ DBusMessageIter iter;
+ GSList *l;
+
g_dbus_remove_watch(connection, listener_id);
- g_slist_free_full(profiles, profile_free);
+ for (l = profiles; l; l = l->next) {
+ struct bluetooth_profile *profile = l->data;
+
+ if (profile->path == NULL)
+ continue;
- if (connection)
+ msg = dbus_message_new_method_call(
+ "org.bluez", "/org/bluez",
+ "org.bluez.ProfileManager1",
+ "UnregisterProfile");
+
+ dbus_message_iter_init_append(msg, &iter);
+
+ dbus_message_iter_append_basic(&iter,
+ DBUS_TYPE_OBJECT_PATH,
+ &profile->path);
+
+ g_dbus_send_message(connection, msg);
+
+ unregister_profile(profile);
+ }
+
+ if (connection) {
dbus_connection_unref(connection);
+ connection = NULL;
+ }
obex_transport_driver_unregister(&driver);
}
--
2.49.0
next prev parent reply other threads:[~2025-04-23 16:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 16:33 [PATCH 0/4] obex: unregster profiles when the user is inactive Andrew Sayers
2025-04-23 16:33 ` [PATCH BlueZ 1/4] pbap: Support calling pbap_init() after pbap_exit() Andrew Sayers
2025-04-23 17:02 ` Pauli Virtanen
2025-04-24 17:20 ` obex: unregster profiles when the user is inactive bluez.test.bot
2025-04-23 16:33 ` Andrew Sayers [this message]
2025-04-23 16:33 ` [PATCH BlueZ 3/4] " Andrew Sayers
2025-04-23 16:33 ` [PATCH BlueZ 4/4] Revert "obexd: only run one instance at once" Andrew Sayers
2025-05-01 13:50 ` [PATCH 0/4] obex: unregster profiles when the user is inactive 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=20250423163343.4160595-3-kernel.org@pileofstuff.org \
--to=kernel.org@pileofstuff.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=pav@iki.fi \
/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