Skip to contentSkip to conversation

Fix bluetoothctl --help hanging if daemon isn't running

PATCH In review Bastien Nocera 4 participants 14 messages May 13, 2025 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

v4 cover Fix bluetoothctl --help hanging if daemon isn't running

The changes are still made in a way that there's never a commit where something is broken that wasn't before, hence the function split happening first, before we enable and use pre_run.

Let me know if you want me to rejig this, I think that the end result is fine, but you might have a different opinion about the way we get to that result.

Cheers

Changes from v3:
- dropped glib upgrade
- use pre_run menu hook to setup dbus if needed

Changes from v2:
- rebased against latest upstream

Bastien Nocera (9):
client: Split installing submenu and doing I/O
client: Install submenus before contacting bluez daemon shared/shell: Add function to handle early help calls
client: Fix --help hanging if bluetoothd is not running shared/shell: Add pre_run menu callback
client: Port "admin" menu to pre_run
client: Port "player" menu to pre_run
client: Port "mgmt" menu to pre_run
client: Port "assistant" menu to pre_run

 client/admin.c     | 13 +++++++++++++
 client/assistant.c | 12 +++++++++++-
 client/main.c      | 13 +++++++------
 client/mgmt.c      | 23 +++++++++++++++++------
 client/mgmt.h      |  2 +-
 client/player.c    | 11 ++++++++++-
 src/shared/shell.c | 19 +++++++++++++++++++
 src/shared/shell.h |  4 ++++
 tools/btmgmt.c     |  6 +-----
 9 files changed, 83 insertions(+), 20 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH v4 1/9 client: Split installing submenu and doing I/O

Split off installing the command's submenu and contacting the management socket or the bluez daemon.

---
 client/admin.c     |  3 +++
 client/admin.h     |  1 +
 client/assistant.c |  3 +++
 client/assistant.h |  1 +
 client/main.c      |  4 ++++
 client/mgmt.c      | 11 +++++++----
 client/mgmt.h      |  3 ++-
 client/player.c    |  3 +++
 client/player.h    |  1 +
 tools/btmgmt.c     |  3 ++-
 10 files changed, 27 insertions(+), 6 deletions(-)
client/admin.c +3 -0
index 4d645d9469bb..614a492f1f5f 100644
@@ -193,7 +193,10 @@ static void disconnect_handler(DBusConnection *connection, void *user_data)
 void admin_add_submenu(void)
 {
 	bt_shell_add_submenu(&admin_menu);
+}
 
+void admin_enable_submenu(void)
+{
 	dbus_conn = bt_shell_get_env("DBUS_CONNECTION");
 	if (!dbus_conn || client)
 		return;
client/admin.h +1 -0
index 0047770dc737..08cca585d466 100644
@@ -9,4 +9,5 @@
  */
 
 void admin_add_submenu(void);
+void admin_enable_submenu(void);
 void admin_remove_submenu(void);
client/assistant.c +3 -0
index 16e94664a5c3..555ac6feb048 100644
@@ -395,7 +395,10 @@ static GDBusClient * client;
 void assistant_add_submenu(void)
 {
 	bt_shell_add_submenu(&assistant_menu);
+}
 
+void assistant_enable_submenu(void)
+{
 	dbus_conn = bt_shell_get_env("DBUS_CONNECTION");
 	if (!dbus_conn || client)
 		return;
client/assistant.h +1 -0
index 418b0b84031f..c304abea0515 100644
@@ -9,5 +9,6 @@
  */
 
 void assistant_add_submenu(void);
+void assistant_enable_submenu(void);
 void assistant_remove_submenu(void);
 
client/main.c +4 -0
index a2d9d88bff43..e35e89dd2362 100644
@@ -3420,9 +3420,13 @@ int main(int argc, char *argv[])
 					(void *)endpoint_option);
 
 	admin_add_submenu();
+	admin_enable_submenu();
 	player_add_submenu();
+	player_enable_submenu();
 	mgmt_add_submenu();
+	mgmt_enable_submenu();
 	assistant_add_submenu();
+	assistant_enable_submenu();
 	hci_add_submenu();
 
 	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
client/mgmt.c +7 -4
index faa97a159e3c..6c6d62f4bba1 100644
@@ -6169,7 +6169,13 @@ static void mgmt_debug(const char *str, void *user_data)
 	print("%s%s", prefix, str);
 }
 
