mirror of
https://github.com/troglobit/finit.git
synced 2026-10-28 12:30:44 +00:00
Refactor ready:script to support new notify framework
Follow-up to abcb3ce, calling the service ready:script when readiness
has been signaled to or detected by Finit.
Issue #300
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
1f9621cf4b
commit
c9f1bff419
7 files changed
+87
-25
No files matched your search
@@ -297,17 +297,10 @@ int cond_set_noupdate(const char *name)
|
||||
|
||||
void cond_set(const char *name)
|
||||
{
|
||||
svc_t *svc;
|
||||
|
||||
dbg("%s", name);
|
||||
if (cond_set_noupdate(name))
|
||||
return;
|
||||
|
||||
/* XXX: refactor when new notify framework is in place */
|
||||
svc = svc_find_by_cond(name);
|
||||
if (svc && svc_has_ready(svc))
|
||||
service_ready_script(svc);
|
||||
|
||||
cond_update(name);
|
||||
}
|
||||
|
||||
|
||||
+25
-10
@@ -1797,7 +1797,7 @@ static void service_pre_script(svc_t *svc)
|
||||
{
|
||||
svc->pid = service_fork(svc);
|
||||
if (svc->pid < 0) {
|
||||
err(1, "Failed forking off %s pre-script %s", svc_ident(svc, NULL, 0), svc->pre_script);
|
||||
err(1, "Failed forking off %s pre:script %s", svc_ident(svc, NULL, 0), svc->pre_script);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1822,6 +1822,8 @@ static void service_pre_script(svc_t *svc)
|
||||
_exit(EX_OSERR);
|
||||
}
|
||||
|
||||
dbg("%s: pre:script %s started as PID %d", svc_ident(svc, NULL, 0), svc->pre_script, svc->pid);
|
||||
|
||||
/* Short hard-coded timeout to prevent locking up Finit */
|
||||
service_timeout_after(svc, svc->killdelay, service_kill_script);
|
||||
}
|
||||
@@ -1830,7 +1832,7 @@ static void service_post_script(svc_t *svc)
|
||||
{
|
||||
svc->pid = service_fork(svc);
|
||||
if (svc->pid < 0) {
|
||||
err(1, "Failed forking off %s post-script %s", svc_ident(svc, NULL, 0), svc->post_script);
|
||||
err(1, "Failed forking off %s post:script %s", svc_ident(svc, NULL, 0), svc->post_script);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1870,6 +1872,8 @@ static void service_post_script(svc_t *svc)
|
||||
_exit(EX_OSERR);
|
||||
}
|
||||
|
||||
dbg("%s: post:script %s started as PID %d", svc_ident(svc, NULL, 0), svc->post_script, svc->pid);
|
||||
|
||||
/* Short hard-coded timeout to prevent locking up Finit */
|
||||
service_timeout_after(svc, svc->killdelay, service_kill_script);
|
||||
}
|
||||
@@ -1908,6 +1912,9 @@ void service_ready_script(svc_t *svc)
|
||||
_exit(EX_OSERR);
|
||||
}
|
||||
|
||||
dbg("%s: ready:script %s started as PID %d", svc_ident(svc, NULL, 0), svc->ready_script, pid);
|
||||
|
||||
/* Short hard-coded timeout to prevent locking up Finit */
|
||||
service_script_add(svc, pid);
|
||||
}
|
||||
|
||||
@@ -2031,6 +2038,18 @@ void service_forked(svc_t *svc)
|
||||
svc_set_state(svc, SVC_RUNNING_STATE);
|
||||
}
|
||||
|
||||
/* Set service/foo/ready condition and call optional ready:script */
|
||||
void service_ready(svc_t *svc)
|
||||
{
|
||||
char buf[MAX_COND_LEN];
|
||||
|
||||
snprintf(buf, sizeof(buf), "service/%s/ready", svc_ident(svc, NULL, 0));
|
||||
cond_set(buf);
|
||||
|
||||
if (svc_has_ready(svc))
|
||||
service_ready_script(svc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Transition task/run/service
|
||||
*
|
||||
@@ -2213,11 +2232,8 @@ restart:
|
||||
|
||||
svc_mark_clean(svc);
|
||||
}
|
||||
if (svc->notify == 2 && svc->notify_watcher.fd == 0) {
|
||||
char buf[120];
|
||||
snprintf(buf, sizeof(buf), "service/%s/ready", svc_ident(svc, NULL, 0));
|
||||
cond_set(buf);
|
||||
}
|
||||
if (svc->notify == 2 && svc->notify_watcher.fd == 0)
|
||||
service_ready(svc);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -2355,7 +2371,7 @@ int service_completed(void)
|
||||
void service_notify_cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
svc_t *svc = (svc_t *)arg;
|
||||
char buf[120];
|
||||
char buf[32];
|
||||
ssize_t len;
|
||||
|
||||
if (UEV_ERROR == events) {
|
||||
@@ -2374,8 +2390,7 @@ void service_notify_cb(uev_t *w, void *arg, int events)
|
||||
|
||||
/* systemd and s6, respectively. The latter then closes the socket */
|
||||
if (!strcmp(buf, "READY=1\n") || !strcmp(buf, "\n")) {
|
||||
snprintf(buf, sizeof(buf), "service/%s/ready", svc_ident(svc, NULL, 0));
|
||||
cond_set(buf);
|
||||
service_ready(svc);
|
||||
/* s6 applications close their socket after notification */
|
||||
if (svc->notify == 2) {
|
||||
uev_io_stop(w);
|
||||
|
||||
@@ -41,6 +41,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);
|
||||
|
||||
int service_stop (svc_t *svc);
|
||||
int service_step (svc_t *svc);
|
||||
|
||||
Reference in new issue
Block a user