aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/pies.c12
-rw-r--r--src/pies.h11
-rw-r--r--src/progman.c55
-rw-r--r--src/sysvinit.c124
4 files changed, 142 insertions, 60 deletions
diff --git a/src/pies.c b/src/pies.c
index 713ae8e..a2dc5e0 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -961,3 +961,3 @@ _cb_flags (enum grecs_callback_command cmd,
-static const char valid_runlevels[] = "0123456Ss";
+static const char valid_runlevels[] = "0123456789Ss";
@@ -2311,2 +2311,3 @@ main (int argc, char **argv)
set_console_dev ();
+ sysvinit_begin ();
}
@@ -2362,5 +2363,8 @@ main (int argc, char **argv)
{
- if (init_process)
- inittrans ();
- if (!children_cleanup)
+ if (init_process && inittrans ())
+ {
+ got_alarm = 1;
+ action = ACTION_CONT;
+ }
+ else if (!children_cleanup)
pies_pause ();
diff --git a/src/pies.h b/src/pies.h
index a679afd..fc4f59c 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -185,4 +185,2 @@ enum pies_comp_mode
-#define is_sysvinit(m) ((m)>=pies_mark_sysvinit)
-
#define CF_DISABLED 0x001 /* The componenet is disabled */
@@ -255,2 +253,4 @@ struct component
+#define is_sysvinit(cp) ((cp)->mode >= pies_mark_sysvinit || (cp)->runlevels)
+
union pies_sockaddr_storage
@@ -303,2 +303,5 @@ void progman_iterate_comp (int (*fun) (struct component *, void *),
void *data);
+void progman_sysvinit_enable (int (*fun) (struct component *, int, void *),
+ void *data);
+
void fd_report (int fd, const char *msg);
@@ -452,4 +455,4 @@ struct inetd_builtin *inetd_builtin_lookup (const char *service, int socktype);
/* sysvinit.c */
-int runlevel_match (struct component *comp);
-void inittrans (void);
+void sysvinit_begin (void);
+int inittrans (void);
int is_comp_wait (struct component *comp);
diff --git a/src/progman.c b/src/progman.c
index f0d0de6..15b8c44 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -108,2 +108,25 @@ progman_iterate_comp (int (*fun) (struct component *, void *), void *data)
+void
+progman_sysvinit_enable (int (*fun) (struct component *, int, void *),
+ void *data)
+{
+ struct prog *prog;
+
+ for (prog = proghead; prog; prog = prog->next)
+ if (IS_COMPONENT (prog) && is_sysvinit (prog->v.p.comp))
+ {
+ int rc = fun (prog->v.p.comp, prog->v.p.status == status_finished,
+ data);
+ if (rc < 0)
+ continue;
+ if (rc)
+ prog->v.p.status = status_enabled;
+ else
+ prog->v.p.status = status_disabled;
+ debug (1, ("%s: %s", prog->tag,
+ prog->v.p.status == status_enabled ?
+ "enabled" : "disabled"));
+ }
+}
+
static struct prog *
@@ -414,3 +437,6 @@ progman_running_p ()
prog->pid > 0)
- return 1;
+ {
+ debug (1, ("COMP %s still running", prog->tag));
+ return 1;
+ }
}
@@ -1187,10 +1213,17 @@ prog_start (struct prog *prog)
- if (is_sysvinit (prog->v.p.comp->mode) && !init_process &&
- prog->v.p.status != status_disabled)
+ if (is_sysvinit (prog->v.p.comp))
{
- logmsg (LOG_NOTICE, "disabling sysvinit component %s", prog->tag);
- prog->v.p.status = status_disabled;
- return;
+ if (!init_process)
+ {
+ if (prog->v.p.status != status_disabled)
+ {
+ logmsg (LOG_NOTICE, "disabling sysvinit component %s",
+ prog->tag);
+ prog->v.p.status = status_disabled;
+ }
+ return;
+ }
+ debug (1, ("ok to start %s", prog->v.p.comp->tag));
}
-
+
/* This call returns 1 in two cases: Either prog is marked as disabled,
@@ -1784,4 +1817,3 @@ progman_start ()
{
- if ((prog->v.p.comp->flags & CF_DISABLED)
- || !runlevel_match (prog->v.p.comp))
+ if (prog->v.p.comp->flags & CF_DISABLED)
disable_socket (prog->v.p.socket);
@@ -1793,4 +1825,3 @@ progman_start ()
}
- else if ((prog->v.p.status == status_enabled && prog->pid == 0
- && runlevel_match (prog->v.p.comp))
+ else if ((prog->v.p.status == status_enabled && prog->pid == 0)
|| prog->v.p.status == status_sleeping)
@@ -2461,3 +2492,3 @@ progman_cleanup (int expect_term)
}
- else if (is_sysvinit(prog->v.p.comp->mode))
+ else if (prog->v.p.comp->mode >= pies_mark_sysvinit)
{
diff --git a/src/sysvinit.c b/src/sysvinit.c
index e09802f..5a0d98a 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -56,3 +56,3 @@ static int boot_trans_tab[max_boot_state][sizeof(valid_runlevels)-1] = {
enum boot_state boot_state;
-int runlevel;
+int runlevel = 0;
@@ -64,3 +64,8 @@ runlevel_index (int n)
{
- char *p = strchr (valid_runlevels, n);
+ char *p;
+
+ if (n == 0)
+ return -1;
+
+ p = strchr (valid_runlevels, n);
if (!p)
@@ -70,42 +75,51 @@ runlevel_index (int n)
-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;
}
@@ -113,2 +127,8 @@ runlevel_match (struct component *comp)
void
+sysvinit_begin ()
+{
+ progman_sysvinit_enable (enablecomp, NULL);
+}
+
+int
inittrans ()
@@ -118,12 +138,20 @@ inittrans ()
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)
@@ -133,2 +161,3 @@ inittrans ()
boot_state = newstate;
+ trans = 1;
}
@@ -152,3 +181,18 @@ inittrans ()
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 to:

Send suggestions and report system problems to the System administrator.