Welcome to little lamb

Code » anopa » commit 3dfe850

enable: Add log/run-args to append content to log/run

author Olivier Brunel
2015-03-16 17:54:51 UTC
committer Olivier Brunel
2015-04-04 12:47:36 UTC
parent f1b36d5f7f4e7e367a380d6385d93edcf6eaf204

enable: Add log/run-args to append content to log/run

This allows to append directives to logger's logging script without
parsing issues nor having to supply the full logger/run script.

doc/aa-enable.pod +17 -0
src/libanopa/enable_service.c +28 -0

diff --git a/doc/aa-enable.pod b/doc/aa-enable.pod
index 4a271e9..620d4c2 100644
--- a/doc/aa-enable.pod
+++ b/doc/aa-enable.pod
@@ -119,6 +119,10 @@ 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>).
 
+- As last step, B<aa-enable>(1) will check if a regular file I<log/run-args>
+exists in the newly created servicedir, and if so its content will be appended
+to I<log/run>
+
 =head2 Special case: Instances
 
 Service names cannot start nor end with a @ character, but can contain one.
@@ -162,6 +166,19 @@ Note that you can also still provide files from the configuration directory in
 listdir, since it is copied last (and that this always includes providing a new
 I<run> file).
 
+Lastly, B<aa-enable>(1)'s last step when creating a servicedir is to check for a
+regular file I<log/run-args> in the newly created servicedir, and if found to
+append its content to I<log/run>
+
+The idea is to allow to easily use the default logger, and yet be able to add
+e.g. directives to B<s6-log>'s loggin script. This could be particularly useful
+e.g. if the default logger does connect its stdout to a fifo, allowing you to
+select lines to write there (or to the logger's stderr).
+
+Note that since you can remove or append to files from configuration (directory
+in I<LISTDIR>; See below), you can either remove, rewrite or append to
+I<log/run-args> as needed before it is processed.
+
 =head2 Removing/appending to files
 
 When copying files from the "configuration directory" (directory in I<LISTDIR>)
diff --git a/src/libanopa/enable_service.c b/src/libanopa/enable_service.c
index e0d3922..f83fae8 100644
--- a/src/libanopa/enable_service.c
+++ b/src/libanopa/enable_service.c
@@ -475,7 +475,35 @@ aa_enable_service (const char       *_name,
         return r;
 
     if (name != _name)
+    {
         r = copy_dir (_name, name, _mode, 0, warn_fn, flags | _AA_FLAG_IS_CONFIGDIR, ae_cb, instance);
+        if (r < 0)
+            return r;
+    }
+
+    {
+        int l = sizeof ("/log/run-args");
+        char buf[l_name + l];
+        struct stat st;
+
+        byte_copy (buf, l_name, name);
+        byte_copy (buf + l_name, l, "/log/run-args");
+
+        r = stat (buf, &st);
+        if (r == 0 && S_ISREG (st.st_mode))
+        {
+            char dst[l_name + l - 5];
+
+            byte_copy (dst, l_name, name);
+            byte_copy (dst + l_name, l - 5, "/log/run");
+
+            r = aa_copy_file (buf, dst, st.st_mode, AA_CP_APPEND);
+            if (r == 0)
+                unlink (buf);
+        }
+        else if (r < 0 && errno == ENOENT)
+            r = 0;
+    }
 
     return r;
 }