Fix bluetoothctl --help hanging if daemon isn't running
v3 cover Fix bluetoothctl --help hanging if daemon isn't running
Changes from v2:
- rebased against latest upstream
Bastien Nocera (7):
configure.ac: Update requirement to glib 2.34
client: Use g_clear_pointer() to clean up menus
client: Split installing submenu and doing I/O
client: Install submenus before contacting bluez daemon
shell: Document "mode" variable
shared/shell: Add function to handle early help calls
client: Fix --help hanging if bluetoothd is not running
acinclude.m4 | 4 ++-- client/admin.c | 8 +++++--- client/admin.h | 1 + client/assistant.c | 8 +++++--- client/assistant.h | 1 + client/main.c | 14 ++++++++++---- client/mgmt.c | 11 +++++++---- client/mgmt.h | 3 ++- client/player.c | 7 +++++-- client/player.h | 1 + configure.ac | 2 +- src/shared/shell.c | 12 +++++++++++- src/shared/shell.h | 2 ++ tools/btmgmt.c | 3 ++- 14 files changed, 55 insertions(+), 22 deletions(-)
Signature · 1 line
2.47.0
PATCH v3 1/7 configure.ac: Update requirement to glib 2.34
Update build requirements from 2011's glib 2.28 all the way up to 2012's glib 2.34. This will allow us to use g_clear_pointer().
--- acinclude.m4 | 4 ++-- configure.ac | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
acinclude.m4 +2 -2
@@ -62,8 +62,8 @@ AC_DEFUN([COMPILER_FLAGS], [ with_cflags="$with_cflags -Wswitch-enum" with_cflags="$with_cflags -Wformat -Wformat-security" with_cflags="$with_cflags -DG_DISABLE_DEPRECATED" - with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28" - with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32" + with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_34" + with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_34" fi AC_SUBST([WARNING_CFLAGS], $with_cflags) ])
configure.ac +1 -1
@@ -81,7 +81,7 @@ AC_CHECK_DECLS([basename], [], ]) -PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.28) +PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.34) if (test "${enable_threads}" = "yes"); then AC_DEFINE(NEED_THREADS, 1, [Define if threading support is required])
Signature · 1 line
2.47.0
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=901846
---Test result---
Test Summary:
CheckPatch FAIL 3.54 seconds GitLint PASS 2.41 seconds BuildEll PASS 24.73 seconds BluezMake PASS 1737.88 seconds MakeCheck PASS 13.46 seconds MakeDistcheck PASS 180.52 seconds CheckValgrind PASS 254.65 seconds CheckSmatch WARNING 358.75 seconds bluezmakeextell PASS 121.22 seconds IncrementalBuild PASS 11429.59 seconds ScanBuild PASS 1028.62 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v3,2/7] client: Use g_clear_pointer() to clean up menus ERROR:INITIALISED_STATIC: do not initialise statics to NULL #66: FILE: client/admin.c:194:
+static GDBusClient *client = NULL;
ERROR:SPACING: need consistent spacing around '*' (ctx:WxV) #66: FILE: client/admin.c:194:
+static GDBusClient *client = NULL;
^ERROR:INITIALISED_STATIC: do not initialise statics to NULL #87: FILE: client/assistant.c:393:
+static GDBusClient * client = NULL;
ERROR:POINTER_LOCATION: "foo * bar" should be "foo *bar" #87: FILE: client/assistant.c:393:
+static GDBusClient * client = NULL;
ERROR:INITIALISED_STATIC: do not initialise statics to NULL #109: FILE: client/player.c:5697:
+static GDBusClient *client = NULL;
/github/workspace/src/src/13845731.patch total: 5 errors, 0 warnings, 46 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/src/13845731.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
##############################
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):
---
Regards,
Linux Bluetooth
PATCH v3 2/7 client: Use g_clear_pointer() to clean up menus
In reply to Bastien NoceraThis would avoid warnings should the client be NULL.
--- client/admin.c | 5 ++--- client/assistant.c | 5 ++--- client/player.c | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-)
client/admin.c +2 -3
@@ -191,7 +191,7 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)admin_policy_status_removed (proxy); } -static GDBusClient *client; +static GDBusClient *client =NULL ;static void disconnect_handler (DBusConnection *connection,void *user_data) {
@@ -215,6 +215,5 @@ void admin_add_submenu(void)void admin_remove_submenu (void ) { -g_dbus_client_unref (client); - client =NULL ; +g_clear_pointer (&client, g_dbus_client_unref); }
client/assistant.c +2 -3
@@ -390,7 +390,7 @@ static const struct bt_shell_menu assistant_menu = { {} }, }; -static GDBusClient * client; +static GDBusClient * client =NULL ;void assistant_add_submenu (void ) {
@@ -409,7 +409,6 @@ void assistant_add_submenu(void)void assistant_remove_submenu (void ) { -g_dbus_client_unref (client); - client =NULL ; +g_clear_pointer (&client, g_dbus_client_unref); }
client/player.c +2 -2
@@ -5694,7 +5694,7 @@ static const struct bt_shell_menu transport_menu = { {} }, }; -static GDBusClient *client; +static GDBusClient *client =NULL ;void player_add_submenu (void ) {
@@ -5715,6 +5715,6 @@ void player_add_submenu(void)void player_remove_submenu (void ) { -g_dbus_client_unref (client); +g_clear_pointer (&client, g_dbus_client_unref);queue_destroy (ios, transport_free); }
Signature · 1 line
2.47.0
PATCH v3 3/7 client: Split installing submenu and doing I/O
In reply to Bastien NoceraSplit 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
@@ -202,7 +202,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
@@ -18,4 +18,5 @@*/ void admin_add_submenu (void ); +void admin_enable_submenu (void );void admin_remove_submenu (void );
client/assistant.c +3 -0
@@ -395,7 +395,10 @@ static GDBusClient * client = NULL;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
@@ -9,5 +9,6 @@*/ void assistant_add_submenu (void ); +void assistant_enable_submenu (void );void assistant_remove_submenu (void );
client/main.c +4 -0
@@ -3204,9 +3204,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 (); client =g_dbus_client_new (dbus_conn,"org.bluez" ,"/org/bluez" );
client/mgmt.c +7 -4
@@ -6026,7 +6026,13 @@ static void mgmt_debug(const char *str, void *user_data)"%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) {
@@ -6034,9 +6040,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
@@ -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
@@ -5701,7 +5701,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
@@ -9,4 +9,5 @@*/ void player_add_submenu (void ); +void player_enable_submenu (void );void player_remove_submenu (void );
tools/btmgmt.c +2 -1
@@ -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.47.0
PATCH v3 4/7 client: Install submenus before contacting bluez daemon
In reply to Bastien NoceraSo that the submenus are installed even if bluez isn't available.
--- client/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
client/main.c +4 -4
@@ -3187,6 +3187,10 @@ 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 ();bt_shell_set_prompt (PROMPT_OFF ,NULL );if (agent_option)
@@ -3203,13 +3207,9 @@ 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 (); client =g_dbus_client_new (dbus_conn,"org.bluez" ,"/org/bluez" );
Signature · 1 line
2.47.0
PATCH v3 5/7 shell: Document "mode" variable
In reply to Bastien NoceraIt's unclear what it does, could probably do with being replaced with an enum to make its possible values and meaning clearer.
--- src/shared/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/shared/shell.c +1 -1
@@ -71,7 +71,7 @@ static struct {char history[256 ];int argc;char **argv; -bool mode; +bool mode;/* whether non-interactive */ bool zsh;bool monitor;int timeout;
Signature · 1 line
2.47.0
PATCH v3 6/7 shared/shell: Add function to handle early help calls
In reply to Bastien NoceraAdd 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
@@ -1697,3 +1697,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
@@ -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.47.0
PATCH v3 7/7 client: Fix --help hanging if bluetoothd is not running
In reply to Bastien NoceraExit after printing all the main and submenu commands.
--- client/main.c | 2 ++ 1 file changed, 2 insertions(+)
client/main.c +2 -0
@@ -3193,6 +3193,8 @@ int main(int argc, char *argv[])assistant_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.47.0
Luiz Augusto von Dentz
maintainerRe: [BlueZ v3 7/7] client: Fix --help hanging if bluetoothd is not running
Hi Bastien,
Quoted 20 lines · Bastien Nocera
Exit after printing all the main and submenu commands.
--- client/main.c | 2 ++ 1 file changed, 2 insertions(+)client/main.c +2
-1@@ -3193,6 +3193,8 @@ int main(int argc, char *argv[])assistant_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 --
Quoted 2 lines
2.47.0
Having some thoughts about how to do this is more clean way, perhaps we should do this as part of bt_shell_run and then introduce .run callback to bt_shell_menu so it is called as part of bt_shell_run, under the .run callback the menu can place e.g. DBUS connection setup, etc, but before it reaches that we can check if it just a help pending.
Signature · 1 line
Luiz Augusto von Dentz
Re: [BlueZ v3 7/7] client: Fix --help hanging if bluetoothd is not running
Quoted 18 lines · Luiz Augusto von Dentz
Hi Bastien,
Quoted 14 lines · Bastien Nocera
Exit after printing all the main and submenu commands.
---
client/main.c | 2 ++1 file changed, 2 insertions(+)client/main.c +0
-0@@ -3193,6 +3193,8 @@ int main(int argc, char *argv[]) assistant_add_submenu(); bt_shell_set_prompt(PROMPT_OFF, NULL);
Quoted 16 lines
Quoted 8 lines
client/main.c +2
-0+ bt_shell_handle_non_interactive_help(); + if (agent_option) auto_register_agent = g_strdup(agent_option);else
--
2.47.0Having some thoughts about how to do this is more clean way, perhaps we should do this as part of
bt_shell_runand then introduce .run callback tobt_shell_menuso it is called as part ofbt_shell_run, under the .run callback the menu can place e.g. DBUS connection setup,
etc, but before it reaches that we can check if it just a help pending.
We need to:
1) set the top menu
2) populate the submenus without any D-Bus IO
3) turn off the prompt
4) print the help and exit if that's what was requested
5) setup IO for submenus
6) run the mainloop
I guess I could do 2) with a callback from bt_shell_set_menu() and then do 4) and 5) from a bt_shell_run() callback.
Is that what you expected?
Do you have preferred names for the callback functions?
I think that we can still use the function split from 3/7, did you have a better name for the functions?
Cheers
Luiz Augusto von Dentz
maintainerRe: [BlueZ v3 7/7] client: Fix --help hanging if bluetoothd is not running
Hi Bastien,
Quoted 45 lines · Bastien Nocera
Quoted 18 lines · Luiz Augusto von Dentz
Hi Bastien,
Quoted 14 lines · Bastien Nocera
Exit after printing all the main and submenu commands.
--- client/main.c | 2 ++ 1 file changed, 2 insertions(+)client/main.c +0
-0@@ -3193,6 +3193,8 @@ int main(int argc, char *argv[])assistant_add_submenu ();bt_shell_set_prompt (PROMPT_OFF ,NULL );Quoted 16 lines
Quoted 8 lines
client/main.c +2
-1+bt_shell_handle_non_interactive_help (); +if (agent_option) auto_register_agent =g_strdup (agent_option);else --2.47.0
Having some thoughts about how to do this is more clean way, perhaps we should do this as part of
bt_shell_runand then introduce .run callback tobt_shell_menuso it is called as part ofbt_shell_run, under the .run callback the menu can place e.g. DBUS connection setup,
etc, but before it reaches that we can check if it just a help pending.We need to:
1) set the top menu
2) populate the submenus without any D-Bus IO
3) turn off the prompt
4) print the help and exit if that's what was requested
5) setup IO for submenus
6) run the mainloop
Quoted 2 lines
I guess I could do 2) with a callback from
bt_shell_set_menu()and then do 4) and 5) from abt_shell_run()callback.
Yep.
Quoted 2 lines
Is that what you expected?
Do you have preferred names for the callback functions?
Id call it .run since it should be the result of bt_shell_run
Quoted 2 lines
I think that we can still use the function split from 3/7, did you have a better name for the functions?
Not sure I follow, there will be a split between adding submenus and .run to achieve the 2 stages, or are you talking about some other split?
Quoted 2 lines
Cheers
Signature · 1 line
Luiz Augusto von Dentz
Re: [BlueZ v3 7/7] client: Fix --help hanging if bluetoothd is not running
Quoted 62 lines · Luiz Augusto von Dentz
Hi Bastien,
Quoted 48 lines · Bastien Nocera
Quoted 29 lines · Luiz Augusto von Dentz
Hi Bastien,
Quoted 18 lines · 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@@ -3193,6 +3193,8 @@ int main(int argc, char *argv[]) assistant_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);Quoted 4 lines
else
--
2.47.0Having some thoughts about how to do this is more clean way,
Quoted 8 lines
perhaps
we should do this as part ofbt_shell_runand then introduce .run callback tobt_shell_menuso it is called as part ofbt_shell_run,
under the .run callback the menu can place e.g. DBUS connection setup,
etc, but before it reaches that we can check if it just a help pending.We need to:
1) set the top menu
2) populate the submenus without any D-Bus IO
3) turn off the prompt
4) print the help and exit if that's what was requested
5) setup IO for submenus
6) run the mainloopQuoted 2 lines
I guess I could do 2) with a callback from
bt_shell_set_menu()and then do 4) and 5) from abt_shell_run()callback.Yep.
Quoted 2 lines
Is that what you expected?
Do you have preferred names for the callback functions?Id call it .run since it should be the result of
bt_shell_run
Quoted 7 lines
Quoted 3 lines
I think that we can still use the function split from 3/7, did you have
a better name for the functions?Not sure I follow, there will be a split between adding submenus and .run to achieve the 2 stages, or are you talking about some other split?
We still need to split the functions called in .run between the bits that populate the submenu, and the bits that will make D-Bus I/O, so patch number 3 still needs to be exist.
Is assistant_add_submenu() and assistant_enable_submenu() OK, or did you want a different name?