All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] client: Handle system bus setup failure
@ 2026-08-28 20:52 ` Tim Sweetman
  0 siblings, 0 replies; 4+ messages in thread
From: Tim Sweetman via B4 Relay @ 2026-08-28 20:52 UTC (permalink / raw)
  To: Linux Bluetooth

From: Tim Sweetman <agenttimblog@gmail.com>

g_dbus_setup_bus() returns NULL when it cannot connect to the system
bus. bluetoothctl currently passes that NULL connection to
g_dbus_attach_object_manager(), causing libdbus to abort on its
connection assertion.

Initialize a DBusError, report the connection failure, and exit cleanly
before using the connection.

Fixes: https://github.com/bluez/bluez/issues/2446
---
Tested with make check (34 tests).
---
 client/main.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/client/main.c b/client/main.c
index 069e20485..d7cecb118 100644
--- a/client/main.c
+++ b/client/main.c
@@ -4017,6 +4017,7 @@ static bool timeout_quit(void *user_data)
 int main(int argc, char *argv[])
 {
 	GDBusClient *client;
+	DBusError error;
 	int status;
 	int timeout;
 	unsigned int timeout_id;
@@ -4048,7 +4049,21 @@ int main(int argc, char *argv[])
 	else
 		auto_register_agent = g_strdup("");
 
-	dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
+	dbus_error_init(&error);
+	dbus_conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &error);
+	if (dbus_conn == NULL) {
+		if (dbus_error_is_set(&error)) {
+			fprintf(stderr, "Failed to connect to system bus: %s\n",
+							error.message);
+			dbus_error_free(&error);
+		} else {
+			fprintf(stderr, "Failed to connect to system bus\n");
+		}
+
+		g_free(auto_register_agent);
+		return EXIT_FAILURE;
+	}
+
 	g_dbus_attach_object_manager(dbus_conn);
 
 	bt_shell_set_env("DBUS_CONNECTION", dbus_conn);

---
base-commit: e8141342284be2a52e16565b96b513ebe1297d84
change-id: 20260828-master-e87099ea4429

Best regards,
--  
Tim Sweetman <agenttimblog@gmail.com>



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-12 22:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28 20:52 [PATCH BlueZ] client: Handle system bus setup failure Tim Sweetman via B4 Relay
2026-08-28 20:52 ` Tim Sweetman
2026-08-28 22:16 ` [BlueZ] " bluez.test.bot
2026-09-12 22:42 ` bluez.test.bot

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.