-bool mgmt_add_submenu(void)
+void mgmt_add_submenu(void)
+{
+	bt_shell_add_submenu(&mgmt_menu);
+	bt_shell_add_submenu(&monitor_menu);
+}
+
+bool mgmt_enable_submenu(void)
 {
 	mgmt = mgmt_new_default();
 	if (!mgmt) {
@@ -6177,9 +6183,6 @@ bool mgmt_add_submenu(void)
 		return false;
 	}
 
-	bt_shell_add_submenu(&mgmt_menu);
-	bt_shell_add_submenu(&monitor_menu);
-
 	if (getenv("MGMT_DEBUG"))
 		mgmt_set_debug(mgmt, mgmt_debug, "mgmt: ", NULL);
 
client/mgmt.h +2 -1
index 5a2026eab6a2..b0f3cafd0777 100644
@@ -8,6 +8,7 @@
  *
  */
 
-bool mgmt_add_submenu(void);
+void mgmt_add_submenu(void);
+bool mgmt_enable_submenu(void);
 void mgmt_remove_submenu(void);
 void mgmt_set_index(const char *arg);
client/player.c +3 -0
index 647e9bed70e6..7aab4af6d861 100644
@@ -5876,7 +5876,10 @@ void player_add_submenu(void)
 	bt_shell_add_submenu(&player_menu);
 	bt_shell_add_submenu(&endpoint_menu);
 	bt_shell_add_submenu(&transport_menu);
+}
 
