diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 6384ba4c..2d341e5c 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -252,6 +252,9 @@ All relevant changes are documented in this file. - Fix `tmpfiles --create --remove`, each entry was removed and created in turn, so an `r` entry removed what an entry above it had just created. All of the removing is now done first +- Fix tmpfiles giving up at the first entry it does not support, an unknown + type or a `%` specifier in the path. No entry after it was run, in that + file or in the files after it. Such an entry is now skipped with a warning - Fix a lost reload for a service paused mid-reload by a condition in flux. A second reload arriving meanwhile re-parsed the unchanged .conf and cleared the pending mark, so the service resumed without ever being diff --git a/src/tmpfiles.c b/src/tmpfiles.c index ab2508b4..f6be2b71 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -56,6 +56,9 @@ int create_flag = 0; int clean_flag = 0; int remove_flag = 0; +/* Set for the first of two passes, the second one does the complaining */ +static int quiet; + #define MAX_EXCLUDES 32 static const char *exclude_prefixes[MAX_EXCLUDES]; static int num_excludes; @@ -727,7 +730,8 @@ static void tmpfiles(char *line) if (!path) return; if (strchr(path, '%')) { - errx(1, "Path name specifiers unsupported, skipping."); + if (!quiet) + warnx("Path name specifiers unsupported, skipping %s", path); return; } if (excluded(path)) @@ -796,7 +800,8 @@ static void tmpfiles(char *line) case 'z': break; default: - errx(1, "Unsupported tmpfiles command '%s'", type); + if (!quiet) + warnx("Unsupported tmpfiles command '%s', skipping %s", type, path); return; } } @@ -1037,7 +1042,8 @@ static void tmpfiles(char *line) globfree(&gl); break; default: - errx(1, "Unsupported tmpfiles command '%s'", type); + if (!quiet) + warnx("Unsupported tmpfiles command '%s', skipping %s", type, path); return; } } @@ -1214,8 +1220,10 @@ int main(int argc, char *argv[]) /* Remove and clean first, or an r entry takes what an f entry above it made */ if (create_flag && (clean_flag || remove_flag)) { create_flag = 0; + quiet = 1; process(argc - optind, &argv[optind]); create_flag = 1; + quiet = 0; clean_flag = remove_flag = 0; } process(argc - optind, &argv[optind]); diff --git a/test/Makefile.am b/test/Makefile.am index 1ef2a00a..eefa8cd6 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -85,6 +85,7 @@ EXTRA_DIST += tmpfiles-acl.sh EXTRA_DIST += tmpfiles-arg.sh EXTRA_DIST += tmpfiles-perm.sh EXTRA_DIST += tmpfiles-order.sh +EXTRA_DIST += tmpfiles-unsupported.sh EXTRA_DIST += unexpected-restart.sh EXTRA_DIST += dbus-auth.sh EXTRA_DIST += dbus-authz.sh @@ -166,6 +167,7 @@ TESTS += tmpfiles-acl.sh TESTS += tmpfiles-arg.sh TESTS += tmpfiles-perm.sh TESTS += tmpfiles-order.sh +TESTS += tmpfiles-unsupported.sh endif TESTS += unexpected-restart.sh if DBUS diff --git a/test/tmpfiles-unsupported.sh b/test/tmpfiles-unsupported.sh new file mode 100755 index 00000000..3951370f --- /dev/null +++ b/test/tmpfiles-unsupported.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Verify that tmpfiles skips an entry it does not support, and goes on +# with the rest +set -eu + +TEST_DIR=$(dirname "$0") + +DIR=/tmp/unsupported +CONF=/tmp/unsupported.conf + +test_teardown() +{ + say "Running test teardown." + run "rm -rf $DIR $CONF" +} + +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + +run "cat > $CONF" <&1") +assert "The entry after is created" "$(texec ls $DIR)" = "after" +assert "Each is reported once" "$(echo "$msg" | grep -c skipping)" -eq 2 + +say 'Remove and create, two passes' +run "rm $DIR/after" +msg=$(texec sh -c "/libexec/finit/tmpfiles --create --remove $CONF 2>&1") +assert "The entry after is created" "$(texec ls $DIR)" = "after" +assert "Each is reported once" "$(echo "$msg" | grep -c skipping)" -eq 2