diff options
author | 2019-02-25 16:16:19 +0100 | |
---|---|---|
committer | 2020-01-20 16:13:07 +0000 | |
commit | e94bd11f6839b619f3f787e8cae2acc7d7887807 (patch) | |
tree | cda17c6acbc1b5677ad69e538fdf2f07a981122f | |
parent | 568f28ed8dc0cc79a0afc6f1689dc6cb007c285c (diff) | |
download | psplash-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.c | 50 |
1 files changed, 34 insertions, 16 deletions
@@ -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]; |