Fix #378: add run/task support for <!> to allow transition from bootstrap

This odd little feature makes it possible to declare run/tasks with a
condition that does not block Finit transitioning from bootstrap to the
next runlevel.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2023-10-30 17:55:39 +01:00
1 parent 5ff28c4dc6
commit 5281d82e80
3 files changed
+50 -5

No files matched your search

+13 -2
View File
@@ -656,11 +656,22 @@ void conf_parse_cond(svc_t *svc, char *cond)
return;
}
/* First character must be '!' if SIGHUP is not supported. */
/*
* First character must be '!' if:
* - service: SIGHUP is not supported
* - run/task: Do not block bootstrap
*/
ptr = cond;
if (ptr[i] == '!') {
svc->sighup = 0;
ptr++;
if (svc_is_runtask(svc)) {
/* see service_runtask_clean() */
svc->sighup = 1;
svc->once = 1;
} else {
svc->sighup = 0;
}
}
while (ptr[i] != '>' && ptr[i] != 0)
+12 -3
View File
@@ -1414,7 +1414,11 @@ static void parse_cmdline_args(svc_t *svc, char *cmd, char **args)
* before they are started. Or restarted, or even SIGHUP'ed, when the
* gateway changes or interfaces come and go. The special case when a
* service is declared with <!> means it does not support SIGHUP but
* must be STOP/START'ed at system reconfiguration.
* must be STOP/START'ed at system reconfiguration. For run/task a <!>
* means Finit can relax its promise to run at least once per runlevel.
* I.e., for run/task conditions that would otherwise block bootstrap:
*
* task [S0123456789] <!sys/pwr/fail> name:pwrfail initctl poweroff -- Power failure, shutting down
*
* Conditions can for example be: pid/NAME:ID for process dependencies,
* net/<IFNAME>/up or net/<IFNAME>/exists. The condition handling is
@@ -2500,7 +2504,7 @@ restart:
case COND_ON:
if (svc_is_changed(svc)) {
if (svc_nohup(svc))
if (svc_nohup(svc) || !svc_is_daemon(svc))
service_stop(svc);
else {
/*
@@ -2601,7 +2605,12 @@ void service_runtask_clean(void)
if (!svc_is_runtask(svc))
continue;
svc->once = 0;
/* run/task declared with <!> */
if (svc->sighup)
svc->once = 1;
else
svc->once = 0;
if (svc->state == SVC_DONE_STATE)
svc_set_state(svc, SVC_HALTED_STATE);
}