Skip to contentSkip to conversation

shared/shell: Introduce bt_shell_exec

PATCH In review Luiz Augusto von Dentz 2 participants 3 messages Mar 1, 2022 – Mar 2, 2022 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 shared/shell: Introduce bt_shell_exec

From: Luiz Augusto von Dentz <[email protected]>

This introduces bt_shell_exec which can be used to inject commands into a bt_shell without using stdin/user input.

---
 src/shared/shell.c | 34 ++++++++++++++++++++++++----------
 src/shared/shell.h |  1 +
 2 files changed, 25 insertions(+), 10 deletions(-)
src/shared/shell.c +24 -10
index cbb9b8b88..0d82bc282 100644
@@ -678,7 +678,6 @@ int bt_shell_release_prompt(const char *input)
 
 static void rl_handler(char *input)
 {
-	wordexp_t w;
 	HIST_ENTRY *last;
 
 	if (!input) {
@@ -703,16 +702,8 @@ static void rl_handler(char *input)
 	if (data.monitor)
 		bt_log_printf(0xffff, data.name, LOG_INFO, "%s", input);
 
-	if (wordexp(input, &w, WRDE_NOCMD))
-		goto done;
-
-	if (w.we_wordc == 0) {
-		wordfree(&w);
-		goto done;
-	}
+	bt_shell_exec(input);
 
-	shell_exec(w.we_wordc, w.we_wordv);
-	wordfree(&w);
 done:
 	free(input);
 }
@@ -1178,6 +1169,29 @@ int bt_shell_run(void)
 	return status;
 }
 
+int bt_shell_exec(const char *input)
+{
+	wordexp_t w;
+	int err;
+
+	if (!input)
+		return 0;
+
+	if (wordexp(input, &w, WRDE_NOCMD))
+		return -ENOEXEC;
+
+	if (w.we_wordc == 0) {
+		wordfree(&w);
+		return -ENOEXEC;
+	}
+
+	err = shell_exec(w.we_wordc, w.we_wordv);
+
+	wordfree(&w);
+
+	return err;
+}
+
 void bt_shell_cleanup(void)
 {
 	bt_shell_release_prompt("");
src/shared/shell.h +1 -0
index cc4f822fb..8baa2854a 100644
@@ -55,6 +55,7 @@ struct bt_shell_opt {
 void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt);
 
 int bt_shell_run(void);
+int bt_shell_exec(const char *input);
 
 void bt_shell_quit(int status);
 void bt_shell_noninteractive_quit(int status);
Signature · 1 line
2.35.1
#1 lore raw

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

---Test result---

Test Summary:

CheckPatch                    PASS      1.51 seconds
GitLint                       PASS      1.07 seconds
Prep - Setup ELL              PASS      51.80 seconds
Build - Prep                  PASS      0.83 seconds
Build - Configure             PASS      10.43 seconds
Build - Make                  PASS      1500.30 seconds
Make Check                    PASS      12.38 seconds
Make Check w/Valgrind         PASS      533.05 seconds
Make Distcheck                PASS      278.20 seconds
Build w/ext ELL - Configure   PASS      10.45 seconds
Build w/ext ELL - Make        PASS      1473.77 seconds
Incremental Build with patchesPASS      0.00 seconds

---
Regards,
Linux Bluetooth

author maintainer
#2 lore raw

Hi,

Quoted 27 lines · On Tue, Mar 1, 2022 at 4:44 PM <[email protected]> wrote:

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

---Test result---

Test Summary:

CheckPatch                    PASS      1.51 seconds
GitLint                       PASS      1.07 seconds
Prep - Setup ELL              PASS      51.80 seconds
Build - Prep                  PASS      0.83 seconds
Build - Configure             PASS      10.43 seconds
Build - Make                  PASS      1500.30 seconds
Make Check                    PASS      12.38 seconds
Make Check w/Valgrind         PASS      533.05 seconds
Make Distcheck                PASS      278.20 seconds
Build w/ext ELL - Configure   PASS      10.45 seconds
Build w/ext ELL - Make        PASS      1473.77 seconds
Incremental Build with patchesPASS      0.00 seconds
Quoted 4 lines

---
Regards,
Linux Bluetooth

Pushed

Signature · 1 line
Luiz Augusto von Dentz