Fix #392: ensure 'ready' condition is cleared on pidfile removal

A service with notify:pid is 'ready' when the pidfile has been created,
the converse also holds true -- when a pidfile is removed the service is
no longer 'ready'.

The state transition for the service has probably already been done, in
svc_set_state(), clearing all <service/foo/*> conditions when the PID
was collected.  The pidfile event may arrive later, so for completeness
we make sure the 'ready' condition is not recreated at least.

Problem introduced in 912a281 with the original supoport for service
readiness notification.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-01-06 12:25:41 +01:00
parent 77cf72cb40
commit d66455496a
3 changed files with 16 additions and 13 deletions
+3 -3
View File
@@ -123,11 +123,11 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
if (svc->notify == SVC_NOTIFY_PID)
cond_set(cond);
if (svc->notify == SVC_NOTIFY_PID || svc->notify == SVC_NOTIFY_NONE)
service_ready(svc);
service_ready(svc, 1);
} else if (mask & IN_DELETE) {
cond_clear(cond);
if (svc->notify == SVC_NOTIFY_PID)
service_ready(svc);
service_ready(svc, 0);
}
}
@@ -242,7 +242,7 @@ static void pidfile_reconf(void *arg)
continue;
if (svc->notify == SVC_NOTIFY_PID)
service_ready(svc);
service_ready(svc, 1);
mkcond(svc, cond, sizeof(cond));
if (cond_get(cond) == COND_ON)
+12 -9
View File
@@ -2330,8 +2330,8 @@ void service_forked(svc_t *svc)
svc_set_state(svc, SVC_RUNNING_STATE);
}
/* Set service/foo/ready condition for services and call optional ready:script */
void service_ready(svc_t *svc)
/* Set or clear service/foo/ready condition for services and call optional ready:script */
void service_ready(svc_t *svc, int ready)
{
char buf[MAX_COND_LEN];
@@ -2339,10 +2339,13 @@ void service_ready(svc_t *svc)
return;
snprintf(buf, sizeof(buf), "service/%s/ready", svc_ident(svc, NULL, 0));
cond_set(buf);
if (ready) {
cond_set(buf);
if (svc_has_ready(svc))
service_ready_script(svc);
if (svc_has_ready(svc))
service_ready_script(svc);
} else
cond_clear(buf);
}
/*
@@ -2551,7 +2554,7 @@ restart:
svc_mark_clean(svc);
}
if (svc->notify == SVC_NOTIFY_NONE)
service_ready(svc);
service_ready(svc, 1);
break;
}
break;
@@ -2585,7 +2588,7 @@ restart:
}
dbg("Reassert %s ready condition", svc_ident(svc, NULL, 0));
service_ready(svc);
service_ready(svc, 1);
}
break;
@@ -2721,7 +2724,7 @@ void service_notify_reconf(void)
if (svc->notify != SVC_NOTIFY_NONE && (svc_is_changed(svc) || svc_is_starting(svc)))
continue;
service_ready(svc);
service_ready(svc, 1);
}
}
@@ -2762,7 +2765,7 @@ void service_notify_cb(uev_t *w, void *arg, int events)
* the service_notify_reconf() function to step the
* generation of the READY condition.
*/
service_ready(svc);
service_ready(svc, 1);
/* s6 applications close their socket after notification */
if (svc->notify == SVC_NOTIFY_S6) {
+1 -1
View File
@@ -42,7 +42,7 @@ int service_timeout_after (svc_t *svc, int timeout, void (*cb)(svc_t *svc
int service_timeout_cancel (svc_t *svc);
void service_forked (svc_t *svc);
void service_ready (svc_t *svc);
void service_ready (svc_t *svc, int ready);
int service_stop (svc_t *svc);
int service_step (svc_t *svc);