Welcome to little lamb

Code » anopa » commit 613dc22

stop: Tweak --skip with --all

author Olivier Brunel
2015-11-21 16:39:56 UTC
committer Olivier Brunel
2015-11-24 13:08:46 UTC
parent 5e539166c25af9d5e6d4af7262d40ee13b855f96

stop: Tweak --skip with --all

Instead of just ignoring the service altogether, in stop-all mode we only send
'x' to s6-supervise, so stopping the service next will have its supervisor exit
as well.

doc/aa-stop.pod +3 -2
src/anopa/aa-stop.c +14 -5
src/scripts/aa-stage3 +3 -4

diff --git a/doc/aa-stop.pod b/doc/aa-stop.pod
index 1452573..5384f74 100644
--- a/doc/aa-stop.pod
+++ b/doc/aa-stop.pod
@@ -36,8 +36,9 @@ Show help screen and exit.
 =item B<-k, --skip> I<service>
 
 If I<service> was asked to be stopped, silently ignore it. This is intended for
-use alongside B<--all> to keep the catch-all logger service running as long as
-possible (It will be stopped when sending SIGTERM to all running processes.).
+use alongside B<--all --all> to keep the catch-all logger service running as
+long as possible. Its B<s6-supervise> will only be sent an 'x' command, so
+stopping the service next will automatically have its supervisor exit as well.
 
 =item B<-l, --listdir> I<dir>
 
diff --git a/src/anopa/aa-stop.c b/src/anopa/aa-stop.c
index 050f62d..40f6ff4 100644
--- a/src/anopa/aa-stop.c
+++ b/src/anopa/aa-stop.c
@@ -85,9 +85,6 @@ preload_service (const char *name)
     int type;
     int r;
 
-    if (skip && str_equal (name, skip))
-        return 0;
-
     type = aa_get_service (name, &si, 0);
     if (type < 0)
         r = type;
@@ -430,8 +427,20 @@ main (int argc, char * const argv[])
 
             if (aa_service (si)->ls == AA_LOAD_DONE)
             {
-                add_to_list (&aa_main_list, si, 0);
-                remove_from_list (&aa_tmp_list, si);
+                if (!skip || !str_equal (aa_service_name (aa_service (si)), skip))
+                {
+                    add_to_list (&aa_main_list, si, 0);
+                    remove_from_list (&aa_tmp_list, si);
+                }
+                else
+                {
+                    ++i;
+                    if (skip)
+                        skip = NULL;
+
+                    if (mode & AA_MODE_STOP_ALL)
+                        stop_supervise_for (si);
+                }
             }
             else
             {
diff --git a/src/scripts/aa-stage3 b/src/scripts/aa-stage3
index 25cab4d..52ef40a 100755
--- a/src/scripts/aa-stage3
+++ b/src/scripts/aa-stage3
@@ -43,11 +43,10 @@ redirfd -w 1 /dev/console
 foreground { aa-echo -DB "Stage 3: Preparing ${1}..." }
 # Stop all running services -- s6-svscan did only exec into us, leaving the
 # whole supervised tree intact. Here we stop everything (longrun & oneshot) in
-# order.
+# order, save for the catch-all (it will get an 'x' though).
 foreground { emptyenv -c s6-setsid aa-ctty -Ds aa-stop -D -aak uncaught-logs }
-# We left the catch-all running (in case), make sure everything will exit
-# properly when we send TERM
-foreground { s6-svc -x /run/services/uncaught-logs }
+# Now stop the catch-all logger (its supervisor will then exit)
+foreground { emptyenv -c s6-setsid aa-stop -D uncaught-logs }
 
 # Kill everything left
 foreground { aa-echo -DB "Killing remaining processes..." }