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:
Joachim Nilsson committed 2018-10-07 18:35:12 +02:00
1 parent 3006caf670
commit 931565c425
1 file changed
+19 -16
+19 -16
View File
@@ -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 * This function is called after `initctl reload` to reassert conditions
* recently been changed or while it's starting up. * 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 void pidfile_reconf(void *arg)
{ {
static char cond[MAX_COND_LEN]; static char cond[MAX_COND_LEN];
svc_t *svc, *iter = NULL; svc_t *svc, *iter = NULL;
int restart = 0;
do {
restart = 0;
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) { for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
if (svc->state != SVC_RUNNING_STATE)
continue;
if (svc_is_changed(svc) || svc_is_starting(svc))
continue;
mkcond(cond, sizeof(cond), svc->cmd); mkcond(cond, sizeof(cond), svc->cmd);
if (svc->state == SVC_RUNNING_STATE && if (cond_get(cond) == COND_ON)
!svc_is_changed(svc) && continue;
!svc_is_starting(svc) &&
cond_get(cond) != COND_ON) {
cond_set_path(cond_path(cond), COND_ON); cond_set_path(cond_path(cond), COND_ON);
restart = 1;
}
} }
if (restart) /*
* 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); service_step_all(SVC_TYPE_SERVICE | SVC_TYPE_RUNTASK | SVC_TYPE_INETD);
} while (restart);
} }
static void pidfile_init(void *arg) static void pidfile_init(void *arg)