aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pies.h5
-rw-r--r--src/progman.c74
-rw-r--r--tests/Makefile.am3
-rwxr-xr-xtests/aux/touchfile (renamed from tests/aux/startup)0
-rw-r--r--tests/shutdown.at58
-rw-r--r--tests/startup.at4
-rw-r--r--tests/testsuite.at1
7 files changed, 125 insertions, 20 deletions
diff --git a/src/pies.h b/src/pies.h
index bdc406b..74cb346 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -144,3 +144,6 @@ enum pies_comp_mode
144 144
145 /* FIXME: Runs before program termination */ 145 /* Components of this type are run right before program termination.
146 They have shutdown_timeout seconds to finish their job and terminate
147 gracefully, othervise they will be terminated forcefully via SIGTERM
148 (and SIGKILL, for persisting ones). */
146 pies_comp_shutdown, 149 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
@@ -289,3 +289,5 @@ register_prog0 (struct component *comp)
289 289
290 if ((comp->flags & CF_DISABLED) || comp->mode == pies_comp_ondemand) 290 if ((comp->flags & CF_DISABLED)
291 || comp->mode == pies_comp_ondemand
292 || comp->mode == pies_comp_shutdown)
291 newp->active = 0; 293 newp->active = 0;
@@ -1797,17 +1799,2 @@ prog_stop (struct prog *prog, int sig)
1797 1799
1798static int
1799mark_for_stopping (struct prog *prog, void *data)
1800{
1801 if (IS_COMPONENT (prog))
1802 prog->stop = 1;
1803 return 0;
1804}
1805
1806void
1807progman_stop (void)
1808{
1809 progman_foreach (mark_for_stopping, NULL);
1810 progman_gc ();
1811}
1812
1813static void 1800static void
@@ -2584,2 +2571,57 @@ progman_gc (void)
2584 2571
2572static int
2573start_shutdown (struct prog *prog, void *data)
2574{
2575 if (IS_COMPONENT (prog) && prog->v.p.comp->mode == pies_comp_shutdown)
2576 {
2577 int *p = data;
2578 if (!*p)
2579 {
2580 diagmsg (DIAG_CON, LOG_INFO, "Starting shutdown components");
2581 *p = 1;
2582 }
2583 prog->active = 1;
2584 prog_start (prog);
2585 prog->stop = 1;
2586 }
2587 return 0;
2588}
2589
2590void
2591program_shutdown (void)
2592{
2593 time_t start = time (NULL);
2594 int sd = 0;
2595
2596 /* Activate shutdown components. */
2597 progman_foreach (start_shutdown, &sd);
2598 while (prog_to_stop (proghead))
2599 {
2600 progman_cleanup (1);
2601 if (time (NULL) - start < shutdown_timeout)
2602 sleep (1);
2603 else
2604 {
2605 progman_gc ();
2606 break;
2607 }
2608 }
2609}
2610
2611static int
2612mark_for_stopping (struct prog *prog, void *data)
2613{
2614 if (IS_COMPONENT (prog))
2615 prog->stop = 1;
2616 return 0;
2617}
2618
2619void
2620progman_stop (void)
2621{
2622 progman_foreach (mark_for_stopping, NULL);
2623 progman_gc ();
2624 program_shutdown ();
2625}
2626
2585/* EOF */ 2627/* EOF */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b2f2719..b404ed4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -20,3 +20,3 @@ AUXTOOLS = \
20 aux/mailer\ 20 aux/mailer\
21 aux/startup 21 aux/touchfile
22 22
@@ -55,2 +55,3 @@ TESTSUITE_AT = \
55 startup.at\ 55 startup.at\
56 shutdown.at\
56 version.at 57 version.at
diff --git a/tests/aux/startup b/tests/aux/touchfile
index b9d92a3..b9d92a3 100755
--- a/tests/aux/startup
+++ b/tests/aux/touchfile
diff --git a/tests/shutdown.at b/tests/shutdown.at
new file mode 100644
index 0000000..79bec37
--- /dev/null
+++ b/tests/shutdown.at
@@ -0,0 +1,58 @@
1# This file is part of GNU pies testsuite. -*- Autotest -*-
2# Copyright (C) 2019 Sergey Poznyakoff
3#
4# GNU pies is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# GNU pies is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([Shutdown components])
18
19AT_CHECK([
20PIES_XFAIL_CHECK
21PIES_CONTROL_INIT
22comp_pid_file=$PWD/comp.pid
23
24cat > pies.conf <<_EOT
25component s {
26 mode shutdown;
27 command "$auxdir/touchfile $PWD 0 shutdown";
28}
29
30component test {
31 mode respawn;
32 command "$auxdir/respawn -append -pid $comp_pid_file";
33}
34_EOT
35
36pies --config-file control.conf --config-file pies.conf
37
38n=0
39while :
40do
41 if test -f $comp_pid_file; then
42 break
43 fi
44 sleep 1
45 n=$(($n + 1))
46 if test $n -gt 10; then
47 echo >&2 "timed out"
48 break
49 fi
50done
51
52PIES_STOP
53
54test -f shutdown
55])
56
57AT_CLEANUP
58
diff --git a/tests/startup.at b/tests/startup.at
index 72017ce..440c249 100644
--- a/tests/startup.at
+++ b/tests/startup.at
@@ -26,3 +26,3 @@ component b1 {
26 mode startup; 26 mode startup;
27 command "$auxdir/startup $PWD 1 b1"; 27 command "$auxdir/touchfile $PWD 1 b1";
28} 28}
@@ -31,3 +31,3 @@ component b2 {
31 mode startup; 31 mode startup;
32 command "$auxdir/startup $PWD 2 b2"; 32 command "$auxdir/touchfile $PWD 2 b2";
33} 33}
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 2a1167d..6775ee7 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -68 +68,2 @@ m4_include([ret-notify.at])
68m4_include([startup.at]) 68m4_include([startup.at])
69m4_include([shutdown.at])

Return to:

Send suggestions and report system problems to the System administrator.