Skip to content

Commit

Permalink
Support args to sysv-like scripts, e.g. bridge-stp br0 start
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
  • Loading branch information
troglobit committed Apr 25, 2022
1 parent bc4e7a8 commit 09f46f6
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static int service_start(svc_t *svc)
}

if (svc_is_sysv(svc))
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s start' ...", svc->cmd);
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s [..] start' ...", svc->cmd);

if (!svc->desc[0])
do_progress = 0;
Expand Down Expand Up @@ -569,8 +569,16 @@ static int service_start(svc_t *svc)
}
wordfree(&we);
} else {
size_t j;

i = 0;
args[i++] = svc->cmd;
/* this handles, e.g., bridge-stop br0 start */
for (j = 0; j < MAX_NUM_SVC_ARGS; j++) {
if (!strlen(svc->args[j]))
break;
args[i++] = svc->args[j];
}
args[i++] = "start";
}
args[i] = NULL;
Expand Down Expand Up @@ -736,7 +744,7 @@ static int service_stop(svc_t *svc)
logit(LOG_CONSOLE | LOG_NOTICE, "Stopping %s[%d], sending %s ...",
svc_ident(svc, NULL, 0), svc->pid, sig_name(svc->sighalt));
} else {
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s stop' ...", svc->cmd);
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s [..] stop' ...", svc->cmd);
}

/*
Expand Down Expand Up @@ -776,15 +784,26 @@ static int service_stop(svc_t *svc)
svc_set_state(svc, SVC_HALTED_STATE);
}
} else {
char *args[] = { svc->cmd, "stop", NULL };
char *args[MAX_NUM_SVC_ARGS + 1];
size_t i = 0, j;
pid_t pid;

args[i++] = svc->cmd;
/* this handles, e.g., bridge-stop br0 stop */
for (j = 0; j < MAX_NUM_SVC_ARGS; j++) {
if (!strlen(svc->args[j]))
break;
args[i++] = svc->args[j];
}
args[i++] = "stop";
args[i] = NULL;

pid = fork();
switch (pid) {
case 0:
setsid();
redirect(svc);
exec_runtask(svc->cmd, args);
exec_runtask(args[0], &args[1]);
_exit(0);
break;
case -1:
Expand Down

0 comments on commit 09f46f6

Please sign in to comment.