aboutsummaryrefslogtreecommitdiff
path: root/initd/runlst.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-04-04 14:58:01 +0200
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-04-04 14:58:01 +0200
commit04a23330e4a2085ee91980c223c5e4f089ebbe97 (patch)
treeda0b02615fb21849a37cf4632c80df1569788dff /initd/runlst.c
parentaa1356cb190a3416936b25f75ecaaa8684c6fcde (diff)
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 <david.oberhollenzer@tele2.at>
Diffstat (limited to 'initd/runlst.c')
-rw-r--r--initd/runlst.c53
1 files changed, 10 insertions, 43 deletions
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);
}
}