mirror of
https://github.com/troglobit/finit.git
synced 2026-11-02 13:20:32 +00:00
Run service stop: and reload: scripts as non-blocking processes
A reload: script, like 'frrinit.sh reload' could potentially take a while to finish, during which Finit would be blocked. This change reuses the service_script_add(), used for ready: scripts, to track these background helpers. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 file changed
+3
-18
+3
-18
@@ -1031,7 +1031,6 @@ static int service_run_script(svc_t *svc, char *script)
|
|||||||
{
|
{
|
||||||
const char *id = svc_ident(svc, NULL, 0);
|
const char *id = svc_ident(svc, NULL, 0);
|
||||||
pid_t pid = service_fork(svc);
|
pid_t pid = service_fork(svc);
|
||||||
int status, rc;
|
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
err(1, "%s: failed forking off script %s", id, script);
|
err(1, "%s: failed forking off script %s", id, script);
|
||||||
@@ -1047,6 +1046,8 @@ static int service_run_script(svc_t *svc, char *script)
|
|||||||
};
|
};
|
||||||
char pidbuf[16];
|
char pidbuf[16];
|
||||||
|
|
||||||
|
redirect(svc);
|
||||||
|
|
||||||
snprintf(pidbuf, sizeof(pidbuf), "%d", svc->pid);
|
snprintf(pidbuf, sizeof(pidbuf), "%d", svc->pid);
|
||||||
setenv("MAINPID", pidbuf, 1);
|
setenv("MAINPID", pidbuf, 1);
|
||||||
|
|
||||||
@@ -1056,23 +1057,7 @@ static int service_run_script(svc_t *svc, char *script)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbg("%s: script '%s' started as PID %d", id, script, pid);
|
dbg("%s: script '%s' started as PID %d", id, script, pid);
|
||||||
if (waitpid(pid, &status, 0) == -1) {
|
return service_script_add(svc, pid, svc->killdelay);
|
||||||
warn("%s: failed calling script %s", id, script);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = WEXITSTATUS(status);
|
|
||||||
if (WIFEXITED(status)) {
|
|
||||||
dbg("%s: script '%s' exited without signal, status: %d", id, script, rc);
|
|
||||||
} else if (WIFSIGNALED(status)) {
|
|
||||||
dbg("%s: script '%s' terminated by signal %d", id, script, WTERMSIG(status));
|
|
||||||
if (!rc)
|
|
||||||
rc = 1;
|
|
||||||
} else {
|
|
||||||
dbg("%s: script '%s' exited with status: %d", id, script, rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure we don't have any notify socket lingering */
|
/* Ensure we don't have any notify socket lingering */
|
||||||
|
|||||||
Reference in new issue
Block a user