* [PATCH BlueZ v2] shared/shell: Fix not running pre_run on MODE_NON_INTERACTIVE
@ 2025-07-07 14:23 Luiz Augusto von Dentz
2025-07-07 15:48 ` [BlueZ,v2] " bluez.test.bot
2025-07-08 19:00 ` [PATCH BlueZ v2] " patchwork-bot+bluetooth
0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2025-07-07 14:23 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If a command is given to be run in non-interactive mode the code would
not attempt to execute .pre_run first since some (sub)menus requires that
in order to properly initialize things.
Fixes: https://github.com/bluez/bluez/issues/1394
Fixes: https://github.com/bluez/bluez/issues/1317
---
src/shared/shell.c | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/src/shared/shell.c b/src/shared/shell.c
index ec9e5f7dc984..ea285c72631d 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -423,7 +423,8 @@ static void cmd_script(int argc, char *argv[])
return bt_shell_noninteractive_quit(EXIT_SUCCESS);
}
-static const struct bt_shell_menu_entry default_menu[] = {
+static const struct bt_shell_menu default_menu = {
+ .entries = {
{ "back", NULL, cmd_back, "Return to main menu", NULL,
NULL, cmd_back_exists },
{ "menu", "<name>", cmd_menu, "Select submenu",
@@ -437,7 +438,7 @@ static const struct bt_shell_menu_entry default_menu[] = {
{ "export", NULL, cmd_export,
"Print environment variables" },
{ "script", "<filename>", cmd_script, "Run script" },
- { }
+ {} },
};
static void shell_print_help(void)
@@ -480,7 +481,7 @@ static void shell_print_menu(void)
print_menu(entry->cmd, entry->arg ? : "", entry->desc ? : "");
}
- for (entry = default_menu; entry->cmd; entry++) {
+ for (entry = default_menu.entries; entry->cmd; entry++) {
if (entry->exists && !entry->exists(data.menu))
continue;
@@ -495,7 +496,7 @@ static void shell_print_menu_zsh_complete(void)
for (entry = data.menu->entries; entry->cmd; entry++)
printf("%s:%s\n", entry->cmd, entry->desc ? : "");
- for (entry = default_menu; entry->cmd; entry++) {
+ for (entry = default_menu.entries; entry->cmd; entry++) {
if (entry->exists && !entry->exists(data.menu))
continue;
@@ -627,9 +628,11 @@ fail:
return -EINVAL;
}
-static int menu_exec(const struct bt_shell_menu_entry *entry,
+static int menu_exec(const struct bt_shell_menu *menu,
int argc, char *argv[])
{
+ const struct bt_shell_menu_entry *entry = menu->entries;
+
for (; entry->cmd; entry++) {
if (strcmp(argv[0], entry->cmd))
continue;
@@ -642,6 +645,9 @@ static int menu_exec(const struct bt_shell_menu_entry *entry,
if (data.menu == data.main && !strcmp(entry->cmd, "back"))
continue;
+ if (data.mode == MODE_NON_INTERACTIVE && menu->pre_run)
+ menu->pre_run(menu);
+
return cmd_exec(entry, argc, argv);
}
@@ -673,7 +679,7 @@ static int submenu_exec(int argc, char *argv[])
memmove(argv[0], argv[0] + len + 1, tlen - len - 1);
memset(argv[0] + tlen - len - 1, 0, len + 1);
- return menu_exec(submenu->entries, argc, argv);
+ return menu_exec(submenu, argc, argv);
}
static int shell_exec(int argc, char *argv[])
@@ -686,9 +692,9 @@ static int shell_exec(int argc, char *argv[])
if (!argsisutf8(argc, argv))
return -EINVAL;
- err = menu_exec(default_menu, argc, argv);
+ err = menu_exec(&default_menu, argc, argv);
if (err == -ENOENT) {
- err = menu_exec(data.menu->entries, argc, argv);
+ err = menu_exec(data.menu, argc, argv);
if (err == -ENOENT) {
err = submenu_exec(argc, argv);
if (err == -ENOENT) {
@@ -980,7 +986,7 @@ static char *cmd_generator(const char *text, int state)
}
if (default_menu_enabled) {
- cmd = find_cmd(text, default_menu, &index);
+ cmd = find_cmd(text, default_menu.entries, &index);
if (cmd) {
return cmd;
} else {
@@ -1171,8 +1177,8 @@ static char **shell_completion(const char *text, int start, int end)
if (wordexp(rl_line_buffer, &w, WRDE_NOCMD))
return NULL;
- matches = menu_completion(default_menu, text, w.we_wordc,
- w.we_wordv[0]);
+ matches = menu_completion(default_menu.entries, text,
+ w.we_wordc, w.we_wordv[0]);
if (!matches) {
matches = menu_completion(data.menu->entries, text,
w.we_wordc,
@@ -1449,6 +1455,12 @@ int bt_shell_run(void)
int status;
const struct queue_entry *submenu;
+ /* Check if on non-interactive mode skip pre-run since that is on-demand
+ * by shell_exec() only for the menu in use.
+ */
+ if (data.mode == MODE_NON_INTERACTIVE)
+ goto done;
+
if (data.menu && data.menu->pre_run)
data.menu->pre_run(data.menu);
@@ -1460,6 +1472,7 @@ int bt_shell_run(void)
menu->pre_run(menu);
}
+done:
status = mainloop_run_with_signal(signal_callback, NULL);
bt_shell_cleanup();
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [BlueZ,v2] shared/shell: Fix not running pre_run on MODE_NON_INTERACTIVE
2025-07-07 14:23 [PATCH BlueZ v2] shared/shell: Fix not running pre_run on MODE_NON_INTERACTIVE Luiz Augusto von Dentz
@ 2025-07-07 15:48 ` bluez.test.bot
2025-07-08 19:00 ` [PATCH BlueZ v2] " patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2025-07-07 15:48 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
[-- Attachment #1: Type: text/plain, Size: 1621 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=979707
---Test result---
Test Summary:
CheckPatch PENDING 0.22 seconds
GitLint PENDING 0.29 seconds
BuildEll PASS 20.34 seconds
BluezMake PASS 2584.81 seconds
MakeCheck PASS 20.80 seconds
MakeDistcheck PASS 190.62 seconds
CheckValgrind PASS 243.83 seconds
CheckSmatch WARNING 310.43 seconds
bluezmakeextell PASS 130.31 seconds
IncrementalBuild PENDING 0.28 seconds
ScanBuild PASS 935.85 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] 3+ messages in thread
* Re: [PATCH BlueZ v2] shared/shell: Fix not running pre_run on MODE_NON_INTERACTIVE
2025-07-07 14:23 [PATCH BlueZ v2] shared/shell: Fix not running pre_run on MODE_NON_INTERACTIVE Luiz Augusto von Dentz
2025-07-07 15:48 ` [BlueZ,v2] " bluez.test.bot
@ 2025-07-08 19:00 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2025-07-08 19:00 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hello:
This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Mon, 7 Jul 2025 10:23:50 -0400 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> If a command is given to be run in non-interactive mode the code would
> not attempt to execute .pre_run first since some (sub)menus requires that
> in order to properly initialize things.
>
> Fixes: https://github.com/bluez/bluez/issues/1394
> Fixes: https://github.com/bluez/bluez/issues/1317
>
> [...]
Here is the summary with links:
- [BlueZ,v2] shared/shell: Fix not running pre_run on MODE_NON_INTERACTIVE
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9ed79eedc075
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-08 18:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-07 14:23 [PATCH BlueZ v2] shared/shell: Fix not running pre_run on MODE_NON_INTERACTIVE Luiz Augusto von Dentz
2025-07-07 15:48 ` [BlueZ,v2] " bluez.test.bot
2025-07-08 19:00 ` [PATCH BlueZ v2] " patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox