summaryrefslogtreecommitdiff
path: root/initd
diff options
context:
space:
mode:
Diffstat (limited to 'initd')
-rw-r--r--initd/init.h4
-rw-r--r--initd/main.c9
-rw-r--r--initd/runlst.c53
3 files changed, 16 insertions, 50 deletions
diff --git a/initd/init.h b/initd/init.h
index cbe22aa..c8d16ba 100644
--- a/initd/init.h
+++ b/initd/init.h
@@ -48,7 +48,7 @@ enum {
does not exit with EXIT_SUCCESS, processing of the list is aborted
and the function returns the exit status of the failed process.
*/
-int runlst_wait(char **exec, size_t num, const char *ctty);
+int runlst_wait(exec_t *list, const char *ctty);
/*
Does basically the same as runlst_wait, but asynchronously.
@@ -60,7 +60,7 @@ int runlst_wait(char **exec, size_t num, const char *ctty);
Alternatively, if num is 1, the child process directly exec()s the
given command.
*/
-pid_t runlst(char **exec, size_t num, const char *ctty);
+pid_t runlst(exec_t *list, const char *ctty);
/********** setup_tty.c **********/
diff --git a/initd/main.c b/initd/main.c
index 9ce23c0..5f85641 100644
--- a/initd/main.c
+++ b/initd/main.c
@@ -53,7 +53,7 @@ static void handle_exited(service_t *svc)
}
}
- svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty);
+ svc->pid = runlst(svc->exec, svc->ctty);
if (svc->pid == -1) {
print_status(svc->desc, STATUS_FAIL, false);
delsvc(svc);
@@ -115,7 +115,7 @@ static void start_runlevel(int level)
svc = cfg.targets[level];
cfg.targets[level] = svc->next;
- if (!svc->num_exec) {
+ if (svc->exec == NULL) {
print_status(svc->desc, STATUS_OK, false);
delsvc(svc);
continue;
@@ -124,8 +124,7 @@ static void start_runlevel(int level)
if (svc->type == SVC_WAIT) {
print_status(svc->desc, STATUS_WAIT, false);
- status = runlst_wait(svc->exec, svc->num_exec,
- svc->ctty);
+ status = runlst_wait(svc->exec, svc->ctty);
print_status(svc->desc,
status == EXIT_SUCCESS ?
@@ -136,7 +135,7 @@ static void start_runlevel(int level)
if (svc->type == SVC_RESPAWN)
print_status(svc->desc, STATUS_STARTED, false);
- svc->pid = runlst(svc->exec, svc->num_exec, svc->ctty);
+ svc->pid = runlst(svc->exec, svc->ctty);
if (svc->pid == -1) {
print_status(svc->desc, STATUS_FAIL, false);
delsvc(svc);
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);
}
}