Welcome to little lamb

Code » anopa » commit fa5592e

enable: Add --skip-down

author Olivier Brunel
2015-02-13 20:07:08 UTC
committer Olivier Brunel
2015-04-04 12:47:33 UTC
parent de437c92357f5f37006c5a4d59aa1d1bb1743029

enable: Add --skip-down

For catch-all logger, to be started by s6-svscan & trigger stage 2.

doc/aa-enable.pod +12 -4
src/anopa/aa-enable.c +24 -13
src/include/anopa/enable_service.h +5 -4
src/libanopa/enable_service.c +6 -0

diff --git a/doc/aa-enable.pod b/doc/aa-enable.pod
index b5c7083..80efa7a 100644
--- a/doc/aa-enable.pod
+++ b/doc/aa-enable.pod
@@ -4,7 +4,7 @@ aa-enable - Enable services, i.e. copy servicedirs to repodir
 
 =head1 SYNOPSIS
 
-B<aa-enable> [B<-D>] [B<-r> I<repodir>] [B<-S> I<sourcedir>]
+B<aa-enable> [B<-D>] [B<-r> I<repodir>] [B<-k> I<service>] [B<-S> I<sourcedir>]
 [B<-s> I<sourcedir>] [B<-l> I<listdir>] [B<-n>] [B<-w>] [I<service...>]
 
 =head1 OPTIONS
@@ -22,6 +22,13 @@ shown on console and logged.
 
 Show help screen and exit.
 
+=item B<-k, --skip-down> I<service>
+
+When (if) enabling I<service> do not create a file I<down> even it there's none
+and it is a longrun service. This is intended to be used during stage 1, for
+the catch-all logger service, which needs to be started automatically by
+B<s6-svscan> (to unblock & trigger stage 2).
+
 =item B<-l, --listdir> I<dir>
 
 Use I<dir> to list services to enable. Only one can be set, if specified more
@@ -94,9 +101,10 @@ merged/copied over into the servicedir. This allows to specify service-specific
 configuration, or could possibly be used to overwrite an actual script.
 
 - If the service is a long-run, an empty regular file I<down> is created (unless
-it already existed) to ensure the service won't be auto-started by B<s6-svscan>,
-and a symlink is added to the servicedir into the I<.scandir> sub-directory of
-I<repodir>.
+it already existed, or the service was specified to B<--skip-down>) to ensure
+the service won't be auto-started by B<s6-svscan>, and a symlink is added to the
+servicedir into the I<.scandir> sub-directory of I<repodir> (even if the service
+was specified to B<--skip-down>).
 
 =head2 Special case: Instances
 
diff --git a/src/anopa/aa-enable.c b/src/anopa/aa-enable.c
index b0d4447..2dea2b2 100644
--- a/src/anopa/aa-enable.c
+++ b/src/anopa/aa-enable.c
@@ -38,6 +38,7 @@ static stralloc names = STRALLOC_ZERO;
 static int nb_enabled = 0;
 static genalloc ga_failed = GENALLOC_ZERO;
 static genalloc ga_next = GENALLOC_ZERO;
+static const char *skip = NULL;
 
 static void
 warn_cb (const char *name, int err)
@@ -86,7 +87,10 @@ enable_service (const char *name, int from_next)
     else
         offset = from_next - 1;
 
+    if (skip && str_equal (cur_name, skip))
+        flags |= AA_FLAG_SKIP_DOWN;
     r = aa_enable_service (name, warn_cb, flags, ae_cb);
