RFC tmpfiles: Allow configuration to ignore execution errors
authorWilliam Douglas <william.douglas@intel.com>
Mon, 10 Sep 2018 19:07:29 +0000 (12:07 -0700)
committerLennart Poettering <lennart@poettering.net>
Tue, 25 Sep 2018 21:30:30 +0000 (23:30 +0200)
This is an implementation that covers making errors encountered when writing
file content optionally fatal. If this is something that folks would want I'll
add handling of this for all the other directives. I'd appreciate suggestions
on how this might better be structured as well (use of a goto fail or such) as
I'm not super happy with the approach.

man/tmpfiles.d.xml
src/tmpfiles/tmpfiles.c

index 9f3660b..9907dc6 100644 (file)
@@ -116,7 +116,7 @@ L     /tmp/foobar -    -    -    -   /dev/null</programlisting>
       <title>Type</title>
 
       <para>The type consists of a single letter and optionally an
-      exclamation mark.</para>
+      exclamation mark and/or minus sign.</para>
 
       <para>The following line types are understood:</para>
 
@@ -439,6 +439,15 @@ r! /tmp/.X[0-9]*-lock</programlisting>
       running system, and will only be executed with
       <option>--boot</option>.</para>
 
+      <para>If the minus sign is used, this line failing to run
+      successfully during create (and only create) will not cause
+      the execution of <command>systemd-tmpfiles</command> to return
+      an error.</para>
+
+      <para>For example:
+      <programlisting># Modify sysfs but don't fail if we are in a container with a read-only /proc
+w- /proc/sys/vm/swappiness - - - - 10</programlisting></para>
+
       <para>Note that for all line types that result in creation of any kind of file node
       (i.e. <varname>f</varname>/<varname>F</varname>,
       <varname>d</varname>/<varname>D</varname>/<varname>v</varname>/<varname>q</varname>/<varname>Q</varname>,
index e29f706..e994be6 100644 (file)
@@ -128,6 +128,8 @@ typedef struct Item {
 
         bool force:1;
 
+        bool allow_failure:1;
+
         bool done:1;
 } Item;
 
@@ -2271,6 +2273,9 @@ static int process_item(Item *i) {
         r = arg_create ? create_item(i) : 0;
         q = arg_remove ? remove_item(i) : 0;
         p = arg_clean ? clean_item(i) : 0;
+        /* Failure can only be tolerated for create */
+        if (i->allow_failure)
+                r = 0;
 
         return t < 0 ? t :
                 r < 0 ? r :
@@ -2474,7 +2479,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
         ItemArray *existing;
         OrderedHashmap *h;
         int r, pos;
-        bool force = false, boot = false;
+        bool force = false, boot = false, allow_failure = false;
 
         assert(fname);
         assert(line >= 1);
@@ -2519,6 +2524,8 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
                         boot = true;
                 else if (action[pos] == '+' && !force)
                         force = true;
+                else if (action[pos] == '-' && !allow_failure)
+                        allow_failure = true;
                 else {
                         *invalid_config = true;
                         log_error("[%s:%u] Unknown modifiers in command '%s'",
@@ -2535,6 +2542,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
 
         i.type = action[0];
         i.force = force;
+        i.allow_failure = allow_failure;
 
         r = specifier_printf(path, specifier_table, NULL, &i.path);
         if (r == -ENXIO)