aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-02-13 21:27:11 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-02-13 21:46:32 +0200
commitc9581808b72ff25623c87cf49c471ce7f017985d (patch)
tree3b6c7143eec966561e24c05ffb87e1d55b4acf58
parent3c774556e22cd30c42304614e14218a767e4d700 (diff)
downloadpies-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.
-rw-r--r--doc/pies.texi19
-rw-r--r--src/comp.c3
-rw-r--r--src/ctl.c30
-rw-r--r--src/pies.h1
-rw-r--r--src/piesctl.c20
-rw-r--r--src/prog.h7
-rw-r--r--src/progman.c86
-rw-r--r--src/sysvinit.c66
8 files changed, 156 insertions, 76 deletions
diff --git a/doc/pies.texi b/doc/pies.texi
index 46bd837..39a2694 100644
--- a/doc/pies.texi
+++ b/doc/pies.texi
@@ -2437,24 +2437,37 @@ describes the type:
2437 2437
2438@multitable @columnfractions 0.2 0.7 2438@multitable @columnfractions 0.2 0.7
2439@headitem Flag @tab Meaning 2439@headitem Flag @tab Meaning
2440@item 3 @tab SysV init @samp{ctrlaltdel} component
2440@item A @tab Accept-style component 2441@item A @tab Accept-style component
2442@item B @tab SysV init @samp{boot} component
2441@item C @tab Init-style component 2443@item C @tab Init-style component
2444@item c @tab SysV init @samp{once} component
2445@item D @tab SysV init @samp{ondemand} component
2442@item E @tab Command being executed 2446@item E @tab Command being executed
2447@item F @tab SysV init @samp{powerfail} component
2448@item f @tab SysV init @samp{powerwait} component
2443@item I @tab Inetd-style component 2449@item I @tab Inetd-style component
2450@item i @tab SysV init @samp{sysinit} component
2451@item k @tab SysV init @samp{kbrequest} component
2452@item n @tab SysV init @samp{powerfailnow} component
2453@item o @tab SysV init @samp{powerokwait} component
2444@item P @tab Pass-style component 2454@item P @tab Pass-style component
2445@item R @tab Output redirector 2455@item R @tab Output redirector
2456@item W @tab SysV init @samp{wait} component
2457@item w @tab SysV init @samp{bootwait} component
2446@end multitable 2458@end multitable
2447 2459
2448 The second flag is meaningful only for components, i.e. if the first 2460 The second flag is meaningful only for components. Its values are:
2449flag is one of @samp{CAIP}. Its values are:
2450 2461
2451@multitable @columnfractions 0.2 0.7 2462@multitable @columnfractions 0.2 0.7
2452@headitem Flag @tab Meaning 2463@headitem Flag @tab Meaning
2453@item D @tab Disabled component 2464@item - @tab Disabled component
2465@item f @tab A finished @samp{once} component
2454@item L @tab Inetd listener 2466@item L @tab Inetd listener
2455@item R @tab Running component 2467@item R @tab Running component
2456@item S @tab Component is stopping 2468@item S @tab Component is stopping
2457@item s @tab Component is sleeping 2469@item s @tab Component is sleeping
2470@item T @tab Component is stopped
2458@end multitable 2471@end multitable
2459 2472
2460 The next column lists the PID (for running components) or socket address 2473 The next column lists the PID (for running components) or socket address
diff --git a/src/comp.c b/src/comp.c
index 6a0e4ba..83818c2 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -729,6 +729,9 @@ component_finish (struct component *comp, grecs_locus_t *locus)
729 comp->prereq = NULL; 729 comp->prereq = NULL;
730 } 730 }
731 } 731 }
732
733 if (comp->mode == pies_comp_ondemand)
734 comp->flags |= CF_DISABLED;
732 } 735 }
733} 736}
734 737
diff --git a/src/ctl.c b/src/ctl.c
index 6f50246..f4154f6 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -463,6 +463,12 @@ json_object_set_number (struct json_value *obj, char const *name, double val)
463 json_object_set (obj, name, json_new_number (val)); 463 json_object_set (obj, name, json_new_number (val));
464} 464}
465 465
466void
467json_object_set_bool (struct json_value *obj, char const *name, int val)
468{
469 json_object_set (obj, name, json_new_bool (val));
470}
471
466static struct json_value * 472static struct json_value *
467json_error_reply_create (const char *msg) 473json_error_reply_create (const char *msg)
468{ 474{
@@ -1449,8 +1455,8 @@ static char * const pies_comp_mode_str[] = {
1449}; 1455};
1450 1456
1451static char * const pies_status_str[] = { 1457static char * const pies_status_str[] = {
1452 [status_enabled] = "enabled", 1458 [status_stopped] = "stopped",
1453 [status_disabled] = "disabled", 1459 [status_running] = "running",
1454 [status_listener] = "listener", 1460 [status_listener] = "listener",
1455 [status_sleeping] = "sleeping", 1461 [status_sleeping] = "sleeping",
1456 [status_stopping] = "stopping", 1462 [status_stopping] = "stopping",
@@ -1822,6 +1828,9 @@ prog_serialize (struct json_value *ret, struct prog *prog)
1822 case TYPE_COMPONENT: 1828 case TYPE_COMPONENT:
1823 FORMAT_IDX (ret, "mode", pies_comp_mode_str, prog->v.p.comp->mode); 1829 FORMAT_IDX (ret, "mode", pies_comp_mode_str, prog->v.p.comp->mode);
1824 FORMAT_IDX (ret, "status", pies_status_str, prog->v.p.status); 1830 FORMAT_IDX (ret, "status", pies_status_str, prog->v.p.status);
1831
1832 json_object_set_bool (ret, "disabled",
1833 prog->v.p.comp->flags & CF_DISABLED);
1825 1834
1826 if (prog->pid) 1835 if (prog->pid)
1827 json_object_set_number (ret, "PID", prog->pid); 1836 json_object_set_number (ret, "PID", prog->pid);
@@ -1864,17 +1873,18 @@ fun_list (struct json_value *result, struct prog *prog)
1864static int 1873static int
1865fun_stop (struct json_value *result, struct prog *prog) 1874fun_stop (struct json_value *result, struct prog *prog)
1866{ 1875{
1867 if (prog->v.p.status == status_disabled) 1876 if (prog->v.p.comp->flags & CF_DISABLED
1877 && prog->v.p.status == status_stopped)
1868 { 1878 {
1879
1869 json_object_set_string (result, "status", "ER"); 1880 json_object_set_string (result, "status", "ER");
1870 json_object_set_string (result, "error_message", "already stopped"); 1881 json_object_set_string (result, "error_message", "already stopped");
1871 return 1; 1882 return 1;
1872 } 1883 }
1873 else 1884 else
1874 { 1885 {
1886 prog->v.p.comp->flags |= CF_DISABLED;
1875 progman_stop_component (&prog); 1887 progman_stop_component (&prog);
1876 if (prog)
1877 prog->v.p.comp->flags |= CF_DISABLED;
1878 json_object_set_string (result, "status", "OK"); 1888 json_object_set_string (result, "status", "OK");
1879 } 1889 }
1880 return 0; 1890 return 0;
@@ -1885,15 +1895,14 @@ fun_start (struct json_value *result, struct prog *prog)
1885{ 1895{
1886 switch (prog->v.p.status) 1896 switch (prog->v.p.status)
1887 { 1897 {
1888 case status_disabled: 1898 case status_stopped:
1889 prog->v.p.comp->flags &= ~CF_DISABLED; 1899 prog->v.p.comp->flags &= ~CF_DISABLED;
1890 prog->v.p.status = status_enabled;
1891 json_object_set_string (result, "status", "OK"); 1900 json_object_set_string (result, "status", "OK");
1892 break; 1901 break;
1893 1902
1894 case status_sleeping: 1903 case status_sleeping:
1895 case status_finished: 1904 case status_finished:
1896 prog->v.p.status = status_enabled; 1905 prog->v.p.status = status_stopped;
1897 prog->v.p.failcount = 0; 1906 prog->v.p.failcount = 0;
1898 prog->v.p.timestamp = 0; 1907 prog->v.p.timestamp = 0;
1899 json_object_set_string (result, "status", "OK"); 1908 json_object_set_string (result, "status", "OK");
@@ -2049,7 +2058,10 @@ res_runlevel (struct ctlio *io, enum http_method meth,
2049 io->code = 200; 2058 io->code = 200;
2050 if (strlen (val->v.s) == 1 2059 if (strlen (val->v.s) == 1
2051 && sysvinit_set_runlevel (val->v.s[0]) == 0) 2060 && sysvinit_set_runlevel (val->v.s[0]) == 0)
2052 json_object_set_string (io->output.reply, "status", "OK"); 2061 {
2062 pies_schedule_action (ACTION_RELOAD);
2063 json_object_set_string (io->output.reply, "status", "OK");
2064 }
2053 else 2065 else
2054 { 2066 {
2055 json_object_set_string (io->output.reply, "status", "ER"); 2067 json_object_set_string (io->output.reply, "status", "ER");
diff --git a/src/pies.h b/src/pies.h
index 9fb87c6..14ea7b7 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -587,3 +587,4 @@ void json_object_set_string (struct json_value *obj,
587 char const *name, char const *fmt, ...); 587 char const *name, char const *fmt, ...);
588void json_object_set_number (struct json_value *obj, 588void json_object_set_number (struct json_value *obj,
589 char const *name, double val); 589 char const *name, double val);
590void json_object_set_bool (struct json_value *obj, char const *name, int val);
diff --git a/src/piesctl.c b/src/piesctl.c
index d6a39a2..5f26aec 100644
--- a/src/piesctl.c
+++ b/src/piesctl.c
@@ -1075,8 +1075,8 @@ struct kwtrans mode_trans[] = {
1075}; 1075};
1076 1076
1077struct kwtrans status_trans[] = { 1077struct kwtrans status_trans[] = {
1078 { "enabled", 'R' }, 1078 { "running", 'R' },
1079 { "disabled", 'D' }, 1079 { "stopped", 'T' },
1080 { "listener", 'L' }, 1080 { "listener", 'L' },
1081 { "sleeping", 's' }, 1081 { "sleeping", 's' },
1082 { "stopping", 'S' }, 1082 { "stopping", 'S' },
@@ -1159,15 +1159,21 @@ print_comp (FILE *fp, struct json_value *v, size_t n)
1159 if (strcmp (type, "component") == 0) 1159 if (strcmp (type, "component") == 0)
1160 { 1160 {
1161 p = getval (v, "mode", json_string, 0); 1161 p = getval (v, "mode", json_string, 0);
1162 if (v) 1162 if (p)
1163 fbuf[fidx++] = kwtoc (p->v.s, mode_trans); 1163 fbuf[fidx++] = kwtoc (p->v.s, mode_trans);
1164 else 1164 else
1165 fbuf[fidx++] = '-'; 1165 fbuf[fidx++] = '-';
1166 p = getval (v, "status", json_string, 0); 1166 p = getval (v, "disabled", json_bool, 0);
1167 if (p) 1167 if (p && p->v.b)
1168 fbuf[fidx++] = status = kwtoc (p->v.s, status_trans);
1169 else
1170 fbuf[fidx++] = '-'; 1168 fbuf[fidx++] = '-';
1169 else
1170 {
1171 p = getval (v, "status", json_string, 0);
1172 if (p)
1173 fbuf[fidx++] = status = kwtoc (p->v.s, status_trans);
1174 else
1175 fbuf[fidx++] = '-';
1176 }
1171 } 1177 }