+    flags &= ~AA_FLAG_SKIP_DOWN;
     if (r < 0)
     {
         int e = errno;
@@ -136,6 +140,7 @@ dieusage (void)
             " -r, --repodir DIR             Use DIR as repository directory\n"
             " -S, --reset-source DIR        Reset list of source directories to DIR\n"
             " -s, --source DIR              Add DIR as source directories\n"
+            " -k, --skip-down SERVICE       Don't create file 'down' for SERVICE\n"
             " -l, --listdir DIR             Use DIR to list services to enable\n"
             " -n, --no-needs                Don't auto-enable services from 'needs'\n"
             " -w, --no-wants                Don't auto-enable services from 'wants'\n"
@@ -162,20 +167,21 @@ main (int argc, char * const argv[])
     for (;;)
     {
         struct option longopts[] = {
-            { "help",               no_argument,        NULL,   'h' },
-            { "version",            no_argument,        NULL,   'V' },
             { "double-output",      no_argument,        NULL,   'D' },
-            { "repodir",            required_argument,  NULL,   'r' },
+            { "help",               no_argument,        NULL,   'h' },
+            { "skip-down",          required_argument,  NULL,   'k' },
             { "listdir",            required_argument,  NULL,   'l' },
-            { "source",             required_argument,  NULL,   's' },
-            { "reset-source",       required_argument,  NULL,   'S' },
             { "no-needs",           no_argument,        NULL,   'n' },
+            { "repodir",            required_argument,  NULL,   'r' },
+            { "reset-source",       required_argument,  NULL,   'S' },
+            { "source",             required_argument,  NULL,   's' },
+            { "version",            no_argument,        NULL,   'V' },
             { "no-wants",           no_argument,        NULL,   'w' },
             { NULL, 0, 0, 0 }
         };
         int c;
 
-        c = getopt_long (argc, argv, "hVDr:l:s:S:nw", longopts, NULL);
+        c = getopt_long (argc, argv, "Dhk:l:nr:S:s:vw", longopts, NULL);
         if (c == -1)
             break;
         switch (c)
@@ -184,9 +190,8 @@ main (int argc, char * const argv[])
                 mode_both = 1;
                 break;
 
-            case 'r':
-                unslash (optarg);
-                path_repo = optarg;
+            case 'k':
+                skip = optarg;
                 break;
 
             case 'l':
@@ -194,6 +199,15 @@ main (int argc, char * const argv[])
                 path_list = optarg;
                 break;
 
+            case 'n':
+                flags &= ~AA_FLAG_AUTO_ENABLE_NEEDS;
+                break;
+
+            case 'r':
+                unslash (optarg);
+                path_repo = optarg;
+                break;
+
             case 'S':
                 aa_sa_sources.len = 0;
                 /* fall through */
@@ -204,10 +218,6 @@ main (int argc, char * const argv[])
                     strerr_diefu1sys (1, "stralloc_catb");
                 break;
 
-            case 'n':
-                flags &= ~AA_FLAG_AUTO_ENABLE_NEEDS;
-                break;
-
             case 'w':
                 flags &= ~AA_FLAG_AUTO_ENABLE_WANTS;
                 break;
@@ -215,6 +225,7 @@ main (int argc, char * const argv[])
             case 'V':
                 aa_die_version ();
 
+            case 'h':
             default:
                 dieusage ();
         }
diff --git a/src/include/anopa/enable_service.h b/src/include/anopa/enable_service.h
index f1fbbeb..11031ec 100644
--- a/src/include/anopa/enable_service.h
+++ b/src/include/anopa/enable_service.h
@@ -9,11 +9,12 @@ typedef enum
 {
     AA_FLAG_AUTO_ENABLE_NEEDS   = (1 << 0),
     AA_FLAG_AUTO_ENABLE_WANTS   = (1 << 1),
+    AA_FLAG_SKIP_DOWN           = (1 << 2),
     /* private */
-    _AA_FLAG_IS_SERVICEDIR      = (1 << 2),
-    _AA_FLAG_IS_NEEDS           = (1 << 3),
-    _AA_FLAG_IS_WANTS           = (1 << 4),
-    _AA_FLAG_IS_BEF_AFT         = (1 << 5),
+    _AA_FLAG_IS_SERVICEDIR      = (1 << 3),
+    _AA_FLAG_IS_NEEDS           = (1 << 4),
+    _AA_FLAG_IS_WANTS           = (1 << 5),
+    _AA_FLAG_IS_BEF_AFT         = (1 << 6),
     _AA_FLAG_IS_1OF4            = _AA_FLAG_IS_NEEDS | _AA_FLAG_IS_WANTS | _AA_FLAG_IS_BEF_AFT
 } aa_enable_flags;
 
diff --git a/src/libanopa/enable_service.c b/src/libanopa/enable_service.c
index edfa28a..f468c76 100644
--- a/src/libanopa/enable_service.c
+++ b/src/libanopa/enable_service.c
@@ -136,6 +136,12 @@ copy_dir (const char        *src,
     dir = opendir (src);
     if (!dir)
         return -ERR_IO;
+
+    if (depth == 0 && (flags & (_AA_FLAG_IS_SERVICEDIR | AA_FLAG_SKIP_DOWN))
+            == (_AA_FLAG_IS_SERVICEDIR | AA_FLAG_SKIP_DOWN))
+        /* treat as if there'e one, so don't create it */
+        has.down = 1;
+
     errno = 0;
     for (;;)
     {