From 2d2bc715025caac8530982190fc4336fdfb6a50c Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 13 May 2025 11:38:18 +0200 Subject: [PATCH] client: Port "mgmt" menu to pre_run --- client/main.c | 1 - client/mgmt.c | 9 +++++---- client/mgmt.h | 1 - tools/btmgmt.c | 5 ----- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/client/main.c b/client/main.c index ce753c1ac..06ae25c9d 100644 --- a/client/main.c +++ b/client/main.c @@ -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"); diff --git a/client/mgmt.c b/client/mgmt.c index 6c6d62f4b..0a9cc589f 100644 --- a/client/mgmt.c +++ b/client/mgmt.c @@ -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", "", cmd_select, "Select a different index" }, @@ -6175,20 +6178,18 @@ void mgmt_add_submenu(void) bt_shell_add_submenu(&monitor_menu); } -bool mgmt_enable_submenu(void) +static void mgmt_menu_pre_run(const struct bt_shell_menu *menu) { mgmt = mgmt_new_default(); if (!mgmt) { fprintf(stderr, "Unable to open mgmt_socket\n"); - return false; + return; } if (getenv("MGMT_DEBUG")) mgmt_set_debug(mgmt, mgmt_debug, "mgmt: ", NULL); register_mgmt_callbacks(mgmt, mgmt_index); - - return true; } void mgmt_remove_submenu(void) diff --git a/client/mgmt.h b/client/mgmt.h index b0f3cafd0..6d235fbb1 100644 --- a/client/mgmt.h +++ b/client/mgmt.h @@ -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); diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 0f6051d5b..0f3de2880 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -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(); -- 2.47.3