aboutsummaryrefslogtreecommitdiff
path: root/src/sysvinit.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-01-04 15:33:00 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-01-04 22:11:21 +0200
commitd8221ce9bdd2d7ae6162bed0e1c85e9f7a3ff8f2 (patch)
tree5fab301e38fede054aa85708c6c8590c1825e541 /src/sysvinit.c
parent95bc9b24928eb9951f0644307e417df0bc8c53b4 (diff)
downloadpies-d8221ce9bdd2d7ae6162bed0e1c85e9f7a3ff8f2.tar.gz
pies-d8221ce9bdd2d7ae6162bed0e1c85e9f7a3ff8f2.tar.bz2
Fix sysvinit transition logic.
* src/pies.c (main): Call sysvinit_begin to initialize sysvinit subsystem. In the main loop, force wakeup if inittrans returns 1. * src/pies.h (is_sysvinit): Rewrite macro. (progman_sysvinit_enable): New proto. (inittrans): Change return type. * src/progman.c (progman_sysvinit_enable): New function. (progman_running_p): Additional debugging. (prog_start): Special handling for sysvinit components. Remove calls to runlevel_match * src/sysvinit.c (runlevel_match): Remove function. (sysvinit_begin): New function. (inittrans): Return boolean value indicating whether a transition has been made. Call progman_sysvinit_enable to change the status of sysvinit components as appropriate.
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.