From 04a23330e4a2085ee91980c223c5e4f089ebbe97 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 4 Apr 2018 14:58:01 +0200 Subject: Merge preprocessing of command lines - Common function for splitting string into argument vector - Preprocess & split command lines while parsing the service file - Specify "before" and "after" dependencies in a single line Signed-off-by: David Oberhollenzer --- initd/runlst.c | 53 ++++++++++------------------------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) (limited to 'initd/runlst.c') diff --git a/initd/runlst.c b/initd/runlst.c index ee8c5c5..49b7def 100644 --- a/initd/runlst.c +++ b/initd/runlst.c @@ -29,42 +29,10 @@ extern char **environ; -static NORETURN void split_and_exec(char *cmd) +static NORETURN void split_and_exec(exec_t *cmd) { - char *argv[128]; - size_t i = 0; - - while (*cmd != '\0') { - argv[i++] = cmd; /* FIXME: buffer overflow!! */ - - if (*cmd == '"') { - while (*cmd != '\0' && *cmd != '"') { - if (cmd[0] == '\\' && cmd[1] != '\0') - ++cmd; - - ++cmd; - } - - if (*cmd == '"') - *(cmd++) = '\0'; - - unescape(argv[i - 1]); - } else { - while (*cmd != '\0' && *cmd != ' ') - ++cmd; - - if (*cmd == ' ') - *(cmd++) = '\0'; - } - - while (*cmd == ' ') - ++cmd; - } - - argv[i] = NULL; - - execve(argv[0], argv, environ); - perror(argv[0]); + execve(cmd->argv[0], cmd->argv, environ); + perror(cmd->argv[0]); exit(EXIT_FAILURE); } @@ -98,19 +66,18 @@ static int child_setup(const char *ctty) return 0; } -int runlst_wait(char **exec, size_t num, const char *ctty) +int runlst_wait(exec_t *list, const char *ctty) { pid_t ret, pid; int status; - size_t i; - for (i = 0; i < num; ++i) { + for (; list != NULL; list = list->next) { pid = fork(); if (pid == 0) { if (child_setup(ctty)) exit(EXIT_FAILURE); - split_and_exec(exec[i]); + split_and_exec(list); } if (pid == -1) { @@ -132,7 +99,7 @@ int runlst_wait(char **exec, size_t num, const char *ctty) return EXIT_SUCCESS; } -pid_t runlst(char **exec, size_t num, const char *ctty) +pid_t runlst(exec_t *list, const char *ctty) { int status; pid_t pid; @@ -143,11 +110,11 @@ pid_t runlst(char **exec, size_t num, const char *ctty) if (child_setup(ctty)) exit(EXIT_FAILURE); - if (num > 1) { - status = runlst_wait(exec, num, NULL); + if (list->next != NULL) { + status = runlst_wait(list, NULL); exit(status); } else { - split_and_exec(exec[0]); + split_and_exec(list); } } -- cgit v1.2.3