Fix #278: enforce conditions also for running pre: scripts

The whole point of pre: scripts is that they run just before the actual
run/task/service process, hence they need to be locked behind the same
conditions as the process.  Otherwise pre: scripts would be nothing more
than plain tasks.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-06-25 15:05:16 +02:00
1 parent d9dbfa23c7
commit fbcd7d2384
2 files changed
+18 -8

No files matched your search

+17 -8
View File
@@ -1886,13 +1886,8 @@ restart:
switch (svc->state) { switch (svc->state) {
case SVC_HALTED_STATE: case SVC_HALTED_STATE:
if (enabled) { if (enabled)
if (svc_has_pre(svc)) {
svc_set_state(svc, SVC_SETUP_STATE);
service_pre_script(svc);
} else
svc_set_state(svc, SVC_READY_STATE); svc_set_state(svc, SVC_READY_STATE);
}
break; break;
case SVC_DONE_STATE: case SVC_DONE_STATE:
@@ -1942,7 +1937,7 @@ restart:
case SVC_SETUP_STATE: case SVC_SETUP_STATE:
if (!svc->pid) if (!svc->pid)
svc_set_state(svc, SVC_READY_STATE); svc_set_state(svc, SVC_STARTING_STATE);
break; break;
case SVC_READY_STATE: case SVC_READY_STATE:
@@ -1953,6 +1948,21 @@ restart:
if (sm_is_in_teardown(&sm)) if (sm_is_in_teardown(&sm))
break; break;
if (svc_has_pre(svc)) {
svc_set_state(svc, SVC_SETUP_STATE);
service_pre_script(svc);
break;
}
svc_set_state(svc, SVC_STARTING_STATE);
}
break;
case SVC_STARTING_STATE:
if (!enabled) {
svc_set_state(svc, SVC_HALTED_STATE);
break;
}
err = service_start(svc); err = service_start(svc);
if (err) { if (err) {
if (svc_is_missing(svc)) { if (svc_is_missing(svc)) {
@@ -1966,7 +1976,6 @@ restart:
/* Everything went fine, clean and set state */ /* Everything went fine, clean and set state */
svc_mark_clean(svc); svc_mark_clean(svc);
svc_set_state(svc, SVC_RUNNING_STATE); svc_set_state(svc, SVC_RUNNING_STATE);
}
break; break;
case SVC_RUNNING_STATE: case SVC_RUNNING_STATE:
+1
View File
@@ -63,6 +63,7 @@ typedef enum {
SVC_SETUP_STATE, /* Running pre: script */ SVC_SETUP_STATE, /* Running pre: script */
SVC_WAITING_STATE, /* Condition is in flux, process SIGSTOPed */ SVC_WAITING_STATE, /* Condition is in flux, process SIGSTOPed */
SVC_READY_STATE, /* Enabled but condition not satisfied */ SVC_READY_STATE, /* Enabled but condition not satisfied */
SVC_STARTING_STATE, /* Conditions OK and pre: script done, start */
SVC_RUNNING_STATE, /* Process running */ SVC_RUNNING_STATE, /* Process running */
} svc_state_t; } svc_state_t;