aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pies.c54
-rw-r--r--src/pies.h11
-rw-r--r--src/prog.h2
-rw-r--r--src/progman.c20
-rw-r--r--src/sysvinit.c59
5 files changed, 67 insertions, 79 deletions
diff --git a/src/pies.c b/src/pies.c
index 96e9281..3734b47 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -1536,7 +1536,7 @@ pies_reload (void)
{
component_config_commit ();
if (init_process)
- sysvinit_runlevel_setup (PIES_COMP_DEFAULT, NULL);
+ sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
progman_create_sockets ();
progman_start ();
}
@@ -1549,9 +1549,8 @@ static struct config_syntax *current_syntax = &config_syntax_tab[CONF_PIES];
#include "cmdline.h"
-int action = ACTION_CONT;
-int children_cleanup = 0;
-int got_alarm = 0;
+static int action = ACTION_CONT;
+static int children_op = PIES_CHLD_NONE;
void
pies_schedule_action (int act)
@@ -1559,6 +1558,12 @@ pies_schedule_action (int act)
action = act;
}
+void
+pies_schedule_children (int op)
+{
+ children_op |= op;
+}
+
RETSIGTYPE
sig_handler (int sig)
{
@@ -1567,7 +1572,7 @@ sig_handler (int sig)
switch (sig)
{
case SIGCHLD:
- children_cleanup = 1;
+ pies_schedule_children (PIES_CHLD_CLEANUP);
break;
case SIGINT:
@@ -1588,7 +1593,7 @@ sig_handler (int sig)
break;
case SIGALRM:
- got_alarm = 1;
+ pies_schedule_children (PIES_CHLD_WAKEUP);
break;
}
}
@@ -2150,9 +2155,7 @@ main (int argc, char **argv)
diag_setup (DIAG_TO_SYSLOG);
}
- if (init_process)
- ctl_open ();
- else
+ if (!init_process)
{
if (ctl_open ())
exit (EX_UNAVAILABLE);
@@ -2173,10 +2176,10 @@ main (int argc, char **argv)
{
if (init_process && inittrans ())
{
- got_alarm = 1;
+ pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
}
- else if (!children_cleanup)
+ else if (children_op == PIES_CHLD_NONE)
pies_pause ();
switch (action)
{
@@ -2190,7 +2193,7 @@ main (int argc, char **argv)
case ACTION_RELOAD:
pies_reload ();
- got_alarm = 1;
+ pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
break;
@@ -2204,38 +2207,31 @@ main (int argc, char **argv)
case ACTION_CTRLALTDEL:
debug (1, ("ctrl-alt-del"));
- sysvinit_runlevel_setup (PIES_COMP_MASK (pies_comp_ctrlaltdel),
- NULL);
- got_alarm = 1;
+ sysvinit_runlevel_setup (PIES_COMP_MASK (pies_comp_ctrlaltdel));
+ pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
break;
case ACTION_KBREQUEST:
debug (1, ("kbrequest"));
- sysvinit_runlevel_setup (PIES_COMP_MASK (pies_comp_kbrequest),
- NULL);
- got_alarm = 1;
+ sysvinit_runlevel_setup (PIES_COMP_MASK (pies_comp_kbrequest));
+ pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
break;
case ACTION_POWER:
debug (1, ("SIGPWR"));
sysvinit_power ();
- got_alarm = 1;
+ pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
}
if (action == ACTION_CONT)
{
- if (children_cleanup)
- {
- children_cleanup = 0;
- progman_cleanup (0);
- }
- if (got_alarm)
- {
- progman_wake_sleeping (1);
- got_alarm = 0;
- }
+ if (children_op & PIES_CHLD_CLEANUP)
+ progman_cleanup (0);
+ if (children_op & PIES_CHLD_WAKEUP)
+ progman_wake_sleeping (1);
+ children_op = PIES_CHLD_NONE;
}
}
while (init_process || action == ACTION_CONT);
diff --git a/src/pies.h b/src/pies.h
index 14ea7b7..bcce32a 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -180,8 +180,7 @@ enum pies_comp_mode
};
#define PIES_COMP_DEFAULT 0
-#define PIES_COMP_WAIT 0x01
-#define PIES_COMP_MASK(m) (1 << ((m)+1))
+#define PIES_COMP_MASK(m) (1 << ((m)))
#define CF_DISABLED 0x001 /* The componenet is disabled */
#define CF_PRECIOUS 0x002 /* The component is precious (should not
@@ -317,6 +316,12 @@ void free_redirector (struct redirector *rp);
void pies_schedule_action (int act);
void free_action (struct action *act);
+#define PIES_CHLD_NONE 0
+#define PIES_CHLD_CLEANUP 0x01
+#define PIES_CHLD_WAKEUP 0x02
+
+void pies_schedule_children (int op);
+
void register_prog (struct component *comp);
int progman_waiting_p (void);
void progman_start (void);
@@ -512,7 +517,7 @@ int console_open (int mode);
int telinit (const char *arg);
int inittab_parse (const char *file);
int sysvinit_sigtrans (int sig, int *pact);
-void sysvinit_runlevel_setup (int mask, int *wait);
+void sysvinit_runlevel_setup (int mask);
void sysvinit_sysdep_begin (void);
void sysvinit_power (void);
diff --git a/src/prog.h b/src/prog.h
index 1db2eee..4658518 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -81,6 +81,8 @@ struct prog
};
#define IS_COMPONENT(p) ((p)->type == TYPE_COMPONENT)
+#define IS_ACTIVE_COMPONENT(prog) \
+ (IS_COMPONENT(prog) && !((prog)->v.p.comp->flags & CF_DISABLED))
struct prog *progman_locate (const char *name);
int progman_foreach (int (*filter) (struct prog *, void *data), void *data);
diff --git a/src/progman.c b/src/progman.c
index 29b5331..8a5187c 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -1050,7 +1050,6 @@ prog_start (struct prog *prog)
}
return;
}
- prog->v.p.wait = is_comp_wait (prog->v.p.comp);
}
/* This call returns 1 in two cases: Either prog is marked as disabled,
@@ -1541,14 +1540,20 @@ progman_wake_sleeping (int onalrm)
struct prog *prog;
time_t now = time (NULL);
- if (progman_waiting_p ())
- /* Noting to do if there are processes left in the previous runlevel */
- return;
+ debug (1, (_("checking for components to start")));
- debug (1, (_("managing sleeping/stopping components")));
+ for (prog = proghead; prog; prog = prog->next)
+ {
+ if (IS_ACTIVE_COMPONENT (prog) && prog->v.p.wait)
+ {
+ if (prog->v.p.status != status_running)
+ prog_start (prog);
+ return;
+ }
+ }
for (prog = proghead; prog; prog = prog->next)
- if (IS_COMPONENT (prog))
+ if (IS_ACTIVE_COMPONENT (prog))
{
switch (prog->v.p.status)
{
@@ -2256,7 +2261,6 @@ react (struct prog *prog, int status, pid_t pid)
prog_start (prog);
}
-
void
progman_cleanup (int expect_term)
{
@@ -2316,6 +2320,8 @@ progman_cleanup (int expect_term)
sysvinit_acct (SYSV_ACCT_PROC_STOP, "", prog_tag (prog),
pid, "");
prog->v.p.status = status_finished;
+ if (prog->v.p.wait)
+ pies_schedule_children (PIES_CHLD_WAKEUP);
prog->v.p.wait = 0;
}
else
diff --git a/src/sysvinit.c b/src/sysvinit.c
index c9447ff..2d0671c 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -212,7 +212,6 @@ runlevel_index (int n)
struct enstate
{
int mask;
- int wait;
};
static int
@@ -249,27 +248,21 @@ enablecomp (struct prog *prog, void *data)
case pies_comp_powerfailnow:
case pies_comp_kbrequest:
return s && (s->mask & PIES_COMP_MASK (comp->mode));
+
default:
break;
}
}
+ if (!comp->runlevels)
+ return -1;
+
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)
- {
- s->wait = 1;
- return 1;
- }
- return 0;
- }
-
return 1;
}
@@ -285,26 +278,22 @@ runlevel_setup_prog (struct prog *prog, void *data)
prog->v.p.comp->flags &= ~CF_DISABLED;
else
prog->v.p.comp->flags |= CF_DISABLED;
- debug (2, ("%s: %s", prog_tag (prog),
+ prog->v.p.wait = is_comp_wait (prog->v.p.comp);
+ debug (2, ("%s: %s%s", prog_tag (prog),
prog->v.p.comp->flags & CF_DISABLED ?
- "disabled" : "enabled"));
+ "disabled" : "enabled",
+ !(prog->v.p.comp->flags & CF_DISABLED) && prog->v.p.wait
+ ? " (wait)" : ""));
}
return 0;
}
void
-sysvinit_runlevel_setup (int mask, int *wait)
+sysvinit_runlevel_setup (int mask)
{
struct enstate s;
s.mask = mask;
- if (wait)
- {
- s.mask |= PIES_COMP_WAIT;
- s.wait = *wait;
- }
progman_foreach (runlevel_setup_prog, &s);
- if (wait)
- *wait = s.wait;
}
static int
@@ -706,7 +695,7 @@ sysvinit_begin ()
console_stty ();
setsid ();
envsetup ();
- sysvinit_runlevel_setup (PIES_COMP_DEFAULT, NULL);
+ sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
add_extra_sigv (sigv, ARRAY_SIZE (sigv));
sysvinit_sysdep_begin ();
}
@@ -743,7 +732,6 @@ inittrans ()
int newlevel = 0;
enum boot_state newstate;
int trans = 0;
- static int wait = 0;
if (progman_waiting_p ())
/* Noting to do if there are processes left in the previous runlevel */
@@ -763,7 +751,6 @@ inittrans ()
boot_state_name[newstate]));
boot_state = newstate;
trans = 1;
- wait = 0;
}
switch (boot_state)
@@ -779,8 +766,11 @@ inittrans ()
case normal:
newlevel = dfl_level ? dfl_level : getinitdefault ();
if (trans)
- /* boot -> normal */
- create_fifo ();
+ {
+ /* boot -> normal */
+ create_fifo ();
+ ctl_open ();
+ }
}
if (newlevel && newlevel != runlevel)
{
@@ -791,22 +781,14 @@ inittrans ()
mf_proctitle_format ("init [%c]", newlevel);
runlevel = newlevel;
trans = 1;
- wait = 0;
}
- if (wait)
- trans = 1;
+
if (trans)
{
int sig;
envsetup ();
- if (wait == 0)
- {
- sysvinit_runlevel_setup (PIES_COMP_DEFAULT, &wait);
- if (wait)
- return 1;
- }
- sysvinit_runlevel_setup (PIES_COMP_DEFAULT, NULL);
+ sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
/* Stop disabled programs */
sig = SIGTERM;
@@ -817,9 +799,6 @@ inittrans ()
progman_foreach (terminate_disabled, &sig);
progman_wait_until (running_disabled, NULL);
}
-
- /* Clear the wait flag */
- wait = 0;
}
return trans;
}
@@ -1147,7 +1126,7 @@ powerfailcmd (int power_stat)
| PIES_COMP_MASK (pies_comp_powerwait);
}
- sysvinit_runlevel_setup (mask, NULL);
+ sysvinit_runlevel_setup (mask);
}
void

Return to:

Send suggestions and report system problems to the System administrator.