public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v1] shared/shell: Allow script command to be used within scripts
@ 2024-09-25 18:27 Luiz Augusto von Dentz
  2024-09-25 20:10 ` [BlueZ,v1] " bluez.test.bot
  2024-09-26 19:20 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2024-09-25 18:27 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This makes script command to allow the usage of script within the
script file by saving existing execute queue and then replacing the
line with script command with the lines of the input file.
---
 src/shared/shell.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index c31487190d0f..2100434f6b15 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -291,15 +291,14 @@ static int bt_shell_queue_exec(char *line)
 	return err;
 }
 
-static bool input_read(struct io *io, void *user_data)
+static bool bt_shell_input_line(struct input *input)
 {
-	struct input *input = user_data;
 	int fd;
 	char *line = NULL;
 	size_t len = 0;
 	ssize_t nread;
 
-	fd = io_get_fd(io);
+	fd = io_get_fd(input->io);
 
 	if (fd < 0) {
 		printf("io_get_fd() returned %d\n", fd);
@@ -336,7 +335,12 @@ static bool input_read(struct io *io, void *user_data)
 
 	free(line);
 
-	return true;
+	return input->f ? true : false;
+}
+
+static bool input_read(struct io *io, void *user_data)
+{
+	return bt_shell_input_line(user_data);
 }
 
 static bool input_hup(struct io *io, void *user_data)
@@ -371,13 +375,25 @@ static struct input *input_new(int fd)
 static bool bt_shell_input_attach(int fd)
 {
 	struct input *input;
+	struct queue *queue;
 
 	input = input_new(fd);
 	if (!input)
 		return false;
 
-	io_set_read_handler(input->io, input_read, input, NULL);
-	io_set_disconnect_handler(input->io, input_hup, input, NULL);
+	/* Save executing queue so input lines can be placed in the correct
+	 * order.
+	 */
+	queue = data.queue;
+	data.queue = queue_new();
+
+	while (bt_shell_input_line(input));
+
+	/* Push existing input lines back into the executing queue */
+	while (!queue_isempty(queue))
+		queue_push_tail(data.queue, queue_pop_head(queue));
+
+	queue_destroy(queue, free);
 
 	return true;
 }
@@ -396,7 +412,10 @@ static void cmd_script(int argc, char *argv[])
 
 	printf("Running script %s...\n", argv[1]);
 
-	bt_shell_input_attach(fd);
+	if (!bt_shell_input_attach(fd))
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
 static const struct bt_shell_menu_entry default_menu[] = {
-- 
2.46.0


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

* RE: [BlueZ,v1] shared/shell: Allow script command to be used within scripts
  2024-09-25 18:27 [PATCH BlueZ v1] shared/shell: Allow script command to be used within scripts Luiz Augusto von Dentz
@ 2024-09-25 20:10 ` bluez.test.bot
  2024-09-26 19:20 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2024-09-25 20:10 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 2231 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=892874

---Test result---

Test Summary:
CheckPatch                    FAIL      0.70 seconds
GitLint                       PASS      0.33 seconds
BuildEll                      PASS      24.50 seconds
BluezMake                     PASS      1661.18 seconds
MakeCheck                     PASS      12.87 seconds
MakeDistcheck                 PASS      179.47 seconds
CheckValgrind                 PASS      252.10 seconds
CheckSmatch                   WARNING   355.16 seconds
bluezmakeextell               PASS      118.97 seconds
IncrementalBuild              PASS      1505.57 seconds
ScanBuild                     PASS      1041.24 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v1] shared/shell: Allow script command to be used within scripts
ERROR:TRAILING_STATEMENTS: trailing statements should be on next line
#153: FILE: src/shared/shell.c:390:
+	while (bt_shell_input_line(input));

/github/workspace/src/src/13812385.patch total: 1 errors, 0 warnings, 68 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/src/13812385.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
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):


---
Regards,
Linux Bluetooth


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

* Re: [PATCH BlueZ v1] shared/shell: Allow script command to be used within scripts
  2024-09-25 18:27 [PATCH BlueZ v1] shared/shell: Allow script command to be used within scripts Luiz Augusto von Dentz
  2024-09-25 20:10 ` [BlueZ,v1] " bluez.test.bot
@ 2024-09-26 19:20 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2024-09-26 19:20 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 Wed, 25 Sep 2024 14:27:30 -0400 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> This makes script command to allow the usage of script within the
> script file by saving existing execute queue and then replacing the
> line with script command with the lines of the input file.
> ---
>  src/shared/shell.c | 33 ++++++++++++++++++++++++++-------
>  1 file changed, 26 insertions(+), 7 deletions(-)

Here is the summary with links:
  - [BlueZ,v1] shared/shell: Allow script command to be used within scripts
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=9a9dc3d456c0

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:[~2024-09-26 19:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-25 18:27 [PATCH BlueZ v1] shared/shell: Allow script command to be used within scripts Luiz Augusto von Dentz
2024-09-25 20:10 ` [BlueZ,v1] " bluez.test.bot
2024-09-26 19:20 ` [PATCH BlueZ v1] " 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