From 4253d0de25fb2da5d5d9d5717d3dc113f567569e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 22 Feb 2026 10:47:25 +0100 Subject: [PATCH] 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 --- src/service.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/service.c b/src/service.c index 5c3d9731..17a0249a 100644 --- a/src/service.c +++ b/src/service.c @@ -1031,7 +1031,6 @@ static int service_run_script(svc_t *svc, char *script) { const char *id = svc_ident(svc, NULL, 0); pid_t pid = service_fork(svc); - int status, rc; if (pid < 0) { 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]; + redirect(svc); + snprintf(pidbuf, sizeof(pidbuf), "%d", svc->pid); 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); - if (waitpid(pid, &status, 0) == -1) { - 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; + return service_script_add(svc, pid, svc->killdelay); } /* Ensure we don't have any notify socket lingering */