mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
service: preserve explicit stop for remain tasks
A completed remain task unconditionally cleared its user stop block after running its post script. Since it was still valid in the current runlevel, it immediately started again, making initctl stop ineffective. Keep explicit stops blocked, distinguish automatic and requested restarts, and route initctl restart through teardown before rerunning the task. Cover stop, start, restart, reload, and runlevel transitions with a regression test. Signed-off-by: zhangxiaohui <xiaohui.zhang@wbstar.com>
This commit is contained in:
1 parent
530d6703f1
commit
3a18ca4a30
3 files changed
+97
-6
No files matched your search
+19
-6
@@ -1599,6 +1599,15 @@ int service_restart_now(svc_t *svc)
|
||||
if (!svc)
|
||||
return 1;
|
||||
|
||||
if (svc_is_runtask(svc) && svc_is_remain(svc) &&
|
||||
svc->state == SVC_DONE_STATE) {
|
||||
service_timeout_cancel(svc);
|
||||
svc_restarting(svc);
|
||||
service_step(svc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!svc_is_running(svc))
|
||||
return service_start_now(svc);
|
||||
|
||||
@@ -3378,8 +3387,8 @@ restart:
|
||||
svc_set_state(svc, SVC_CLEANUP_STATE);
|
||||
service_cleanup_script(svc);
|
||||
} else {
|
||||
/* Unblock remain tasks after post script so they can restart */
|
||||
if (svc_is_remain(svc))
|
||||
/* Restart remain tasks after runlevel/reload/restart teardown. */
|
||||
if (svc_is_remain(svc) && svc_is_restart(svc))
|
||||
svc_unblock(svc);
|
||||
svc_set_state(svc, SVC_HALTED_STATE);
|
||||
}
|
||||
@@ -3398,13 +3407,17 @@ restart:
|
||||
break;
|
||||
|
||||
case SVC_DONE_STATE:
|
||||
/* Remain tasks: always run post script when stopped, even if config changed */
|
||||
if (svc_is_runtask(svc) && svc_is_remain(svc) && svc_is_stopped(svc)) {
|
||||
/* Remain tasks run post script before stopping or restarting. */
|
||||
if (svc_is_runtask(svc) && svc_is_remain(svc) &&
|
||||
(svc_is_stopped(svc) || svc_is_restart(svc))) {
|
||||
if (svc_has_post(svc)) {
|
||||
svc_set_state(svc, SVC_TEARDOWN_STATE);
|
||||
service_post_script(svc);
|
||||
} else
|
||||
} else {
|
||||
if (svc_is_restart(svc))
|
||||
svc_unblock(svc);
|
||||
svc_set_state(svc, SVC_HALTED_STATE);
|
||||
}
|
||||
} else if (svc_is_changed(svc))
|
||||
svc_set_state(svc, SVC_HALTED_STATE);
|
||||
else if (svc_is_runtask(svc) && svc_is_manual(svc) && enabled)
|
||||
@@ -3727,7 +3740,7 @@ void service_runtask_clean(void)
|
||||
|
||||
/* Config changed or leaving runlevel: stop, run post, restart */
|
||||
svc->once = 0;
|
||||
svc_stop(svc);
|
||||
svc_restarting(svc);
|
||||
service_step(svc);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user