+void player_enable_submenu(void)
+{
 	dbus_conn = bt_shell_get_env("DBUS_CONNECTION");
 	if (!dbus_conn || client)
 		return;
client/player.h +1 -0
index e7778cb1efd9..c09ffa94cbff 100644
@@ -9,4 +9,5 @@
  */
 
 void player_add_submenu(void);
+void player_enable_submenu(void);
 void player_remove_submenu(void);
tools/btmgmt.c +2 -1
index 436c2bb21f10..0f6051d5befe 100644
@@ -46,7 +46,8 @@ int main(int argc, char *argv[])
 
 	bt_shell_init(argc, argv, &opt);
 
-	if (!mgmt_add_submenu()) {
+	mgmt_add_submenu();
+	if (!mgmt_enable_submenu()) {
 		fprintf(stderr, "Unable to open mgmt_socket\n");
 		return EXIT_FAILURE;
 	}
Signature · 1 line
2.49.0
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=962345

---Test result---

Test Summary:

CheckPatch                    PENDING   0.29 seconds
GitLint                       PENDING   0.30 seconds
BuildEll                      PASS      20.52 seconds
BluezMake                     PASS      2734.32 seconds
MakeCheck                     PASS      19.90 seconds
MakeDistcheck                 PASS      199.61 seconds
CheckValgrind                 PASS      277.78 seconds
CheckSmatch                   WARNING   305.92 seconds
bluezmakeextell               PASS      129.21 seconds
IncrementalBuild              PENDING   0.33 seconds
ScanBuild                     PASS      913.02 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):src/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:

---
Regards,
Linux Bluetooth

#3 lore raw

PATCH v4 2/9 client: Install submenus before contacting bluez daemon

In reply to Bastien Nocera

So that the submenus are installed even if bluez isn't available.

---
 client/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
client/main.c +5 -5
index e35e89dd2362..9efa92380663 100644
@@ -3403,6 +3403,11 @@ int main(int argc, char *argv[])
 	bt_shell_add_submenu(&advertise_monitor_menu);
 	bt_shell_add_submenu(&scan_menu);
 	bt_shell_add_submenu(&gatt_menu);
+	admin_add_submenu();
+	player_add_submenu();
+	mgmt_add_submenu();
+	assistant_add_submenu();
+	hci_add_submenu();
 	bt_shell_set_prompt(PROMPT_OFF, NULL);
 
 	if (agent_option)
@@ -3419,15 +3424,10 @@ int main(int argc, char *argv[])
 		bt_shell_set_env("AUTO_REGISTER_ENDPOINT",
 					(void *)endpoint_option);
 
-	admin_add_submenu();
 	admin_enable_submenu();
-	player_add_submenu();
 	player_enable_submenu();
-	mgmt_add_submenu();
 	mgmt_enable_submenu();
-	assistant_add_submenu();
 	assistant_enable_submenu();
-	hci_add_submenu();
 
 	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
 
Signature · 1 line
2.49.0
#4 lore raw

PATCH v4 3/9 shared/shell: Add function to handle early help calls

In reply to Bastien Nocera

Add a function that would allow tools to exit after handling --help, so as to avoid the daemon waiting to communicate with a D-Bus service that might not be running.

---
 src/shared/shell.c | 10 ++++++++++
 src/shared/shell.h |  2 ++
 2 files changed, 12 insertions(+)
src/shared/shell.c +10 -0
index 674992065744..4e42bd69b4d7 100644
@@ -1708,3 +1708,13 @@ int bt_shell_get_timeout(void)
 {
 	return data.timeout;
 }
+
+void bt_shell_handle_non_interactive_help(void)
+{
+	if (!data.mode)
+		return;
+	if (data.argv[0] != cmplt)
+		return;
+	print_cmds();
+	exit(EXIT_SUCCESS);
+}
src/shared/shell.h +2 -0
index e431db9f5821..eebbc71faffb 100644
@@ -60,6 +60,8 @@ int bt_shell_exec(const char *input);
 void bt_shell_quit(int status);
 void bt_shell_noninteractive_quit(int status);
 
+void bt_shell_handle_non_interactive_help(void);
+
 bool bt_shell_set_menu(const struct bt_shell_menu *menu);
 
 bool bt_shell_add_submenu(const struct bt_shell_menu *menu);
Signature · 1 line
2.49.0
#5 lore raw

PATCH v4 4/9 client: Fix --help hanging if bluetoothd is not running

In reply to Bastien Nocera

Exit after printing all the main and submenu commands.

---
 client/main.c | 2 ++
 1 file changed, 2 insertions(+)
client/main.c +2 -0
index 9efa92380663..c536a179dc7a 100644
@@ -3410,6 +3410,8 @@ int main(int argc, char *argv[])
 	hci_add_submenu();
 	bt_shell_set_prompt(PROMPT_OFF, NULL);
 
+	bt_shell_handle_non_interactive_help();
+
 	if (agent_option)
 		auto_register_agent = g_strdup(agent_option);
 	else
Signature · 1 line
2.49.0
#6 lore raw

PATCH v4 5/9 shared/shell: Add pre_run menu callback

In reply to Bastien Nocera

This callback will be called every time the menu is called, and can be used to make sure that, for example, a D-Bus connection, is setup for the menu to use.

This means that it is now possible to install a menu without setting up a D-Bus connexion, but still have access to that connexion when the menu is activated.

---
 src/shared/shell.c | 9 +++++++++
 src/shared/shell.h | 2 ++
 2 files changed, 11 insertions(+)
src/shared/shell.c +9 -0
index 4e42bd69b4d7..3e5959fc1868 100644
@@ -1447,6 +1447,15 @@ static void env_destroy(void *data)
 int bt_shell_run(void)
 {
 	int status;
+	const struct queue_entry *submenu;
+
+	for (submenu = queue_get_entries(data.submenus); submenu;
+	     submenu = submenu->next) {
+		struct bt_shell_menu *menu = submenu->data;
+
+		if (menu->pre_run != NULL)
+			menu->pre_run(menu);
+	}
 
 	status = mainloop_run_with_signal(signal_callback, NULL);
 
src/shared/shell.h +2 -0
index eebbc71faffb..297fb69a6fb8 100644
@@ -27,6 +27,7 @@ typedef void (*bt_shell_menu_disp_t) (char **matches, int num_matches,
 							int max_length);
 typedef void (*bt_shell_prompt_input_func) (const char *input, void *user_data);
 typedef bool (*bt_shell_menu_exists_t) (const struct bt_shell_menu *menu);
+typedef void (*bt_shell_menu_pre_run_t) (const struct bt_shell_menu *menu);
 
 struct bt_shell_menu_entry {
 	const char *cmd;
@@ -41,6 +42,7 @@ struct bt_shell_menu_entry {
 struct bt_shell_menu {
 	const char *name;
 	const char *desc;
+	bt_shell_menu_pre_run_t pre_run;
 	const struct bt_shell_menu_entry entries[];
 };
 
Signature · 1 line
2.49.0
#7 lore raw

PATCH v4 6/9 client: Port "admin" menu to pre_run

In reply to Bastien Nocera
---
 client/admin.c | 12 +++++++++++-
 client/admin.h |  1 -
 client/main.c  |  1 -
 3 files changed, 11 insertions(+), 3 deletions(-)
client/admin.c +11 -1
index 614a492f1f5f..6bcbdc026906 100644
@@ -27,6 +27,8 @@ static GList *admin_proxies;
 static GDBusProxy *set_proxy;
 static GDBusProxy *status_proxy;
 
+static void admin_menu_pre_run(const struct bt_shell_menu *menu);
+
 static void admin_policy_set_set_proxy(GDBusProxy *proxy)
 {
 	set_proxy = proxy;
@@ -140,6 +142,7 @@ static void cmd_admin_allow(int argc, char *argv[])
 static const struct bt_shell_menu admin_menu = {
 	.name = "admin",
 	.desc = "Admin Policy Submenu",
+	.pre_run = admin_menu_pre_run,
 	.entries = {
 	{ "allow", "[clear/uuid1 uuid2 ...]", cmd_admin_allow,
 				"Allow service UUIDs and block rest of them"},
@@ -195,8 +198,13 @@ void admin_add_submenu(void)
 	bt_shell_add_submenu(&admin_menu);
 }
 
-void admin_enable_submenu(void)
+static bool pre_run_done = false;
+
+static void admin_menu_pre_run(const struct bt_shell_menu *menu)
 {
+	if (pre_run_done)
+		return;
+
 	dbus_conn = bt_shell_get_env("DBUS_CONNECTION");
 	if (!dbus_conn || client)
 		return;
@@ -205,6 +213,8 @@ void admin_enable_submenu(void)
 	g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
 							NULL, NULL);
 	g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);
+
+	pre_run_done = true;
 }
 
 void admin_remove_submenu(void)
client/admin.h +0 -1
index 08cca585d466..0047770dc737 100644
@@ -9,5 +9,4 @@
  */
 
 void admin_add_submenu(void);
-void admin_enable_submenu(void);
 void admin_remove_submenu(void);
client/main.c +0 -1
index c536a179dc7a..5d32b5218857 100644
@@ -3426,7 +3426,6 @@ int main(int argc, char *argv[])
 		bt_shell_set_env("AUTO_REGISTER_ENDPOINT",
 					(void *)endpoint_option);
 
-	admin_enable_submenu();
 	player_enable_submenu();
 	mgmt_enable_submenu();
 	assistant_enable_submenu();
Signature · 1 line
2.49.0
#8 lore raw

PATCH v4 7/9 client: Port "player" menu to pre_run

In reply to Bastien Nocera
---
 client/main.c   |  1 -
 client/player.c | 10 ++++++++--
 client/player.h |  1 -
 3 files changed, 8 insertions(+), 4 deletions(-)
client/main.c +0 -1
index 5d32b5218857..ce753c1ac4c4 100644
@@ -3426,7 +3426,6 @@ int main(int argc, char *argv[])
 		bt_shell_set_env("AUTO_REGISTER_ENDPOINT",
 					(void *)endpoint_option);
 
-	player_enable_submenu();
 	mgmt_enable_submenu();
 	assistant_enable_submenu();
 
client/player.c +8 -2
index 7aab4af6d861..41bf45bf88d0 100644
@@ -154,6 +154,7 @@ struct transport_select_args {
 	struct queue *selecting;
 };
 
+static void player_menu_pre_run(const struct bt_shell_menu *menu);
 static void transport_set_links(struct transport_select_args *args);
 static void transport_select(struct transport_select_args *args);
 
@@ -5838,6 +5839,7 @@ static void cmd_volume_transport(int argc, char *argv[])
 static const struct bt_shell_menu transport_menu = {
 	.name = "transport",
 	.desc = "Media Transport Submenu",
+	.pre_run = player_menu_pre_run,
 	.entries = {
 	{ "list",         NULL,    cmd_list_transport,
 						"List available transports" },
@@ -5878,10 +5880,12 @@ void player_add_submenu(void)
 	bt_shell_add_submenu(&transport_menu);
 }
 
-void player_enable_submenu(void)
+static bool pre_run_done = false;
+
+static void player_menu_pre_run(const struct bt_shell_menu *menu)
 {
 	dbus_conn = bt_shell_get_env("DBUS_CONNECTION");
-	if (!dbus_conn || client)
+	if (pre_run_done || !dbus_conn || client)
 		return;
 
 	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
@@ -5889,6 +5893,8 @@ void player_enable_submenu(void)
 	g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
 							property_changed, NULL);
 	g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);
+
+	pre_run_done = true;
 }
 
 void player_remove_submenu(void)
client/player.h +0 -1
index c09ffa94cbff..e7778cb1efd9 100644
@@ -9,5 +9,4 @@
  */
 
 void player_add_submenu(void);
-void player_enable_submenu(void);
 void player_remove_submenu(void);
Signature · 1 line
2.49.0
#9 lore raw

PATCH v4 8/9 client: Port "mgmt" menu to pre_run

In reply to Bastien Nocera
---
 client/main.c  |  1 -
 client/mgmt.c  | 14 +++++++++++---
 client/mgmt.h  |  1 -
 tools/btmgmt.c |  5 -----
 4 files changed, 11 insertions(+), 10 deletions(-)
client/main.c +0 -1
index ce753c1ac4c4..06ae25c9d8e9 100644
@@ -3426,7 +3426,6 @@ int main(int argc, char *argv[])
 		bt_shell_set_env("AUTO_REGISTER_ENDPOINT",
 					(void *)endpoint_option);
 
-	mgmt_enable_submenu();
 	assistant_enable_submenu();
 
 	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
client/mgmt.c +11 -3
index 6c6d62f4bba1..eda68b25a3e9 100644
@@ -71,6 +71,8 @@ static int pending_index = 0;
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 #endif
 
+static void mgmt_menu_pre_run(const struct bt_shell_menu *menu);
+
 #define PROMPT_ON	COLOR_BLUE "[mgmt]" COLOR_OFF "> "
 
 static void update_prompt(uint16_t index)
@@ -5998,6 +6000,7 @@ static const struct bt_shell_menu monitor_menu = {
 static const struct bt_shell_menu mgmt_menu = {
 	.name = "mgmt",
 	.desc = "Management Submenu",
+	.pre_run = mgmt_menu_pre_run,
 	.entries = {
 	{ "select",		"<index>",
 		cmd_select,		"Select a different index"	},
@@ -6175,12 +6178,17 @@ void mgmt_add_submenu(void)
 	bt_shell_add_submenu(&monitor_menu);
 }
 
-bool mgmt_enable_submenu(void)
+static bool pre_run_done = false;
+
+static void mgmt_menu_pre_run(const struct bt_shell_menu *menu)
 {
+	if (pre_run_done)
+		return;
+
 	mgmt = mgmt_new_default();
 	if (!mgmt) {
 		fprintf(stderr, "Unable to open mgmt_socket\n");
-		return false;
+		return;
 	}
 
 	if (getenv("MGMT_DEBUG"))
@@ -6188,7 +6196,7 @@ bool mgmt_enable_submenu(void)
 
 	register_mgmt_callbacks(mgmt, mgmt_index);
 
-	return true;
+	pre_run_done = true;
 }
 
 void mgmt_remove_submenu(void)
client/mgmt.h +0 -1
index b0f3cafd0777..6d235fbb1388 100644
@@ -9,6 +9,5 @@
  */
 
 void mgmt_add_submenu(void);
-bool mgmt_enable_submenu(void);
 void mgmt_remove_submenu(void);
 void mgmt_set_index(const char *arg);
tools/btmgmt.c +0 -5
index 0f6051d5befe..0f3de2880014 100644
@@ -47,11 +47,6 @@ int main(int argc, char *argv[])
 	bt_shell_init(argc, argv, &opt);
 
 	mgmt_add_submenu();
-	if (!mgmt_enable_submenu()) {
-		fprintf(stderr, "Unable to open mgmt_socket\n");
-		return EXIT_FAILURE;
-	}
-
 	mgmt_set_index(index_option);
 	bt_shell_attach(fileno(stdin));
 	status = bt_shell_run();
Signature · 1 line
2.49.0
#10 lore raw

PATCH v4 9/9 client: Port "assistant" menu to pre_run

In reply to Bastien Nocera
---
 client/assistant.c | 11 +++++++++--
 client/assistant.h |  1 -
 client/main.c      |  2 --
 3 files changed, 9 insertions(+), 5 deletions(-)
client/assistant.c +9 -2
index 555ac6feb048..6d172a8d8e81 100644
@@ -55,6 +55,8 @@ static DBusConnection *dbus_conn;
 
 static GList *assistants;
 
+static void assistant_menu_pre_run(const struct bt_shell_menu *menu);
+
 static char *proxy_description(GDBusProxy *proxy, const char *title,
 						const char *description)
 {
@@ -384,6 +386,7 @@ fail:
 static const struct bt_shell_menu assistant_menu = {
 	.name = "assistant",
 	.desc = "Media Assistant Submenu",
+	.pre_run = assistant_menu_pre_run,
 	.entries = {
 	{ "push", "<assistant>", cmd_push_assistant,
 					"Send stream information to peer" },
@@ -397,10 +400,12 @@ void assistant_add_submenu(void)
 	bt_shell_add_submenu(&assistant_menu);
 }
 
-void assistant_enable_submenu(void)
+static bool pre_run_done = false;
+
+static void assistant_menu_pre_run(const struct bt_shell_menu *menu)
 {
 	dbus_conn = bt_shell_get_env("DBUS_CONNECTION");
-	if (!dbus_conn || client)
+	if (pre_run_done || !dbus_conn || client)
 		return;
 
 	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
@@ -408,6 +413,8 @@ void assistant_enable_submenu(void)
 	g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
 							property_changed, NULL);
 	g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);
+
+	pre_run_done = true;
 }
 
 void assistant_remove_submenu(void)
client/assistant.h +0 -1
index c304abea0515..418b0b84031f 100644
@@ -9,6 +9,5 @@
  */
 
 void assistant_add_submenu(void);
-void assistant_enable_submenu(void);
 void assistant_remove_submenu(void);
 
client/main.c +0 -2
index 06ae25c9d8e9..36a7446d52c1 100644
@@ -3426,8 +3426,6 @@ int main(int argc, char *argv[])
 		bt_shell_set_env("AUTO_REGISTER_ENDPOINT",
 					(void *)endpoint_option);
 
-	assistant_enable_submenu();
-
 	client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
 
 	g_dbus_client_set_connect_watch(client, connect_handler, NULL);
Signature · 1 line
2.49.0
#11 lore raw

Re: [BlueZ v4 9/9] client: Port "assistant" menu to pre_run

Hi Bastien,

Quoted 29 lines · Bastien Nocera
---
 client/assistant.c | 11 +++++++++--
 client/assistant.h |  1 -
 client/main.c      |  2 --
 3 files changed, 9 insertions(+), 5 deletions(-)
client/assistant.c +3 -0
index 555ac6feb048..6d172a8d8e81 100644
@@ -55,6 +55,8 @@ static DBusConnection *dbus_conn;
 
 static GList *assistants;
 
+static void assistant_menu_pre_run(const struct bt_shell_menu *menu);
+
 static char *proxy_description(GDBusProxy *proxy, const char *title,
                                                const char *description)
 {
@@ -384,6 +386,7 @@ fail:
 static const struct bt_shell_menu assistant_menu = {
        .name = "assistant",
        .desc = "Media Assistant Submenu",
+       .pre_run = assistant_menu_pre_run,
        .entries = {
        { "push", "<assistant>", cmd_push_assistant,
                                        "Send stream information to peer" },

client/assistant.c void assistant_add_submenu(void) · line 403

Quoted 5 lines
client/assistant.c +1 -1
@@ -397,10 +400,12 @@ void assistant_add_submenu(void)
        bt_shell_add_submenu(&assistant_menu);
 }
 
-void assistant_enable_submenu(void)
+static bool pre_run_done = false;

Is the flag above really required though, I mean the bt_shell_run shall only be run once and even if that is no the case the shell itself could be doing the checking if the submenu.pre_run has been called, anyway if that is required Id say we do this in a separate patch, just let me know since I can drop the use of pre_run_done flag while applying these changes.

Quoted 45 lines
client/assistant.c +4 -1
+static void assistant_menu_pre_run(const struct bt_shell_menu *menu)
 {
        dbus_conn = bt_shell_get_env("DBUS_CONNECTION");
-       if (!dbus_conn || client)
+       if (pre_run_done || !dbus_conn || client)
                return;
 
        client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
@@ -408,6 +413,8 @@ void assistant_enable_submenu(void)
        g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
                                                        property_changed, NULL);
        g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);
+
+       pre_run_done = true;
 }
 
 void assistant_remove_submenu(void)
client/assistant.h +0 -1
index c304abea0515..418b0b84031f 100644
@@ -9,6 +9,5 @@
  */
 
 void assistant_add_submenu(void);
-void assistant_enable_submenu(void);
 void assistant_remove_submenu(void);
 
client/main.c +0 -3
index 06ae25c9d8e9..36a7446d52c1 100644
@@ -3426,8 +3426,6 @@ int main(int argc, char *argv[])
                bt_shell_set_env("AUTO_REGISTER_ENDPOINT",
                                        (void *)endpoint_option);
 
-       assistant_enable_submenu();
-
        client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez");
 
        g_dbus_client_set_connect_watch(client, connect_handler, NULL);
--

2.49.0

Signature · 1 line
Luiz Augusto von Dentz
#12 lore raw

Re: [BlueZ v4 9/9] client: Port "assistant" menu to pre_run

Quoted 6 lines · Luiz Augusto von Dentz

Is the flag above really required though, I mean the bt_shell_run shall only be run once and even if that is no the case the shell itself could be doing the checking if the submenu.pre_run has been called, anyway if that is required Id say we do this in a separate patch, just let me know since I can drop the use of pre_run_done flag while applying these changes.

You're right, you can drop it. I don't know why, I thought that bt_shell_run() was being run for every user-provided command when run.

That's the problem with coming back to work on patches months after another iteration...

Feel free to remove the pre_run_done checks before merging

Thanks for the quick review!

#13 lore raw
In reply to Bastien Nocera
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 9 lines · On Tue, 13 May 2025 11:38:10 +0200 you wrote:

The changes are still made in a way that there's never a commit where something is broken that wasn't before, hence the function split happening first, before we enable and use pre_run.

Let me know if you want me to rejig this, I think that the end result is fine, but you might have a different opinion about the way we get to that result.

[...]

Here is the summary with links:
- [BlueZ,v4,1/9] client: Split installing submenu and doing I/O

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=b36c39102e02
  - [BlueZ,v4,2/9] client: Install submenus before contacting bluez daemon
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c0ed04ab07b8
  - [BlueZ,v4,3/9] shared/shell: Add function to handle early help calls
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=80c810ec9e72
  - [BlueZ,v4,4/9] client: Fix --help hanging if bluetoothd is not running
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=773cce6b378d
  - [BlueZ,v4,5/9] shared/shell: Add pre_run menu callback
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=102b9f3d075b

- [BlueZ,v4,6/9] client: Port "admin" menu to pre_run (no matching commit)
- [BlueZ,v4,7/9] client: Port "player" menu to pre_run (no matching commit)
- [BlueZ,v4,8/9] client: Port "mgmt" menu to pre_run (no matching commit)
- [BlueZ,v4,9/9] client: Port "assistant" menu to pre_run (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html