aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-02-19 08:41:12 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-02-19 08:41:12 +0200
commite6902abfddb4d7b16dc9a4231a3781f354a08cd5 (patch)
treec634621af2ae765460e010ce83c8492ed4e859bc /src
parent51a797445a4bfc34ad1ae7ea91e12486d823abda (diff)
downloadpies-e6902abfddb4d7b16dc9a4231a3781f354a08cd5.tar.gz
pies-e6902abfddb4d7b16dc9a4231a3781f354a08cd5.tar.bz2
Revamp program termination after reconfiguring.
* src/pies.h (PIES_CHLD_GC): New op. (progman_stop_tag): Remove proto. * src/pies.c (main): Handle PIES_CHLD_GC: stop all programs marked for termination. * src/comp.c (component_config_commit): Mark leftover components for termination, instead of waiting for them to terminate. * src/sysvinit.c (runlevel_setup_prog): Skip prog if its active status didn't change. Mark inactivated progs for termination. (sysvinit_runlevel_setup): Schedule PIES_CHLD_GC. (inittrans): Don't wait for programs to terminate. That will be done in the main loop. * src/prog.h (prog)<stop>: New boolean member. * src/progman.c (progman_cleanup) (progman_stop_component): Clear the stop flag. (progman_gc): New function. (progman_stop_tag): Remove.
Diffstat (limited to 'src')
-rw-r--r--src/comp.c32
-rw-r--r--src/pies.c2
-rw-r--r--src/pies.h2
-rw-r--r--src/prog.h5
-rw-r--r--src/progman.c89
-rw-r--r--src/sysvinit.c42
6 files changed, 99 insertions, 73 deletions
diff --git a/src/comp.c b/src/comp.c
index 6a0e4ba..b340abe 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -360,8 +360,8 @@ prog_is_leftover (struct prog *prog)
-/* If PROG is a leftover, gracefully stop it and mark as disabled */
+/* If PROG is a leftover, mark it for termination */
static int
-cb_terminate_prog (struct prog *prog, void *data)
+mark_prog (struct prog *prog, void *data)
{
if (prog_is_leftover (prog))
- progman_stop_component (&prog);
+ prog->v.p.stop = 1;
return 0;
@@ -369,18 +369,2 @@ cb_terminate_prog (struct prog *prog, void *data)
-/* If PROG is a leftover, slay it with SIGKILL */
-static int
-cb_kill_prog (struct prog *prog, void *data)
-{
- if (prog_is_leftover (prog))
- prog_stop (prog, SIGKILL);
- return 0;
-}
-
-static int
-list_is_empty (void *p)
-{
- struct complist *list = p;
- return list->head == NULL;
-}
-
static int
@@ -506,3 +490,3 @@ component_config_commit (void)
- /* Terminate orphaned progs */
+ /* Mark orphaned progs for termination */
list = &comp_list[prev];
@@ -510,8 +494,4 @@ component_config_commit (void)
{
- progman_foreach (cb_terminate_prog, NULL);
- if (progman_wait_until (list_is_empty, list))
- {
- progman_foreach (cb_kill_prog, NULL);
- progman_wait_until (list_is_empty, list);
- }
+ progman_foreach (mark_prog, NULL);
+ pies_schedule_children (PIES_CHLD_GC);
}
diff --git a/src/pies.c b/src/pies.c
index 046f681..cb4d2f5 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -2223,2 +2223,4 @@ main (int argc, char **argv)
{
+ if (children_op & PIES_CHLD_GC)
+ progman_gc ();
if (children_op & PIES_CHLD_CLEANUP)
diff --git a/src/pies.h b/src/pies.h
index 9a3dfca..b61e11b 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -320,2 +320,3 @@ void free_action (struct action *act);
#define PIES_CHLD_WAKEUP 0x02
+#define PIES_CHLD_GC 0x04
@@ -332,3 +333,2 @@ void progman_filter (int (*filter) (struct component *, void *data),
int progman_wait_until (int (*cond) (void *), void *data);
-void progman_stop_tag (const char *name);
int progman_accept (int socket, void *data);
diff --git a/src/prog.h b/src/prog.h
index 316a229..4e86596 100644
--- a/src/prog.h
+++ b/src/prog.h
@@ -53,4 +53,5 @@ struct prog
struct component *comp;
- int wait :1;
- int active :1;
+ int active :1; /* The prog is active */
+ int wait :1; /* Wait for this prog to terminate */
+ int stop :1; /* Stop this prog */
int socket;
diff --git a/src/progman.c b/src/progman.c
index da5a970..52c875f 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -954,3 +954,2 @@ check_connection_rate (struct prog *prog)
-
static int
@@ -1475,3 +1474,2 @@ progman_create_sockets ()
-
void
@@ -1511,4 +1509,2 @@ progman_recompute_alarm ()
-
-
void
@@ -2317,2 +2313,3 @@ progman_cleanup (int expect_term)
print_status (prog_tag (prog), pid, status, expect_term);
+ prog->v.p.stop = 0;
if (prog->v.p.comp->mode == pies_comp_inetd)
@@ -2420,2 +2417,3 @@ progman_stop_component (struct prog **progptr)
case status_stopped:
+ prog->v.p.stop = 0;
if (!component_is_active (prog->v.p.comp))
@@ -2427,2 +2425,4 @@ progman_stop_component (struct prog **progptr)
destroy_prog (progptr);
+ else if (prog->v.p.stop)
+ prog->v.p.stop = 0;
else
@@ -2434,3 +2434,7 @@ progman_stop_component (struct prog **progptr)
- default:
+ case status_stopping:
+ break;
+
+ case status_finished:
+ prog->v.p.stop = 0;
if (!component_is_active (prog->v.p.comp))
@@ -2481,8 +2485,79 @@ prog_activate_listener (struct prog *prog)
+/* Starting at PROG, find first program component marked for termination. */
+static struct prog *
+prog_to_stop (struct prog *prog)
+{
+ for (; prog; prog = prog->next)
+ if (IS_COMPONENT (prog) && prog->v.p.stop)
+ break;
+ return prog;
+}
+
+#define DIAG_CON \
+ (init_process ? (DIAG_TO_STDERR|DIAG_REOPEN_LOG) : diag_output)
+
+/* Stop all program components marked for termination. Wait at most
+ 2*shutdown_timeout seconds. */
void
-progman_stop_tag (const char *name)
+progman_gc ()
+{
+ time_t start;
+ struct prog *prog, *next;
+
+ /* Find first marked prog */
+ prog = prog_to_stop (proghead);
+ if (!prog)
+ return;
+
+ /* First round: */
+ /* Gracefully stop it and all marked programs that follow */
+ diagmsg (DIAG_CON, LOG_INFO, "Sending processes the TERM signal");
+ start = time (NULL);
+ do
{
- struct prog *prog = progman_locate (name);
+ next = prog->next;
progman_stop_component (&prog);
}
+ while ((prog = prog_to_stop (next)));
+
+ /* Wait for them to terminate */
+ while (1)
+ {
+ progman_cleanup (1);
+ prog = prog_to_stop (proghead);
+ if (!prog)
+ return;
+ if (time (NULL) - start < shutdown_timeout)
+ sleep (1);
+ else
+ break;
+ }
+
+ /* Second round: */
+ /* Kill the remaining programs with SIGKILL */
+ diagmsg (DIAG_CON, LOG_INFO, "Sending processes the KILL signal");
+ start = time (NULL);
+ do
+ {
+ next = prog->next;
+ prog_stop (prog, SIGKILL);
+ }
+ while ((prog = prog_to_stop (next)));
+
+ /* Wait for them to terminate */
+ while (1)
+ {
+ progman_cleanup (1);
+ prog = prog_to_stop (proghead);
+ if (!prog)
+ return;
+ if (time (NULL) - start < shutdown_timeout)
+ sleep (1);
+ else
+ break;
+ }
+
+ /* FIXME: Report remaining programs */
+
+}
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 6276228..41d5b9d 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -64,3 +64,2 @@ int emergency_shell;
-#define DIAG_CON (DIAG_TO_STDERR|DIAG_REOPEN_LOG)
@@ -284,3 +283,3 @@ runlevel_setup_prog (struct prog *prog, void *data)
int rc = enablecomp (prog, data);
- if (rc < 0)
+ if (rc < 0 || prog->v.p.active == rc)
return 0;
@@ -289,2 +288,5 @@ runlevel_setup_prog (struct prog *prog, void *data)
prog->v.p.wait = is_comp_wait (prog->v.p.comp);
+ else if (prog->v.p.status != status_stopped
+ && prog->v.p.status != status_finished)
+ prog->v.p.stop = 1;
debug (2, ("%s: %s%s", prog_tag (prog),
@@ -303,2 +305,3 @@ sysvinit_runlevel_setup (int mask)
progman_foreach (runlevel_setup_prog, &s);
+ pies_schedule_children (PIES_CHLD_GC);
}
@@ -765,22 +768,2 @@ sysvinit_begin ()
-static int
-cond_running_disabled (struct prog *prog, void *data)
-{
- return IS_RUNNING_DISABLED_PROG (prog);
-}
-
-static int
-no_disabled_running (void *data)
-{
- return !progman_foreach (cond_running_disabled, NULL);
-}
-
-static int
-terminate_disabled (struct prog *prog, void *data)
-{
- if (IS_RUNNING_DISABLED_PROG (prog))
- prog_stop (prog, *(int*)data);
- return 0;
-}
-
int
@@ -846,19 +829,4 @@ inittrans ()
{
- int sig;
-
envsetup ();
sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
-
- /* Stop disabled programs */
- sig = SIGTERM;
- diagmsg (DIAG_CON, LOG_INFO, "Sending processes the TERM signal");
- progman_foreach (terminate_disabled, &sig);
- if (progman_wait_until (no_disabled_running, NULL))
- {
- sig = SIGKILL;
- diagmsg (DIAG_CON, LOG_INFO, "Sending processes the KILL signal");
- progman_foreach (terminate_disabled, &sig);
- progman_wait_until (no_disabled_running, NULL);
- }
-
pies_schedule_children (PIES_CHLD_WAKEUP);

Return to:

Send suggestions and report system problems to the System administrator.