public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/shell: Fix bt_shell_printf in non-interactive mode
@ 2026-02-17 22:29 Lars Christensen
  2026-02-17 23:24 ` [BlueZ] " bluez.test.bot
  2026-02-18 13:30 ` Arkadiusz Bokowy
  0 siblings, 2 replies; 4+ messages in thread
From: Lars Christensen @ 2026-02-17 22:29 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lars Christensen

Commit e73bf582d ("shared/shell: Don't init input for
non-interactive shells") stopped creating input objects for
non-interactive shells to avoid reading from stdin. However, this
caused bt_shell_printf to stop working because it checks if the
inputs queue is empty and returns early without printing anything.

Fix this by moving the empty inputs check to after the
non-interactive mode check, so that non-interactive mode can print
using vprintf even when no inputs are registered.

This fixes command-line invocations like 'bluetoothctl devices
Paired' which would execute but produce no output.

Fixes: https://github.com/bluez/bluez/issues/1896
---
 src/shared/shell.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index f014d8f7c..61b003819 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -711,9 +711,6 @@ void bt_shell_printf(const char *fmt, ...)
 	char *saved_line;
 	int saved_point;
 
-	if (queue_isempty(data.inputs))
-		return;
-
 	if (data.mode == MODE_NON_INTERACTIVE) {
 		va_start(args, fmt);
 		vprintf(fmt, args);
@@ -721,6 +718,9 @@ void bt_shell_printf(const char *fmt, ...)
 		return;
 	}
 
+	if (queue_isempty(data.inputs))
+		return;
+
 	save_input = !RL_ISSTATE(RL_STATE_DONE);
 
 	if (save_input) {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [BlueZ] shared/shell: Fix bt_shell_printf in non-interactive mode
  2026-02-17 22:29 [PATCH BlueZ] shared/shell: Fix bt_shell_printf in non-interactive mode Lars Christensen
@ 2026-02-17 23:24 ` bluez.test.bot
  2026-02-18 13:30 ` Arkadiusz Bokowy
  1 sibling, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2026-02-17 23:24 UTC (permalink / raw)
  To: linux-bluetooth, larsch

[-- Attachment #1: Type: text/plain, Size: 1622 bytes --]

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=1055023

---Test result---

Test Summary:
CheckPatch                    PENDING   0.34 seconds
GitLint                       PENDING   0.43 seconds
BuildEll                      PASS      21.31 seconds
BluezMake                     PASS      657.91 seconds
MakeCheck                     PASS      18.63 seconds
MakeDistcheck                 PASS      247.63 seconds
CheckValgrind                 PASS      303.17 seconds
CheckSmatch                   WARNING   367.42 seconds
bluezmakeextell               PASS      185.72 seconds
IncrementalBuild              PENDING   0.38 seconds
ScanBuild                     PASS      1038.52 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
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):
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [BlueZ] shared/shell: Fix bt_shell_printf in non-interactive mode
  2026-02-17 22:29 [PATCH BlueZ] shared/shell: Fix bt_shell_printf in non-interactive mode Lars Christensen
  2026-02-17 23:24 ` [BlueZ] " bluez.test.bot
@ 2026-02-18 13:30 ` Arkadiusz Bokowy
  2026-02-18 14:46   ` Luiz Augusto von Dentz
  1 sibling, 1 reply; 4+ messages in thread
From: Arkadiusz Bokowy @ 2026-02-18 13:30 UTC (permalink / raw)
  To: larsch; +Cc: linux-bluetooth

> Fix this by moving the empty inputs check to after the
> non-interactive mode check, so that non-interactive mode can print
> using vprintf even when no inputs are registered.

Such approach fixes the problem with no output in the non-interactive mode,
but does not restore the behavior that was before the e73bf58 commit. It
prints some additional initialization messages:

> $ bluetoothctl list
> [NEW] Controller 8C:68:8B:00:5F:D4 MYHOST [default]
> [NEW] Device D0:16:B4:25:BB:AE HWM20
> Controller 8C:68:8B:00:5F:D4 MYHOST [default]
> No agent is registered

Such output might break some scripts which relied on the output formatting.

Below is a naive approach which fully restores behavior prior to the e73bf58
commit:

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 78d58c513..3f11f696f 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -81,6 +81,7 @@ static struct {
 	bool monitor;
 	int timeout;
 	int init_fd;
+	bool attached;
 	struct queue *inputs;
 
 	char *line;
@@ -712,16 +713,18 @@ void bt_shell_printf(const char *fmt, ...)
 	char *saved_line;
 	int saved_point;
 
-	if (queue_isempty(data.inputs))
-		return;
-
 	if (data.mode == MODE_NON_INTERACTIVE) {
+		if (!data.attached)
+			return;
 		va_start(args, fmt);
 		vprintf(fmt, args);
 		va_end(args);
 		return;
 	}
 
+	if (queue_isempty(data.inputs))
+		return;
+
 	save_input = !RL_ISSTATE(RL_STATE_DONE);
 
 	if (save_input) {
@@ -1660,6 +1663,7 @@ bool bt_shell_attach(int fd)
 				return false;
 		}
 	} else {
+		data.attached = true;
 		if (shell_exec(data.argc, data.argv) < 0) {
 			bt_shell_noninteractive_quit(EXIT_FAILURE);
 			return true;
@@ -1675,6 +1679,7 @@ bool bt_shell_attach(int fd)
 
 bool bt_shell_detach(void)
 {
+	data.attached = false;
 	if (queue_isempty(data.inputs))
 		return false;
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [BlueZ] shared/shell: Fix bt_shell_printf in non-interactive mode
  2026-02-18 13:30 ` Arkadiusz Bokowy
@ 2026-02-18 14:46   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2026-02-18 14:46 UTC (permalink / raw)
  To: Arkadiusz Bokowy; +Cc: larsch, linux-bluetooth

Hi Arkadiusz, Lars,

On Wed, Feb 18, 2026 at 8:32 AM Arkadiusz Bokowy
<arkadiusz.bokowy@gmail.com> wrote:
>
> > Fix this by moving the empty inputs check to after the
> > non-interactive mode check, so that non-interactive mode can print
> > using vprintf even when no inputs are registered.
>
> Such approach fixes the problem with no output in the non-interactive mode,
> but does not restore the behavior that was before the e73bf58 commit. It
> prints some additional initialization messages:
>
> > $ bluetoothctl list
> > [NEW] Controller 8C:68:8B:00:5F:D4 MYHOST [default]
> > [NEW] Device D0:16:B4:25:BB:AE HWM20
> > Controller 8C:68:8B:00:5F:D4 MYHOST [default]
> > No agent is registered
>
> Such output might break some scripts which relied on the output formatting.
>
> Below is a naive approach which fully restores behavior prior to the e73bf58
> commit:
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index 78d58c513..3f11f696f 100644
> --- a/src/shared/shell.c
> +++ b/src/shared/shell.c
> @@ -81,6 +81,7 @@ static struct {
>         bool monitor;
>         int timeout;
>         int init_fd;
> +       bool attached;
>         struct queue *inputs;
>
>         char *line;
> @@ -712,16 +713,18 @@ void bt_shell_printf(const char *fmt, ...)
>         char *saved_line;
>         int saved_point;
>
> -       if (queue_isempty(data.inputs))
> -               return;
> -
>         if (data.mode == MODE_NON_INTERACTIVE) {
> +               if (!data.attached)
> +                       return;
>                 va_start(args, fmt);
>                 vprintf(fmt, args);
>                 va_end(args);
>                 return;
>         }
>
> +       if (queue_isempty(data.inputs))
> +               return;
> +
>         save_input = !RL_ISSTATE(RL_STATE_DONE);
>
>         if (save_input) {
> @@ -1660,6 +1663,7 @@ bool bt_shell_attach(int fd)
>                                 return false;
>                 }
>         } else {
> +               data.attached = true;
>                 if (shell_exec(data.argc, data.argv) < 0) {
>                         bt_shell_noninteractive_quit(EXIT_FAILURE);
>                         return true;
> @@ -1675,6 +1679,7 @@ bool bt_shell_attach(int fd)
>
>  bool bt_shell_detach(void)
>  {
> +       data.attached = false;
>         if (queue_isempty(data.inputs))
>                 return false;
>

This looks better, at first I didn't like the idea of having to track
the attach state but there doesn't seem to be a better option,
otherwise we would have to revert back to all attach to STDIN, so this
way we don't reintroduce the issue mentioned in e73bf582d.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-18 14:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-17 22:29 [PATCH BlueZ] shared/shell: Fix bt_shell_printf in non-interactive mode Lars Christensen
2026-02-17 23:24 ` [BlueZ] " bluez.test.bot
2026-02-18 13:30 ` Arkadiusz Bokowy
2026-02-18 14:46   ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox