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/ctl.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/ctl.c')
-rw-r--r-- | src/ctl.c | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -463,6 +463,12 @@ json_object_set_number (struct json_value *obj, char const *name, double val) json_object_set (obj, name, json_new_number (val)); } +void +json_object_set_bool (struct json_value *obj, char const *name, int val) +{ + json_object_set (obj, name, json_new_bool (val)); +} + static struct json_value * json_error_reply_create (const char *msg) { @@ -1449,8 +1455,8 @@ static char * const pies_comp_mode_str[] = { }; static char * const pies_status_str[] = { - [status_enabled] = "enabled", - [status_disabled] = "disabled", + [status_stopped] = "stopped", + [status_running] = "running", [status_listener] = "listener", [status_sleeping] = "sleeping", [status_stopping] = "stopping", @@ -1822,6 +1828,9 @@ prog_serialize (struct json_value *ret, struct prog *prog) case TYPE_COMPONENT: FORMAT_IDX (ret, "mode", pies_comp_mode_str, prog->v.p.comp->mode); FORMAT_IDX (ret, "status", pies_status_str, prog->v.p.status); + + json_object_set_bool (ret, "disabled", + prog->v.p.comp->flags & CF_DISABLED); if (prog->pid) json_object_set_number (ret, "PID", prog->pid); @@ -1864,17 +1873,18 @@ fun_list (struct json_value *result, struct prog *prog) static int fun_stop (struct json_value *result, struct prog *prog) { - if (prog->v.p.status == status_disabled) + if (prog->v.p.comp->flags & CF_DISABLED + && prog->v.p.status == status_stopped) { + json_object_set_string (result, "status", "ER"); json_object_set_string (result, "error_message", "already stopped"); return 1; } else { + prog->v.p.comp->flags |= CF_DISABLED; progman_stop_component (&prog); - if (prog) - prog->v.p.comp->flags |= CF_DISABLED; json_object_set_string (result, "status", "OK"); } return 0; @@ -1885,15 +1895,14 @@ fun_start (struct json_value *result, struct prog *prog) { switch (prog->v.p.status) { - case status_disabled: + case status_stopped: prog->v.p.comp->flags &= ~CF_DISABLED; - prog->v.p.status = status_enabled; json_object_set_string (result, "status", "OK"); break; case status_sleeping: case status_finished: - prog->v.p.status = status_enabled; + prog->v.p.status = status_stopped; prog->v.p.failcount = 0; prog->v.p.timestamp = 0; json_object_set_string (result, "status", "OK"); @@ -2049,7 +2058,10 @@ res_runlevel (struct ctlio *io, enum http_method meth, io->code = 200; if (strlen (val->v.s) == 1 && sysvinit_set_runlevel (val->v.s[0]) == 0) - json_object_set_string (io->output.reply, "status", "OK"); + { + pies_schedule_action (ACTION_RELOAD); + json_object_set_string (io->output.reply, "status", "OK"); + } else { json_object_set_string (io->output.reply, "status", "ER"); |