aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-05-24 17:07:22 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-05-24 17:10:34 +0300
commita8d45eff28e7e186d0749e3e9cf980a23d93231e (patch)
tree50eb85966b6d87f73128728dab876e36dcc67799 /src
parent2ba31eb953d18bb818a87caddcbca80bc8a1d37d (diff)
downloadpies-a8d45eff28e7e186d0749e3e9cf980a23d93231e.tar.gz
pies-a8d45eff28e7e186d0749e3e9cf980a23d93231e.tar.bz2
Implement shutdown components
* src/pies.h: Update comment. * src/progman.c (register_prog0): Register shutdown components in disabled state. (program_shutdown): New function. (progman_stop): Call program_shutdown. * tests/shutdown.at: New test. * tests/Makefile.am: Add new test. * tests/testsuite.at: Likewise. * tests/aux/startup: Rename to tests/aux/touchfile * tests/startup.at: Reflect the change.
Diffstat (limited to 'src')
-rw-r--r--src/pies.h5
-rw-r--r--src/progman.c74
2 files changed, 62 insertions, 17 deletions
diff --git a/src/pies.h b/src/pies.h
index bdc406b..74cb346 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -142,7 +142,10 @@ enum pies_comp_mode
components is delayed until the last startup component finishes. */
pies_comp_startup,
- /* FIXME: Runs before program termination */
+ /* Components of this type are run right before program termination.
+ They have shutdown_timeout seconds to finish their job and terminate
+ gracefully, othervise they will be terminated forcefully via SIGTERM
+ (and SIGKILL, for persisting ones). */
pies_comp_shutdown,
/*
diff --git a/src/progman.c b/src/progman.c
index a625885..bae82ba 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -287,7 +287,9 @@ register_prog0 (struct component *comp)
else
newp->v.p.status = status_stopped;
- if ((comp->flags & CF_DISABLED) || comp->mode == pies_comp_ondemand)
+ if ((comp->flags & CF_DISABLED)
+ || comp->mode == pies_comp_ondemand
+ || comp->mode == pies_comp_shutdown)
newp->active = 0;
else
newp->active = 1;
@@ -1795,21 +1797,6 @@ prog_stop (struct prog *prog, int sig)
kill (prog->pid, sig);
}
-static int
-mark_for_stopping (struct prog *prog, void *data)
-{
- if (IS_COMPONENT (prog))
- prog->stop = 1;
- return 0;
-}
-
-void
-progman_stop (void)
-{
- progman_foreach (mark_for_stopping, NULL);
- progman_gc ();
-}
-
static void
print_status (const char *tag, pid_t pid, int status, int expect_term)
{
@@ -2582,4 +2569,59 @@ progman_gc (void)
}
+static int
+start_shutdown (struct prog *prog, void *data)
+{
+ if (IS_COMPONENT (prog) && prog->v.p.comp->mode == pies_comp_shutdown)
+ {
+ int *p = data;
+ if (!*p)
+ {
+ diagmsg (DIAG_CON, LOG_INFO, "Starting shutdown components");
+ *p = 1;
+ }
+ prog->active = 1;
+ prog_start (prog);
+ prog->stop = 1;
+ }
+ return 0;
+}
+
+void
+program_shutdown (void)
+{
+ time_t start = time (NULL);
+ int sd = 0;
+
+ /* Activate shutdown components. */
+ progman_foreach (start_shutdown, &sd);
+ while (prog_to_stop (proghead))
+ {
+ progman_cleanup (1);
+ if (time (NULL) - start < shutdown_timeout)
+ sleep (1);
+ else
+ {
+ progman_gc ();
+ break;
+ }
+ }
+}
+
+static int
+mark_for_stopping (struct prog *prog, void *data)
+{
+ if (IS_COMPONENT (prog))
+ prog->stop = 1;
+ return 0;
+}
+
+void
+progman_stop (void)
+{
+ progman_foreach (mark_for_stopping, NULL);
+ progman_gc ();
+ program_shutdown ();
+}
+
/* EOF */

Return to:

Send suggestions and report system problems to the System administrator.