aboutsummaryrefslogtreecommitdiff
path: root/src/progman.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-01-31 13:43:18 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-01-31 13:43:18 +0200
commit6f9f2fd7a6952b544dccbf0bdc7f9c312f602afe (patch)
tree8bf0b45bb6578dee844dc92c1a90a93474f0fa7a /src/progman.c
parent7f20aa4f7e26d8f740b55bef98f0c3c78eca0e79 (diff)
downloadpies-6f9f2fd7a6952b544dccbf0bdc7f9c312f602afe.tar.gz
pies-6f9f2fd7a6952b544dccbf0bdc7f9c312f602afe.tar.bz2
Fix runlevel switching; handle powerfail commands.
* src/ctl.c (prog_serialize): List runlevels. * src/pies.c (main): Set got_alarm after reloading configuration. Handle ACTION_POWER. * src/pies.h (ACTION_POWER): New constant. (progman_running_p): Rename to progman_waiting_p. All uses changed. (sysvinit_power): New proto. (POWER_STAT_FILE): New define. (POWER_STAT_FAIL,POWER_STAT_LOW,POWER_STAT_OK): New constants. * src/prog.h (prog) <idx>: Remove. (prog) <wait>: New member. * src/progman.c (prog_lookup_by_idx): Remove. (progman_waiting_p): Return 1 only if there is at least one prog with v.p.wait set. (prog_start): Initialize v.p.wait for sysvinit components. (progman_start): Don't do anything if waiting for components from the previous runlevel. (progman_wake_sleeping): Likewise. (progman_cleanup): Assume expect_term if waiting for components from the previous runlevel. Clear v.p.wait on exited progs. * src/sysvinit.c (sysvinit_fifo_handler): Don't call progman_stop when handling runlevel changes. Handle INIT_CMD_POWERFAIL, INIT_CMD_POWERFAILNOW, and INIT_CMD_POWEROK. (sysvinit_sigtrans): Handle SIGPWR. (is_comp_wait): Rewrite. (power_stat_file): New variable. (sysvinit_power): New function.
Diffstat (limited to 'src/progman.c')
-rw-r--r--src/progman.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/progman.c b/src/progman.c
index 3bbd8b3..4ca3824 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -116,12 +116,2 @@ progman_lookup_tcpmux (const char *service, const char *master)
-struct prog *
-prog_lookup_by_idx (unsigned idx)
-{
- struct prog *prog;
- for (prog = proghead; prog; prog = prog->next)
- if (IS_COMPONENT (prog) && prog->v.p.idx == idx)
- break;
- return prog;
-}
-
void prog_stop (struct prog *prog, int sig);
@@ -307,3 +297,3 @@ register_command (char *tag, char *command, pid_t pid)
int
-progman_running_p ()
+progman_waiting_p ()
{
@@ -313,5 +303,9 @@ progman_running_p ()
{
- if (IS_COMPONENT (prog) && is_comp_wait (prog->v.p.comp) &&
- prog->pid > 0)
- return 1;
+ if (IS_COMPONENT (prog) && prog->v.p.wait && prog->pid > 0)
+ {
+ debug(1, ("%s: waiting for %s (%lu)",
+ __FUNCTION__, prog_tag (prog),
+ (unsigned long) prog->pid));
+ return 1;
+ }
}
@@ -1061,2 +1055,3 @@ prog_start (struct prog *prog)
}
+ prog->v.p.wait = is_comp_wait (prog->v.p.comp);
debug (1, ("ok to start %s", prog->v.p.comp->tag));
@@ -1503,2 +1498,6 @@ progman_start ()
+ if (progman_waiting_p ())
+ /* Noting to do if there are processes left in the previous runlevel */
+ return;
+
recompute_alarm = 0;
@@ -1548,2 +1547,6 @@ progman_wake_sleeping (int onalrm)
+ if (progman_waiting_p ())
+ /* Noting to do if there are processes left in the previous runlevel */
+ return;
+
debug (1, (_("managing sleeping/stopping components")));
@@ -2256,2 +2259,5 @@ progman_cleanup (int expect_term)
int status;
+
+ if (!expect_term)
+ expect_term = progman_waiting_p ();
while ((pid = waitpid (-1, &status, WNOHANG)) > 0)
@@ -2306,2 +2312,3 @@ progman_cleanup (int expect_term)
prog->v.p.status = status_finished;
+ prog->v.p.wait = 0;
}

Return to:

Send suggestions and report system problems to the System administrator.