mirror of
https://github.com/troglobit/finit.git
synced 2026-10-14 10:19:36 +00:00
Simplify pidfile_reconf() thanks to the addition of schedule_wq()
We can now rely on service_step() to continue stepping run/taks/services until no more state transitions are made. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
3006caf670
commit
931565c425
1 file changed
+22
-19
+22
-19
@@ -73,35 +73,38 @@ static void pidfile_callback(void *arg, int fd, int events)
|
||||
}
|
||||
|
||||
/*
|
||||
* Assert condition only if the service is running, but not if it's
|
||||
* recently been changed or while it's starting up.
|
||||
* This function is called after `initctl reload` to reassert conditions
|
||||
* for services that have not been changed.
|
||||
*
|
||||
* We must wait for the service to create/touch its pidfile.
|
||||
* We reassert the run/task/service's condition only if it is running,
|
||||
* but not if it's recently been changed or while it's starting up.
|
||||
*/
|
||||
static void pidfile_reconf(void *arg)
|
||||
{
|
||||
static char cond[MAX_COND_LEN];
|
||||
svc_t *svc, *iter = NULL;
|
||||
int restart = 0;
|
||||
|
||||
do {
|
||||
restart = 0;
|
||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||
if (svc->state != SVC_RUNNING_STATE)
|
||||
continue;
|
||||
|
||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||
mkcond(cond, sizeof(cond), svc->cmd);
|
||||
if (svc->state == SVC_RUNNING_STATE &&
|
||||
!svc_is_changed(svc) &&
|
||||
!svc_is_starting(svc) &&
|
||||
cond_get(cond) != COND_ON) {
|
||||
cond_set_path(cond_path(cond), COND_ON);
|
||||
restart = 1;
|
||||
}
|
||||
}
|
||||
if (svc_is_changed(svc) || svc_is_starting(svc))
|
||||
continue;
|
||||
|
||||
if (restart)
|
||||
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_RUNTASK | SVC_TYPE_INETD);
|
||||
mkcond(cond, sizeof(cond), svc->cmd);
|
||||
if (cond_get(cond) == COND_ON)
|
||||
continue;
|
||||
|
||||
} while (restart);
|
||||
cond_set_path(cond_path(cond), COND_ON);
|
||||
}
|
||||
|
||||
/*
|
||||
* This will call service_step(), which in turn will schedule itself
|
||||
* as long as stepped services change state. Services going from
|
||||
* WAITING to RUNNING will reassert their conditions in that loop,
|
||||
* which in turn may unlock other services, and so on.
|
||||
*/
|
||||
service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_RUNTASK | SVC_TYPE_INETD);
|
||||
}
|
||||
|
||||
static void pidfile_init(void *arg)
|
||||
|
||||
Reference in new issue
Block a user