From 6d7b543342ba5e83a3da230200c357430ac0797b Mon Sep 17 00:00:00 2001 From: William Douglas Date: Mon, 10 Sep 2018 12:07:29 -0700 Subject: [PATCH] RFC tmpfiles: Allow configuration to ignore execution errors 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 | 11 ++++++++++- src/tmpfiles/tmpfiles.c | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml index 9f3660bd46..9907dc6b9a 100644 --- a/man/tmpfiles.d.xml +++ b/man/tmpfiles.d.xml @@ -116,7 +116,7 @@ L /tmp/foobar - - - - /dev/null Type The type consists of a single letter and optionally an - exclamation mark. + exclamation mark and/or minus sign. The following line types are understood: @@ -439,6 +439,15 @@ r! /tmp/.X[0-9]*-lock running system, and will only be executed with . + If the minus sign is used, this line failing to run + successfully during create (and only create) will not cause + the execution of systemd-tmpfiles to return + an error. + + For example: + # Modify sysfs but don't fail if we are in a container with a read-only /proc +w- /proc/sys/vm/swappiness - - - - 10 + Note that for all line types that result in creation of any kind of file node (i.e. f/F, d/D/v/q/Q, diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index e29f706fc0..e994be66df 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -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)