Fix bluetoothctl --help hanging if daemon isn't running
v2 cover Fix bluetoothctl --help hanging if daemon isn't running
v2, this one can print all the submenus without requiring bluetoothd to be running.
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 v2 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 an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
----- Output -----
error: patch failed: client/main.c:3187
error: client/main.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Please resolve the issue and submit the patches again.
---
Regards,
Linux Bluetooth
Quoted 9 lines · On Tue, 2024-10-22 at 05:31 -0700, [email protected] wrote:
This is an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
Quoted 7 lines
----- Output -----
error: patch failed:
client/main.c:3187
error:client/main.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patchPlease resolve the issue and submit the patches again.
Which patch is that for? The error message doesn't say.
Quoted 6 lines
---
Regards,
Linux Bluetooth
Quoted 12 lines · Bastien Nocera
Quoted 11 lines · On Tue, 2024-10-22 at 05:31 -0700, [email protected] wrote:
This is an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.----- Output -----
Quoted 7 lines
Quoted 5 lines
error: patch failed:
client/main.c:3187
error:client/main.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patchPlease resolve the issue and submit the patches again.
Which patch is that for? The error message doesn't say.
Figured it out. Happy to send a patch to the bot if somebody tells me where its code lives.
PATCH v2 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
Luiz Augusto von Dentz
maintainerRe: [BlueZ v2 2/7] client: Use g_clear_pointer() to clean up menus
Hi Bastien,
Quoted 22 lines · Bastien Nocera
This 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 +1
-1@@ -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) {
client/admin.c void admin_add_submenu(void) · line 218
Quoted 6 lines
client/admin.c +1
-2@@ -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);
Don't think it is worth bumping the glib dependency just to add a NULL pointer check, in fact g_dbus_client_unref should be safe to be called with NULL pointers so I wonder if this is a false positive.
Quoted 48 lines
client/admin.c +0
-0}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
-3@@ -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); } --2.47.0
Signature · 1 line
Luiz Augusto von Dentz
Re: [BlueZ v2 2/7] client: Use g_clear_pointer() to clean up menus
Quoted 29 lines · Luiz Augusto von Dentz
Hi Bastien,
Quoted 25 lines · Bastien Nocera
This 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 +1
-1@@ -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)
{client/admin.c +0
-0@@ -215,6 +215,5 @@ void admin_add_submenu(void)
Quoted 11 lines
client/admin.c void admin_add_submenu(void) · line 218
Quoted 5 lines
client/admin.c +1
-2void admin_remove_submenu(void) { - g_dbus_client_unref(client); - client = NULL; + g_clear_pointer(&client, g_dbus_client_unref);Don't think it is worth bumping the glib dependency just to add a NULL
pointer check, in factg_dbus_client_unrefshould be safe to be called
with NULL pointers so I wonder if this is a false positive.
You're right, it's not the GLib gdbus. Feel free to skip this and the preceding patch then. It should rebase cleanly, but I can send a v4 if needed.
Quoted 53 lines
Quoted 51 lines
client/admin.c +0
-0}client/assistant.c +1
-1@@ -390,7 +390,7 @@ static const struct bt_shell_menu assistant_menu = { {} }, }; -static GDBusClient * client; +static GDBusClient * client =NULL ; void assistant_add_submenu(void){
client/assistant.c +1
-2@@ -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 +1
-1@@ -5694,7 +5694,7 @@ static const struct bt_shell_menu transport_menu = { {} }, }; -static GDBusClient *client; +static GDBusClient *client =NULL ; void player_add_submenu(void){
client/player.c +1
-2@@ -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); } --2.47.0
PATCH v2 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
@@ -6028,7 +6028,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) {
@@ -6036,9 +6042,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 v2 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 );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 v2 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 v2 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
@@ -1694,3 +1694,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 v2 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 ); +bt_shell_handle_non_interactive_help (); +if (agent_option) auto_register_agent =g_strdup (agent_option);else
Signature · 1 line
2.47.0