@@ -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");
@@ -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)
@@ -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);
@@ -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();