mirror of
https://github.com/troglobit/finit.git
synced 2026-11-07 16:01:08 +00:00
Check return value from kill(pid, SIGHUP), maybe lost pid
This patch handles a corner case when Finit may not have detected a supervised process has died. When a user calls `initctl restart foo` we now send such lost PIDs to the service_monitor() for restart. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
6cdcacf20b
commit
477b50b7a6
1 file changed
+15
-7
+15
-7
@@ -722,6 +722,7 @@ static int service_stop(svc_t *svc)
|
|||||||
static int service_restart(svc_t *svc)
|
static int service_restart(svc_t *svc)
|
||||||
{
|
{
|
||||||
int do_progress = 1;
|
int do_progress = 1;
|
||||||
|
pid_t lost = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Ignore if finit is SIGSTOP'ed */
|
/* Ignore if finit is SIGSTOP'ed */
|
||||||
@@ -748,19 +749,26 @@ static int service_restart(svc_t *svc)
|
|||||||
logit(LOG_CONSOLE | LOG_NOTICE, "Restarting %s[%d], sending SIGHUP ...",
|
logit(LOG_CONSOLE | LOG_NOTICE, "Restarting %s[%d], sending SIGHUP ...",
|
||||||
svc_ident(svc, NULL, 0), svc->pid);
|
svc_ident(svc, NULL, 0), svc->pid);
|
||||||
rc = kill(svc->pid, SIGHUP);
|
rc = kill(svc->pid, SIGHUP);
|
||||||
|
if (rc == -1 && errno == ESRCH) {
|
||||||
|
/* nobody home, reset internal state machine */
|
||||||
|
lost = svc->pid;
|
||||||
|
} else {
|
||||||
|
/* Declare we're waiting for svc to re-assert/touch its pidfile */
|
||||||
|
svc_starting(svc);
|
||||||
|
|
||||||
/* Declare we're waiting for svc to re-assert/touch its pidfile */
|
/* Service does not maintain a PID file on its own */
|
||||||
svc_starting(svc);
|
if (svc_has_pidfile(svc)) {
|
||||||
|
sched_yield();
|
||||||
/* Service does not maintain a PID file on its own */
|
touch(pid_file(svc));
|
||||||
if (svc_has_pidfile(svc)) {
|
}
|
||||||
sched_yield();
|
|
||||||
touch(pid_file(svc));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_progress)
|
if (do_progress)
|
||||||
print_result(rc);
|
print_result(rc);
|
||||||
|
|
||||||
|
if (lost)
|
||||||
|
service_monitor(lost, 0);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user