From ce610af143b2a11011f00c65ea96f7a88453373b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 25 Aug 2022 17:16:02 +0200 Subject: [PATCH] tmpfiles: in C lines, make missing source graceful error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | 7 +++++++ test/units/testsuite-22.02.sh | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 07432a1e51e..4bbf9b4acee 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -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: diff --git a/test/units/testsuite-22.02.sh b/test/units/testsuite-22.02.sh index 0719d68292b..49c55f136b0 100755 --- a/test/units/testsuite-22.02.sh +++ b/test/units/testsuite-22.02.sh @@ -116,6 +116,8 @@ test "$(stat -c %U:%G:%a /tmp/C/2/f1)" = "daemon:daemon:755" systemd-tmpfiles --create - <