diff mbox series

[BlueZ,v3,7/7] client: Fix --help hanging if bluetoothd is not running

Message ID 20241022141118.150143-8-hadess@hadess.net
State Superseded
Headers show
Series Fix bluetoothctl --help hanging if daemon isn't running | expand

Commit Message

Bastien Nocera Oct. 22, 2024, 2:10 p.m. UTC
Exit after printing all the main and submenu commands.
---
 client/main.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Luiz Augusto von Dentz Oct. 24, 2024, 4:08 p.m. UTC | #1
Hi Bastien,

On Tue, Oct 22, 2024 at 10:11 AM Bastien Nocera <hadess@hadess.net> wrote:
>
> Exit after printing all the main and submenu commands.
> ---
>  client/main.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/client/main.c b/client/main.c
> index f60bef1a6d3a..f5ed9f9f5297 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -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
> --
> 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.
Bastien Nocera Oct. 28, 2024, 3:35 p.m. UTC | #2
On Thu, 2024-10-24 at 12:08 -0400, Luiz Augusto von Dentz wrote:
> Hi Bastien,
> 
> On Tue, Oct 22, 2024 at 10:11 AM Bastien Nocera <hadess@hadess.net>
> wrote:
> > 
> > Exit after printing all the main and submenu commands.
> > ---
> >  client/main.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/client/main.c b/client/main.c
> > index f60bef1a6d3a..f5ed9f9f5297 100644
> > --- a/client/main.c
> > +++ b/client/main.c
> > @@ -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
> > --
> > 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.

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 Oct. 28, 2024, 3:54 p.m. UTC | #3
Hi Bastien,

On Mon, Oct 28, 2024 at 11:35 AM Bastien Nocera <hadess@hadess.net> wrote:
>
> On Thu, 2024-10-24 at 12:08 -0400, Luiz Augusto von Dentz wrote:
> > Hi Bastien,
> >
> > On Tue, Oct 22, 2024 at 10:11 AM Bastien Nocera <hadess@hadess.net>
> > wrote:
> > >
> > > Exit after printing all the main and submenu commands.
> > > ---
> > >  client/main.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > >
> > > diff --git a/client/main.c b/client/main.c
> > > index f60bef1a6d3a..f5ed9f9f5297 100644
> > > --- a/client/main.c
> > > +++ b/client/main.c
> > > @@ -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
> > > --
> > > 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.
>
> 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.

Yep.

> 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

> 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?

> Cheers
>
Bastien Nocera Oct. 28, 2024, 9:53 p.m. UTC | #4
On Mon, 2024-10-28 at 11:54 -0400, Luiz Augusto von Dentz wrote:
> Hi Bastien,
> 
> On Mon, Oct 28, 2024 at 11:35 AM Bastien Nocera <hadess@hadess.net>
> wrote:
> > 
> > On Thu, 2024-10-24 at 12:08 -0400, Luiz Augusto von Dentz wrote:
> > > Hi Bastien,
> > > 
> > > On Tue, Oct 22, 2024 at 10:11 AM Bastien Nocera
> > > <hadess@hadess.net>
> > > wrote:
> > > > 
> > > > Exit after printing all the main and submenu commands.
> > > > ---
> > > >  client/main.c | 2 ++
> > > >  1 file changed, 2 insertions(+)
> > > > 
> > > > diff --git a/client/main.c b/client/main.c
> > > > index f60bef1a6d3a..f5ed9f9f5297 100644
> > > > --- a/client/main.c
> > > > +++ b/client/main.c
> > > > @@ -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
> > > > --
> > > > 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.
> > 
> > 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.
> 
> Yep.
> 
> > 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
> 
> > 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?
diff mbox series

Patch

diff --git a/client/main.c b/client/main.c
index f60bef1a6d3a..f5ed9f9f5297 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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