aboutsummaryrefslogtreecommitdiff
path: root/src/progman.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-02-23 18:04:52 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-02-23 18:04:52 +0200
commitdd2c48ddfc7f8bc62c565b43bbd42a3a2a87836d (patch)
treec160c3d7af3a7709fb33224e8344caafe581fcc4 /src/progman.c
parent6e73a7b0822d1fd506c75a662070f447bba94afb (diff)
downloadpies-dd2c48ddfc7f8bc62c565b43bbd42a3a2a87836d.tar.gz
pies-dd2c48ddfc7f8bc62c565b43bbd42a3a2a87836d.tar.bz2
Bugfixes
* lib/addrfmt.c: Include limits.h * src/ctl.c (fun_stop,fun_start): Ignore non-component progs. * src/pies.c (request_restart_components): Fix piesctl invocation. * src/pies.h (PIES_CHLD_RESCHEDULE_ALARM): New flag. (progman_wait_until): Remove. (progman_recompute_alarm): New proto. * src/progman.c (recompute_alarm): Remove. All uses raise PIES_CHLD_RESCHEDULE_ALARM instead. (progman_wake_sleeping): Handle status_stopping components independently on their activity flag. (prog_stop_all, progman_wait_until): Remove. (progman_stop): Rewrite using mark+sweep approach.
Diffstat (limited to 'src/progman.c')
-rw-r--r--src/progman.c91
1 files changed, 25 insertions, 66 deletions
diff --git a/src/progman.c b/src/progman.c
index 547f806..2d3a14c 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -18,7 +18,6 @@
#include "prog.h"
static struct prog *proghead, *progtail;
-static int recompute_alarm;
static struct grecs_symtab *conn_tab;
struct prog *
@@ -908,7 +907,7 @@ check_rate (struct prog *prog, unsigned testtime, size_t max_count)
{
prog->v.p.timestamp = now;
prog->v.p.status = status_sleeping;
- recompute_alarm = 1;
+ pies_schedule_children (PIES_CHLD_RESCHEDULE_ALARM);
return 1;
}
@@ -1471,7 +1470,6 @@ progman_recompute_alarm ()
time_t now = time (NULL);
time_t alarm_time = 0, x;
- recompute_alarm = 0;
debug (2, ("Recomputing alarm settings"));
for (prog = proghead; prog; prog = prog->next)
if (IS_COMPONENT (prog))
@@ -1508,7 +1506,6 @@ progman_start ()
/* Noting to do if there are processes left in the previous runlevel */
return;
- recompute_alarm = 0;
debug (1, ("starting components"));
for (prog = proghead; prog; prog = prog->next)
if (IS_COMPONENT (prog))
@@ -1549,7 +1546,7 @@ check_stopping (struct prog *prog, time_t now)
kill (prog->pid, SIGKILL);
}
else
- recompute_alarm = 1;
+ pies_schedule_children (PIES_CHLD_RESCHEDULE_ALARM);
}
void
@@ -1574,11 +1571,11 @@ progman_wake_sleeping (int onalrm)
}
for (prog = proghead; prog; prog = prog->next)
- if (IS_ACTIVE_COMPONENT (prog))
+ switch (prog->v.p.status)
{
- switch (prog->v.p.status)
+ case status_sleeping:
+ if (IS_ACTIVE_COMPONENT (prog))
{
- case status_sleeping:
if (now - prog->v.p.timestamp >= SLEEPTIME)
{
if (prog->v.p.comp->mode == pies_comp_inetd)
@@ -1597,23 +1594,22 @@ progman_wake_sleeping (int onalrm)
/* If there is no alarm pending, recompute next alarm.
This allows to cope with eventual clock inaccuracies. */
if (onalrm)
- recompute_alarm = 1;
- break;
+ pies_schedule_children (PIES_CHLD_RESCHEDULE_ALARM);
+ }
+ break;
- case status_stopping:
- check_stopping (prog, now);
- break;
+ case status_stopping:
+ check_stopping (prog, now);
+ break;
- case status_stopped:
- prog_start (prog);
- break;
+ case status_stopped:
+ if (IS_ACTIVE_COMPONENT (prog))
+ prog_start (prog);
+ break;
- default:
- break;
- }
+ default:
+ break;
}
- if (recompute_alarm)
- progman_recompute_alarm ();
}
static int
@@ -1725,7 +1721,7 @@ prog_stop (struct prog *prog, int sig)
{
prog->v.p.status = status_stopping;
prog->v.p.timestamp = time (NULL);
- recompute_alarm = 1;
+ pies_schedule_children (PIES_CHLD_RESCHEDULE_ALARM);
}
}
debug (1, ("stopping %s (%lu)", prog_tag (prog), (unsigned long) prog->pid));
@@ -1735,56 +1731,19 @@ prog_stop (struct prog *prog, int sig)
kill (prog->pid, sig);
}
-static void
-prog_stop_all (int sig)
-{
- struct prog *prog;
-
- debug (1, ("stopping all components (signal %d)", sig));
- for (prog = progtail; prog; prog = prog->prev)
- if (IS_COMPONENT (prog)
- && (prog->v.p.status == status_running
- || prog->v.p.status == status_stopping))
- prog_stop (prog, sig);
-}
-
-int
-progman_wait_until (int (*cond) (void *), void *data)
-{
- time_t start = time (NULL);
-
- do
- {
- progman_cleanup (1);
- if (cond && cond (data))
- return 0;
- sleep (1);
- }
- while (time (NULL) - start < shutdown_timeout);
- return 1;
-}
-
static int
-no_children_left (void *p)
+mark_for_stopping (struct prog *prog, void *data)
{
- struct prog *prog;
-
- for (prog = proghead; prog; prog = prog->next)
- if (prog->pid > 0)
- return 0;
-
- return 1;
+ if (IS_COMPONENT (prog))
+ prog->v.p.stop = 1;
+ return 0;
}
void
-progman_stop ()
+progman_stop (void)
{
- prog_stop_all (SIGTERM);
- if (progman_wait_until (no_children_left, NULL))
- {
- prog_stop_all (SIGKILL);
- progman_wait_until (no_children_left, NULL);
- }
+ progman_foreach (mark_for_stopping, NULL);
+ progman_gc ();
}
static void

Return to:

Send suggestions and report system problems to the System administrator.