summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2016-01-31 14:40:27 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2016-01-31 14:40:27 (GMT)
commitd9d267052215f223897af18310e4adee310308e7 (patch) (unidiff)
tree6b6f9eb636975f5721e00d2d71007185fa5b2fbf
parent6f9f2fd7a6952b544dccbf0bdc7f9c312f602afe (diff)
downloadpies-d9d267052215f223897af18310e4adee310308e7.tar.gz
pies-d9d267052215f223897af18310e4adee310308e7.tar.bz2
Support sysvinit ondemand components.
* src/ctl.c (fun_start): Handle status_finished same as status_sleeping (for restarting ondemand components). * src/progman.c: Respawn ondemand components. * src/sysvinit.c (enablecomp): Handle pies_comp_ondemand. (sysvinit_demand): New function. (sysvinit_fifo_handler): Handle ondemand runlevels. (inittab_parse): Support "off" fields. Convert runlevels to upper case.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/ctl.c16
-rw-r--r--src/progman.c9
-rw-r--r--src/sysvinit.c90
3 files changed, 83 insertions, 32 deletions
diff --git a/src/ctl.c b/src/ctl.c
index 0e5ea97..489fc7f 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1876,21 +1876,23 @@ fun_stop (struct json_value *result, struct prog *prog)
1876static int 1876static int
1877fun_start (struct json_value *result, struct prog *prog) 1877fun_start (struct json_value *result, struct prog *prog)
1878{ 1878{
1879 if (prog->v.p.status == status_disabled) 1879 switch (prog->v.p.status)
1880 { 1880 {
1881 case status_disabled:
1881 prog->v.p.comp->flags &= ~CF_DISABLED; 1882 prog->v.p.comp->flags &= ~CF_DISABLED;
1882 prog->v.p.status = status_enabled; 1883 prog->v.p.status = status_enabled;
1883 json_object_set_string (result, "status", "OK"); 1884 json_object_set_string (result, "status", "OK");
1884 } 1885 break;
1885 else if (prog->v.p.status == status_sleeping) 1886
1886 { 1887 case status_sleeping:
1888 case status_finished:
1887 prog->v.p.status = status_enabled; 1889 prog->v.p.status = status_enabled;
1888 prog->v.p.failcount = 0; 1890 prog->v.p.failcount = 0;
1889 prog->v.p.timestamp = 0; 1891 prog->v.p.timestamp = 0;
1890 json_object_set_string (result, "status", "OK"); 1892 json_object_set_string (result, "status", "OK");
1891 } 1893 break;
1892 else 1894
1893 { 1895 default:
1894 json_object_set_string (result, "status", "ER"); 1896 json_object_set_string (result, "status", "ER");
1895 json_object_set_string (result, "error_message", "already running"); 1897 json_object_set_string (result, "error_message", "already running");
1896 return 1; 1898 return 1;
diff --git a/src/progman.c b/src/progman.c
index 4ca3824..020dccd 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -303,9 +303,9 @@ progman_waiting_p ()
303 { 303 {
304 if (IS_COMPONENT (prog) && prog->v.p.wait && prog->pid > 0) 304 if (IS_COMPONENT (prog) && prog->v.p.wait && prog->pid > 0)
305 { 305 {
306 debug(1, ("%s: waiting for %s (%lu)", 306 debug (3, ("%s: waiting for %s (%lu)",
307 __FUNCTION__, prog_tag (prog), 307 __FUNCTION__, prog_tag (prog),
308 (unsigned long) prog->pid)); 308 (unsigned long) prog->pid));
309 return 1; 309 return 1;
310 } 310 }
311 } 311 }
@@ -2305,7 +2305,8 @@ progman_cleanup (int expect_term)
2305 } 2305 }
2306 else 2306 else
2307 { 2307 {
2308 if (prog->v.p.comp->mode >= pies_mark_sysvinit) 2308 if (prog->v.p.comp->mode >= pies_mark_sysvinit
2309 && prog->v.p.comp->mode != pies_comp_ondemand)
2309 { 2310 {
2310 sysvinit_acct (SYSV_ACCT_PROC_STOP, "", prog_tag (prog), 2311 sysvinit_acct (SYSV_ACCT_PROC_STOP, "", prog_tag (prog),
2311 pid, ""); 2312 pid, "");
diff --git a/src/sysvinit.c b/src/sysvinit.c
index be7aef8..337b922 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -238,11 +238,14 @@ enablecomp (struct prog *prog, void *data)
238 case pies_comp_boot: 238 case pies_comp_boot:
239 case pies_comp_bootwait: 239 case pies_comp_bootwait:
240 return 0; 240 return 0;
241
242 case pies_comp_ondemand:
243 return prog->v.p.status == status_enabled;
244
241 case pies_comp_powerfail: 245 case pies_comp_powerfail:
242 case pies_comp_powerwait: 246 case pies_comp_powerwait:
243 case pies_comp_powerokwait: 247 case pies_comp_powerokwait:
244 case pies_comp_ctrlaltdel: 248 case pies_comp_ctrlaltdel:
245 case pies_comp_ondemand:
246 case pies_comp_powerfailnow: 249 case pies_comp_powerfailnow:
247 case pies_comp_kbrequest: 250 case pies_comp_kbrequest:
248 return s && (s->mask & PIES_COMP_MASK (comp->mode)); 251 return s && (s->mask & PIES_COMP_MASK (comp->mode));
@@ -300,7 +303,28 @@ sysvinit_runlevel_setup (int mask, int *wait)
300 if (wait) 303 if (wait)
301 *wait = s.wait; 304 *wait = s.wait;
302} 305}
303 306
307static int
308demand_prog (struct prog *prog, void *data)
309{
310 int *rl = data;
311 struct component *comp = prog->v.p.comp;
312 if (comp->mode == pies_comp_ondemand
313 && comp->runlevels
314 && strchr (comp->runlevels, *rl))
315 {
316 prog->v.p.status = status_enabled;
317 debug (1, ("%s: %s", prog_tag (prog), "enabled"));
318 }
319 return 0;
320}
321
322static void
323sysvinit_demand (int rl)
324{
325 progman_foreach (demand_prog, &rl);
326}
327
304static const char valid_runlevel_arg[] = "0123456789SsQqAaBbCcUu"; 328static const char valid_runlevel_arg[] = "0123456789SsQqAaBbCcUu";
305 329
306int 330int
@@ -458,8 +482,21 @@ sysvinit_fifo_handler (int fd, void *data)
458 default: 482 default:
459 if (buf.req.runlevel != runlevel) 483 if (buf.req.runlevel != runlevel)
460 { 484 {
461 dfl_level = buf.req.runlevel; 485 switch (buf.req.runlevel)
462 inittrans (); 486 {
487 case 'A':
488 case 'B':
489 case 'C':
490 sysvinit_demand (buf.req.runlevel);
491 break;
492
493 default:
494 if (runlevel_index (buf.req.runlevel) != -1)
495 {
496 dfl_level = buf.req.runlevel;
497 inittrans ();
498 }
499 }
463 } 500 }
464 } 501 }
465 break; 502 break;
@@ -819,19 +856,19 @@ struct action_parser
819}; 856};
820 857
821static struct action_parser action_tab[] = { 858static struct action_parser action_tab[] = {
822 { "wait", pies_comp_wait }, 859 { "wait", pies_comp_wait },
823 { "once", pies_comp_once }, 860 { "once", pies_comp_once },
824 { "boot", pies_comp_boot }, 861 { "boot", pies_comp_boot },
825 { "bootwait", pies_comp_bootwait }, 862 { "bootwait", pies_comp_bootwait },
826 { "powerfail", pies_comp_powerfail }, 863 { "powerfail", pies_comp_powerfail },
827 { "powerwait", pies_comp_powerwait }, 864 { "powerwait", pies_comp_powerwait },
828 { "powerokwait", pies_comp_powerokwait }, 865 { "powerokwait", pies_comp_powerokwait },
829 { "ctrlaltdel", pies_comp_ctrlaltdel }, 866 { "ctrlaltdel", pies_comp_ctrlaltdel },
830 { "ondemand", pies_comp_ondemand }, 867 { "ondemand", pies_comp_ondemand },
831 { "sysinit", pies_comp_sysinit }, 868 { "sysinit", pies_comp_sysinit },
832 { "powerfailnow", pies_comp_powerfailnow }, 869 { "powerfailnow", pies_comp_powerfailnow },
833 { "kbrequest", pies_comp_kbrequest }, 870 { "kbrequest", pies_comp_kbrequest },
834 { "respawn", pies_comp_respawn }, 871 { "respawn", pies_comp_respawn },
835 { NULL } 872 { NULL }
836}; 873};
837 874
@@ -846,6 +883,15 @@ find_action_parser (const char *action)
846 return NULL; 883 return NULL;
847} 884}
848 885
886static char *
887strupr (char *s)
888{
889 char *p;
890 for (p = s; *p; p++)
891 *p = toupper (*p);
892 return s;
893}
894
849int 895int
850inittab_parse (const char *file) 896inittab_parse (const char *file)
851{ 897{
@@ -931,8 +977,7 @@ inittab_parse (const char *file)
931 977
932 if (!id || !runlevels || !action || !process) 978 if (!id || !runlevels || !action || !process)
933 { 979 {
934 logmsg (LOG_ERR, "%s:%u: %s", 980 logmsg (LOG_ERR, "%s:%u: %s", file, line_no, _("not enough fields"));
935 file, line_no, _("not enough fields"));
936 err = 1; 981 err = 1;
937 continue; 982 continue;
938 } 983 }
@@ -950,18 +995,21 @@ inittab_parse (const char *file)
950 continue; 995 continue;
951 } 996 }
952 997
998 if (strcmp (action, "off") == 0)
999 /* Ignore the entry */
1000 continue;
1001
953 ap = find_action_parser (action); 1002 ap = find_action_parser (action);
954 if (!ap) 1003 if (!ap)
955 { 1004 {
956 logmsg (LOG_ERR, "%s:%u: %s", 1005 logmsg (LOG_ERR, "%s:%u: %s", file, line_no, _("unknown action"));
957 file, line_no, _("unknown action"));
958 err = 1; 1006 err = 1;
959 continue; 1007 continue;
960 } 1008 }
961 1009
962 comp = component_create (id); 1010 comp = component_create (id);
963 comp->mode = ap->mode; 1011 comp->mode = ap->mode;
964 comp->runlevels = grecs_strdup (runlevels); 1012 comp->runlevels = grecs_strdup (strupr (runlevels));
965 1013
966 if (wordsplit (process, &ws, WRDSF_DEFFLAGS)) 1014 if (wordsplit (process, &ws, WRDSF_DEFFLAGS))
967 { 1015 {

Return to:

Send suggestions and report system problems to the System administrator.