diff mbox series

[BlueZ,v4,1/6] pbap: Support calling pbap_init() after pbap_exit()

Message ID 20250428131842.488921-2-kernel.org@pileofstuff.org
State Superseded
Headers show
Series obexd: unregister profiles when the user is inactive | expand

Commit Message

Andrew Sayers April 28, 2025, 1:15 p.m. UTC
pbap_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 the UnregisterProfile message directly from pbap_exit(),
then call unregister_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.

Signed-off-by: Andrew Sayers <kernel.org@pileofstuff.org>
---
 obexd/client/pbap.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Luiz Augusto von Dentz April 28, 2025, 9:47 p.m. UTC | #1
Hi Andrew,

On Mon, Apr 28, 2025 at 9:19 AM Andrew Sayers
<kernel.org@pileofstuff.org> wrote:
>
> pbap_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 the UnregisterProfile message directly from pbap_exit(),
> then call unregister_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.
>
> Signed-off-by: Andrew Sayers <kernel.org@pileofstuff.org>
> ---
>  obexd/client/pbap.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/obexd/client/pbap.c b/obexd/client/pbap.c
> index 2f234fadf..90f8bdc02 100644
> --- a/obexd/client/pbap.c
> +++ b/obexd/client/pbap.c
> @@ -1485,8 +1485,20 @@ void pbap_exit(void)
>  {
>         DBG("");
>
> -       dbus_connection_unref(conn);
> -       conn = NULL;
> +       g_dbus_remove_watch(system_conn, listener_id);
> +
> +       unregister_profile();
> +
> +       if (system_conn) {
> +               dbus_connection_close(system_conn);
> +               dbus_connection_unref(system_conn);
> +               system_conn = NULL;
> +       }
> +
> +       if (conn) {
> +               dbus_connection_unref(conn);
> +               conn = NULL;
> +       }
>
>         obc_driver_unregister(&pbap);
>  }
> --
> 2.49.0

Quite a few errors still: https://github.com/bluez/bluez/pull/1208
diff mbox series

Patch

diff --git a/obexd/client/pbap.c b/obexd/client/pbap.c
index 2f234fadf..90f8bdc02 100644
--- a/obexd/client/pbap.c
+++ b/obexd/client/pbap.c
@@ -1485,8 +1485,20 @@  void pbap_exit(void)
 {
 	DBG("");
 
-	dbus_connection_unref(conn);
-	conn = NULL;
+	g_dbus_remove_watch(system_conn, listener_id);
+
+	unregister_profile();
+
+	if (system_conn) {
+		dbus_connection_close(system_conn);
+		dbus_connection_unref(system_conn);
+		system_conn = NULL;
+	}
+
+	if (conn) {
+		dbus_connection_unref(conn);
+		conn = NULL;
+	}
 
 	obc_driver_unregister(&pbap);
 }