]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfiles: in C lines, make missing source graceful error
authorLennart Poettering <lennart@poettering.net>
Thu, 25 Aug 2022 15:16:02 +0000 (17:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 26 Aug 2022 09:11:48 +0000 (11:11 +0200)
I don't see where it would ever be a good thing that file copies done
via tmpfiles.d/ C lines cause the tmpfiles operation to fail if their
source happens to be missing. It's a problem if we can't set up the
destination properly (which is the job of systemd-tmpfiles after all),
but if the source is simply missing (NB: setting up the source is the job of
of the rules writer) this shouldn't be a problem.

This is useful for copying stuff into place if it happens to exist. For
example, if systemd-stub passes additional data into the initrd's
/.extra/ directory, we can copy it into a better place (e.g. /run/) with
this, where it will survive the initrd→host transition.

This mirrors behaviour of the recently added "^" line modifier which may
be used source "w" lines from credentials â€“ there two the behaviour is
to simply skip the line if the source is missing.

src/tmpfiles/tmpfiles.c
test/units/testsuite-22.02.sh

index 07432a1e51ecc0d34378da1aa2f2bb918255a783..4bbf9b4acee996a321cf0e1c2a3ba6a27b6e7e9e 100644 (file)
@@ -3153,6 +3153,13 @@ static int parse_line(
                 }
 
                 path_simplify(i.argument);
+
+                if (laccess(i.argument, F_OK) == -ENOENT) {
+                        /* Silently skip over lines where the source file is missing. */
+                        log_syntax(NULL, LOG_INFO, fname, line, 0, "Copy source path '%s' does not exist, skipping line.", i.argument);
+                        return 0;
+                }
+
                 break;
 
         case CREATE_CHAR_DEVICE:
index 0719d68292ba2665f4a24c5b184d935d413acc32..49c55f136b045a3e895c914ec3c0141b59f2db14 100755 (executable)
@@ -116,6 +116,8 @@ test "$(stat -c %U:%G:%a /tmp/C/2/f1)" = "daemon:daemon:755"
 
 systemd-tmpfiles --create - <<EOF
 C     /tmp/C/3    0755 daemon daemon - /tmp/C/3-origin
+C     /tmp/C/4    0755 daemon daemon - /tmp/C/definitely-missing
 EOF
 
 test "$(stat -c %U:%G:%a /tmp/C/3/f1)" = "root:root:644"
+test ! -e /tmp/C/4