aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Agner <stefan.agner@toradex.com>2019-02-25 16:16:19 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-01-20 16:13:07 +0000
commite94bd11f6839b619f3f787e8cae2acc7d7887807 (patch)
treecda17c6acbc1b5677ad69e538fdf2f07a981122f
parent568f28ed8dc0cc79a0afc6f1689dc6cb007c285c (diff)
downloadpsplash-e94bd11f6839b619f3f787e8cae2acc7d7887807.tar.gz
process consecutive commands
Process consecutive commands separated by null-termations. Since it is a FIFO, in theory, two commands can be queued from two independent calls to psplash-write. This also makes the command parser more robust. With this code, sequences like this get parsed just fine: echo -e "\nPROGRESS 10\n\0\nQUIT" > /run/psplash_fifo Signed-off-by: Stefan Agner <stefan.agner@toradex.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--psplash.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/psplash.c b/psplash.c
index 169f9c1..b40adf2 100644
--- a/psplash.c
+++ b/psplash.c
@@ -115,11 +115,17 @@ parse_command (PSplashFB *fb, char *string)
if (!strcmp(command,"PROGRESS"))
{
- psplash_draw_progress (fb, atoi(strtok(NULL,"\0")));
+ char *arg = strtok(NULL, "\0");
+
+ if (arg)
+ psplash_draw_progress (fb, atoi(arg));
}
else if (!strcmp(command,"MSG"))
{
- psplash_draw_msg (fb, strtok(NULL,"\0"));
+ char *arg = strtok(NULL, "\0");
+
+ if (arg)
+ psplash_draw_msg (fb, arg);
}
else if (!strcmp(command,"QUIT"))
{
@@ -137,6 +143,7 @@ psplash_main (PSplashFB *fb, int pipe_fd, int timeout)
fd_set descriptors;
struct timeval tv;
char *end;
+ char *cmd;
char command[2048];
tv.tv_sec = timeout;
@@ -172,21 +179,32 @@ psplash_main (PSplashFB *fb, int pipe_fd, int timeout)
pipe_fd = open(PSPLASH_FIFO,O_RDONLY|O_NONBLOCK);
goto out;
}
-
- if (command[length-1] == '\0')
- {
- if (parse_command(fb, command))
- return;
- length = 0;
- }
- else if (command[length-1] == '\n')
- {
- command[length-1] = '\0';
- if (parse_command(fb, command))
- return;
- length = 0;
- }
+ cmd = command;
+ do {
+ int cmdlen;
+ char *cmdend = memchr(cmd, '\n', length);
+
+ /* Replace newlines with string termination */
+ if (cmdend)
+ *cmdend = '\0';
+
+ cmdlen = strnlen(cmd, length);
+
+ /* Skip string terminations */
+ if (!cmdlen && length)
+ {
+ length--;
+ cmd++;
+ continue;
+ }
+
+ if (parse_command(fb, cmd))
+ return;
+
+ length -= cmdlen;
+ cmd += cmdlen;
+ } while (length);
out:
end = &command[length];