mirror of
https://github.com/troglobit/finit.git
synced 2026-11-03 13:28:27 +00:00
Initial support for restarting lost processes during norespawn
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
cb874d7a94
commit
1d6cbe31fe
1 file changed
+22
-1
@@ -37,6 +37,7 @@
|
|||||||
/* The registered services are kept in shared memory for easy read-only access
|
/* The registered services are kept in shared memory for easy read-only access
|
||||||
* by 3rd party APIs. Mostly because of the ability to, from the outside, query
|
* by 3rd party APIs. Mostly because of the ability to, from the outside, query
|
||||||
* liveness state of all daemons that should run. */
|
* liveness state of all daemons that should run. */
|
||||||
|
static int was_stopped = 0;
|
||||||
static int svc_counter = 0; /* Number of registered services to monitor. */
|
static int svc_counter = 0; /* Number of registered services to monitor. */
|
||||||
static svc_t *services = NULL; /* List of registered services, in shared memory. */
|
static svc_t *services = NULL; /* List of registered services, in shared memory. */
|
||||||
|
|
||||||
@@ -347,11 +348,29 @@ static int is_norespawn(void)
|
|||||||
fexist("/tmp/norespawn");
|
fexist("/tmp/norespawn");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void restart_any_lost_procs(void)
|
||||||
|
{
|
||||||
|
svc_t *svc;
|
||||||
|
|
||||||
|
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||||
|
if (svc->pid > 0 && pid_alive(svc->pid))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
svc_start(svc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void svc_monitor(void)
|
void svc_monitor(void)
|
||||||
{
|
{
|
||||||
pid_t lost;
|
pid_t lost;
|
||||||
svc_t *svc;
|
svc_t *svc;
|
||||||
|
|
||||||
|
if (was_stopped && !is_norespawn()) {
|
||||||
|
was_stopped = 0;
|
||||||
|
restart_any_lost_procs();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lost = waitpid(-1, NULL, WNOHANG);
|
lost = waitpid(-1, NULL, WNOHANG);
|
||||||
if (lost < 1)
|
if (lost < 1)
|
||||||
return;
|
return;
|
||||||
@@ -360,8 +379,10 @@ void svc_monitor(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* Power user at the console, don't respawn tasks. */
|
/* Power user at the console, don't respawn tasks. */
|
||||||
if (is_norespawn())
|
if (is_norespawn()) {
|
||||||
|
was_stopped = 1;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (tty_respawn(lost))
|
if (tty_respawn(lost))
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user