aboutsummaryrefslogtreecommitdiff
path: root/src/sysvinit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysvinit.c')
-rw-r--r--src/sysvinit.c124
1 files changed, 84 insertions, 40 deletions
diff --git a/src/sysvinit.c b/src/sysvinit.c
index e09802f..5a0d98a 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -54,7 +54,7 @@ static int boot_trans_tab[max_boot_state][sizeof(valid_runlevels)-1] = {
};
enum boot_state boot_state;
-int runlevel;
+int runlevel = 0;
int initdefault; /* Default runlevel */
int dfl_level;
@@ -62,75 +62,104 @@ int dfl_level;
static int
runlevel_index (int n)
{
- char *p = strchr (valid_runlevels, n);
+ char *p;
+
+ if (n == 0)
+ return -1;
+
+ p = strchr (valid_runlevels, n);
if (!p)
return -1;
return p - valid_runlevels;
}
-int
-runlevel_match (struct component *comp)
+static int
+enablecomp (struct component *comp, int finished, void *data)
{
- if (init_process)
+ int *wait = data;
+ int rc;
+
+ switch (boot_state)
{
- switch (boot_state)
- {
- case sysinit:
- return comp->mode == pies_comp_sysinit;
-
- case boot:
- return comp->mode == pies_comp_boot ||
- comp->mode == pies_comp_bootwait;
+ case sysinit:
+ return comp->mode == pies_comp_sysinit;
- case single0:
- case single1:
- case normal:
- switch (comp->mode)
- {
- case pies_comp_sysinit:
- case pies_comp_boot:
- case pies_comp_bootwait:
- return 0;
- case pies_comp_powerfail:
- case pies_comp_powerwait:
- case pies_comp_powerokwait:
- case pies_comp_ctrlaltdel:
- case pies_comp_ondemand:
- case pies_comp_powerfailnow:
- case pies_comp_kbrequest:
- /* FIXME */
- return 0;
- }
+ case boot:
+ return comp->mode == pies_comp_boot || comp->mode == pies_comp_bootwait;
- if (!comp->runlevels)
- return 1;
- return !!strchr (comp->runlevels, runlevel);
+ case single0:
+ case single1:
+ case normal:
+ switch (comp->mode)
+ {
+ case pies_comp_sysinit:
+ case pies_comp_boot:
+ case pies_comp_bootwait:
+ return 0;
+ case pies_comp_powerfail:
+ case pies_comp_powerwait:
+ case pies_comp_powerokwait:
+ case pies_comp_ctrlaltdel:
+ case pies_comp_ondemand:
+ case pies_comp_powerfailnow:
+ case pies_comp_kbrequest:
+ /* FIXME */
+ return 0;
}
}
- return 1;
+ rc = !!strchr (comp->runlevels, runlevel);
+ if (!rc)
+ return rc;
+ if (finished)
+ return -1;
+ if (wait)
+ {
+ if (comp->mode == pies_comp_wait)
+ {
+ *wait = 1;
+ return 1;
+ }
+ return 0;
+ }
+ return rc;
}
void
+sysvinit_begin ()
+{
+ progman_sysvinit_enable (enablecomp, NULL);
+}
+
+int
inittrans ()
{
int n;
int newlevel = 0;
enum boot_state newstate;
-
+ int trans = 0;
+ static int wait = 0;
+
if (progman_running_p ())
/* Noting to do if there are processes left in the previous runlevel */
- return;
+ return 0;
- n = runlevel_index (runlevel);
+ if (runlevel == 0)
+ n = runlevel_index (dfl_level ? dfl_level : initdefault);
+ else
+ n = runlevel_index (runlevel);
if (n == -1)
- n = 11; /* assume S */
+ n = runlevel_index ('S');
newstate = boot_trans_tab[boot_state][n];
+ debug (1, ("STATE TRANS: %s(%c,%d) -> %s", boot_state_name[boot_state],
+ runlevel,n,
+ boot_state_name[newstate]));
if (newstate != boot_state)
{
debug (1, ("STATE TRANS: %s -> %s", boot_state_name[boot_state],
boot_state_name[newstate]));
boot_state = newstate;
+ trans = 1;
}
switch (boot_state)
@@ -150,7 +179,22 @@ inittrans ()
{
debug (1, ("RL TRANS: %c -> %c", runlevel, newlevel));
runlevel = newlevel;
+ trans = 1;
+ wait = 0;
+ }
+ if (wait)
+ trans = 1;
+ if (trans)
+ {
+ if (wait == 0)
+ {
+ progman_sysvinit_enable (enablecomp, &wait);
+ if (wait)
+ return 1;
+ }
+ progman_sysvinit_enable (enablecomp, NULL);
}
+ return trans;
}
/* Return true if the progman should wait for the component to

Return to:

Send suggestions and report system problems to the System administrator.