diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-02-13 21:27:11 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-02-13 21:46:32 +0200 |
commit | c9581808b72ff25623c87cf49c471ce7f017985d (patch) | |
tree | 3b6c7143eec966561e24c05ffb87e1d55b4acf58 /src/sysvinit.c | |
parent | 3c774556e22cd30c42304614e14218a767e4d700 (diff) | |
download | pies-c9581808b72ff25623c87cf49c471ce7f017985d.tar.gz pies-c9581808b72ff25623c87cf49c471ce7f017985d.tar.bz2 |
Stop disabled components when switching runlevels.
* src/prog.h (status_enabled, status_disabled): Remove.
(status_stopped, status_running): New modes.
All uses updated.
* src/comp.c (component_finish): Disable ondemand component
by default.
* src/ctl.c (json_object_set_bool): New function.
(pies_status_str): Update.
(prog_serialize): Set "disabled" attribute.
(fun_stop, fun_start): Use CF_DISABLED flag.
(res_runlevel): Schedule ACTION_RELOAD.
* src/pies.h (json_object_set_bool): New proto.
* src/piesctl.c (status_trans): Reflect changes in modes.
(print_comp): Check the "disabled" attribute.
* src/progman.c (register_prog0)
(prog_open_socket,prog_start,prog_stop)
(progman_wake_sleeping)
(prog_start_prerequisites)
(react, progman_cleanup)
(progman_stop_component): Update.
(no_children_left): Fix.
* src/sysvinit.c (enablecomp): Make CF_DISABLED flag
persist for ondemand components.
(runlevel_setup_prog): Use CF_DISABLED flag.
(inittrans): Stop inactivated processes.
* doc/pies.texi: Update.
Diffstat (limited to 'src/sysvinit.c')
-rw-r--r-- | src/sysvinit.c | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/src/sysvinit.c b/src/sysvinit.c index 9e918c7..c9447ff 100644 --- a/src/sysvinit.c +++ b/src/sysvinit.c @@ -219,7 +219,6 @@ static int enablecomp (struct prog *prog, void *data) { struct enstate *s = data; - int rc; struct component *comp = prog->v.p.comp; switch (boot_state) @@ -240,7 +239,8 @@ enablecomp (struct prog *prog, void *data) return 0; case pies_comp_ondemand: - return prog->v.p.status == status_enabled; + /* Disabled flag persists: */ + return !(prog->v.p.comp->flags & CF_DISABLED); case pies_comp_powerfail: case pies_comp_powerwait: @@ -253,11 +253,13 @@ enablecomp (struct prog *prog, void *data) break; } } - rc = !!strchr (comp->runlevels, runlevel); - if (!rc) - return rc; + + if (!strchr (comp->runlevels, runlevel)) + return 0; + if (prog->v.p.status == status_finished) return -1; + if (s && s->mask & PIES_COMP_WAIT) { if (comp->mode == pies_comp_wait) @@ -267,7 +269,8 @@ enablecomp (struct prog *prog, void *data) } return 0; } - return rc; + + return 1; } static int @@ -279,12 +282,12 @@ runlevel_setup_prog (struct prog *prog, void *data) if (rc < 0) return 0; if (rc) - prog->v.p.status = status_enabled; + prog->v.p.comp->flags &= ~CF_DISABLED; else - prog->v.p.status = status_disabled; - debug (1, ("%s: %s", prog_tag (prog), - prog->v.p.status == status_enabled ? - "enabled" : "disabled")); + prog->v.p.comp->flags |= CF_DISABLED; + debug (2, ("%s: %s", prog_tag (prog), + prog->v.p.comp->flags & CF_DISABLED ? + "disabled" : "enabled")); } return 0; } @@ -313,7 +316,7 @@ demand_prog (struct prog *prog, void *data) && comp->runlevels && strchr (comp->runlevels, *rl)) { - prog->v.p.status = status_enabled; + prog->v.p.comp->flags &= ~CF_DISABLED; debug (1, ("%s: %s", prog_tag (prog), "enabled")); } return 0; @@ -708,6 +711,31 @@ sysvinit_begin () sysvinit_sysdep_begin (); } +#define IS_RUNNING_DISABLED_PROG(prog) \ + (IS_COMPONENT (prog) \ + && prog->v.p.status == status_running \ + && prog->v.p.comp->flags & CF_DISABLED) \ + +static int +cond_running_disabled (struct prog *prog, void *data) +{ + return IS_RUNNING_DISABLED_PROG (prog); +} + +static int +running_disabled (void *data) +{ + return progman_foreach (cond_running_disabled, NULL); +} + +static int +terminate_disabled (struct prog *prog, void *data) +{ + if (IS_RUNNING_DISABLED_PROG (prog)) + prog_stop (prog, *(int*)data); + return 0; +} + int inittrans () { @@ -769,6 +797,8 @@ inittrans () trans = 1; if (trans) { + int sig; + envsetup (); if (wait == 0) { @@ -777,6 +807,18 @@ inittrans () return 1; } sysvinit_runlevel_setup (PIES_COMP_DEFAULT, NULL); + + /* Stop disabled programs */ + sig = SIGTERM; + progman_foreach (terminate_disabled, &sig); + if (progman_wait_until (running_disabled, NULL)) + { + sig = SIGKILL; + progman_foreach (terminate_disabled, &sig); + progman_wait_until (running_disabled, NULL); + } + + /* Clear the wait flag */ wait = 0; } return trans; |