From fcbea6f3658d979622aad1a7f1311aaf0f7abd53 Mon Sep 17 00:00:00 2001 From: Iulia Tanasescu Date: Thu, 7 Mar 2024 17:58:49 +0200 Subject: [PATCH] shared/shell: Add fixes for the init script scenario This adds some fixes to the scenario when the shell is run with the -i/--init-script command line option. In bt_shell_dequeue_exec, if a prompt was released with the current line, all other prompts, if any left, should also try to be released. If no other prompts are available, the next line should be executed on bt_shell_noninteractive_quit. In bt_shell_prompt_input, if data is already available in data.queue, execution should continue and the prompt should be released with the input. --- src/shared/shell.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/shared/shell.c b/src/shared/shell.c index 7bcfcff3e..0e4cbb7b1 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -638,7 +638,15 @@ static void bt_shell_dequeue_exec(void) bt_shell_printf("%s\n", data.line); if (!bt_shell_release_prompt(data.line)) { - bt_shell_dequeue_exec(); + /* If a prompt was released with this line, + * try to release all the other prompts, + * if any are left. Otherwise, the next + * line will be executed on + * bt_shell_noninteractive_quit. + */ + if (data.saved_prompt) + bt_shell_dequeue_exec(); + return; } @@ -693,6 +701,13 @@ void bt_shell_prompt_input(const char *label, const char *msg, prompt_input(str, func, user_data); free(str); + + if (data.line && !queue_isempty(data.queue)) + /* If a prompt was set to receive input and + * data is already available, try to execute + * the line and release the prompt. + */ + bt_shell_dequeue_exec(); } static void prompt_free(void *data) -- 2.47.3