public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [BlueZ] shell: Clarify "mode" variable
@ 2025-04-30 14:40 Bastien Nocera
  2025-04-30 16:07 ` bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Bastien Nocera @ 2025-04-30 14:40 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bastien Nocera

It's unclear what that variable did, and which value corresponded to
which state, so replace it with a typed enum so that conditionals are
more easily parsed.
---
 src/shared/shell.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 631a07f35625..6ab4acfd0ccf 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -65,13 +65,18 @@ struct input {
 	FILE *f;
 };
 
+typedef enum {
+     MODE_INTERACTIVE     = 0,
+     MODE_NON_INTERACTIVE = 1
+} mode_type_t;
+
 static struct {
 	bool init;
 	char *name;
 	char history[256];
 	int argc;
 	char **argv;
-	bool mode;
+	mode_type_t mode;
 	bool zsh;
 	bool monitor;
 	int timeout;
@@ -708,7 +713,7 @@ void bt_shell_printf(const char *fmt, ...)
 	if (queue_isempty(data.inputs))
 		return;
 
-	if (data.mode) {
+	if (data.mode == MODE_NON_INTERACTIVE) {
 		va_start(args, fmt);
 		vprintf(fmt, args);
 		va_end(args);
@@ -833,7 +838,7 @@ void bt_shell_prompt_input(const char *label, const char *msg,
 {
 	char *str;
 
-	if (!data.init || data.mode)
+	if (!data.init || data.mode == MODE_NON_INTERACTIVE)
 		return;
 
 	if (data.saved_prompt) {
@@ -1192,7 +1197,7 @@ static void signal_callback(int signum, void *user_data)
 
 	switch (signum) {
 	case SIGINT:
-		if (!queue_isempty(data.inputs) && !data.mode) {
+		if (!queue_isempty(data.inputs) && data.mode == MODE_INTERACTIVE) {
 			rl_replace_line("", 0);
 			rl_crlf();
 			rl_on_new_line();
@@ -1210,7 +1215,7 @@ static void signal_callback(int signum, void *user_data)
 		/* fall through */
 	case SIGTERM:
 		if (!terminated) {
-			if (!data.mode) {
+			if (data.mode == MODE_INTERACTIVE) {
 				rl_replace_line("", 0);
 				rl_crlf();
 			}
@@ -1266,7 +1271,7 @@ done:
 
 static void rl_init(void)
 {
-	if (data.mode)
+	if (data.mode == MODE_NON_INTERACTIVE)
 		return;
 
 	/* Allow conditional parsing of the ~/.inputrc file. */
@@ -1346,7 +1351,7 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 			usage(argc, argv, opt);
 			data.argc = 1;
 			data.argv = &cmplt;
-			data.mode = 1;
+			data.mode = MODE_NON_INTERACTIVE;
 			goto done;
 		case 's':
 			if (optarg && data.init_fd < 0) {
@@ -1400,10 +1405,10 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 	data.argc = argc - optind;
 	data.argv = argv + optind;
 	optind = 0;
-	data.mode = (data.argc > 0);
+	data.mode = (data.argc > 0) ? MODE_NON_INTERACTIVE : MODE_INTERACTIVE;
 
 done:
-	if (data.mode)
+	if (data.mode == MODE_NON_INTERACTIVE)
 		bt_shell_set_env("NON_INTERACTIVE", &data.mode);
 
 	mainloop_init();
@@ -1420,7 +1425,7 @@ done:
 
 static void rl_cleanup(void)
 {
-	if (data.mode)
+	if (data.mode == MODE_NON_INTERACTIVE)
 		return;
 
 	if (data.history[0] != '\0')
@@ -1540,7 +1545,7 @@ void bt_shell_quit(int status)
 
 void bt_shell_noninteractive_quit(int status)
 {
-	if (!data.mode || data.timeout) {
+	if (data.mode == MODE_INTERACTIVE || data.timeout) {
 		bt_shell_dequeue_exec();
 		return;
 	}
@@ -1581,7 +1586,7 @@ void bt_shell_set_prompt(const char *string, const char *color)
 {
 	char *prompt;
 
-	if (!data.init || data.mode)
+	if (!data.init || data.mode == MODE_NON_INTERACTIVE)
 		return;
 
 	/* Envelope color within RL_PROMPT_START_IGNORE (\001) and
@@ -1614,12 +1619,12 @@ bool bt_shell_attach(int fd)
 	if (!input)
 		return false;
 
-	if (!data.mode) {
+	if (data.mode == MODE_INTERACTIVE) {
 		io_set_read_handler(input->io, input_read, input, NULL);
 		io_set_disconnect_handler(input->io, input_hup, input, NULL);
 	}
 
-	if (data.mode) {
+	if (data.mode == MODE_NON_INTERACTIVE) {
 		if (shell_exec(data.argc, data.argv) < 0) {
 			bt_shell_noninteractive_quit(EXIT_FAILURE);
 			return true;
-- 
2.49.0


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

* RE: [BlueZ] shell: Clarify "mode" variable
  2025-04-30 14:40 [BlueZ] shell: Clarify "mode" variable Bastien Nocera
@ 2025-04-30 16:07 ` bluez.test.bot
  0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2025-04-30 16:07 UTC (permalink / raw)
  To: linux-bluetooth, hadess

[-- 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=958551

---Test result---

Test Summary:
CheckPatch                    PENDING   0.25 seconds
GitLint                       PENDING   0.22 seconds
BuildEll                      PASS      21.36 seconds
BluezMake                     PASS      2928.53 seconds
MakeCheck                     PASS      20.22 seconds
MakeDistcheck                 PASS      200.83 seconds
CheckValgrind                 PASS      279.43 seconds
CheckSmatch                   WARNING   306.28 seconds
bluezmakeextell               PASS      129.18 seconds
IncrementalBuild              PENDING   0.29 seconds
ScanBuild                     PASS      923.79 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] 2+ messages in thread

end of thread, other threads:[~2025-04-30 16:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 14:40 [BlueZ] shell: Clarify "mode" variable Bastien Nocera
2025-04-30 16:07 ` bluez.test.bot

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