From 6b5a8e0386a6f1f312210e940da4cb0b450d719b Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 21 Nov 2026 10:14:02 +0100 Subject: [PATCH] tmpfiles: add --cat-config, to show the files that would be read With files in five directories, where one in /etc replaces the one with the same name in /usr/lib, it is not easy to tell what tmpfiles goes by. systemd-tmpfiles has --cat-config for this. Add the option. It prints each file that would be read below a line with its name, and exits: /libexec/finit/tmpfiles --cat-config Signed-off-by: Joachim Wiberg --- doc/ChangeLog.md | 2 ++ doc/tmpfiles-todo.md | 3 +-- src/tmpfiles.c | 21 +++++++++++++++++++++ test/tmpfiles-arg.sh | 4 ++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 10b97972..b6752cc3 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -34,6 +34,8 @@ All relevant changes are documented in this file. escapes, for a path with a space in it: `d "/srv/my files"` - tmpfiles: add the `~` modifier for `f`, `F`, and `w` entries, as in `f~`, where the argument is Base64, for a file with binary content +- tmpfiles: add `--cat-config`, to show the files that would be read, + each below a line with its name - tmpfiles: add `--prefix=PATH`, to only run the entries for paths below it. `--prefix` and `--exclude-prefix` match whole path components, `--exclude-prefix=/dev` no longer skips `/devices` diff --git a/doc/tmpfiles-todo.md b/doc/tmpfiles-todo.md index aa6d1fe0..3537e5fd 100644 --- a/doc/tmpfiles-todo.md +++ b/doc/tmpfiles-todo.md @@ -22,8 +22,7 @@ files or common packages already rely on, last what few will miss. 2. Command line --------------- -Missing options: `--root`, `--replace`, `--purge`, `--graceful`, and -`--cat-config`. +Missing options: `--root`, `--replace`, `--purge`, and `--graceful`. 3. Smaller things diff --git a/src/tmpfiles.c b/src/tmpfiles.c index f5b99906..725e2df9 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -63,6 +63,7 @@ int clean_flag = 0; int remove_flag = 0; int boot_flag = 0; int dry_run = 0; +int cat_config = 0; /* Set for the first of two passes, the second one does the complaining */ static int quiet; @@ -1941,6 +1942,14 @@ static void process_file(const char *fn) return; } + if (cat_config) { + printf("# %s\n", fn); + fcopyfile(fp, stdout); + puts(""); + fclose(fp); + return; + } + while (!feof(fp)) { /* No comment character, a # is only a comment at the start of a line */ const char delim[3] = { '\\', '\\', 0 }; @@ -2020,6 +2029,7 @@ static int usage(int rc) "\n" "Options:\n" " --boot Also run boot-only entries, marked with !\n" + " --cat-config Show the files that would be read, and exit\n" " -C, --clean Clean files and directories based on age\n" " -c, --create Create files and directories\n" " -d, --debug Show developer debug messages\n" @@ -2041,12 +2051,14 @@ enum { OPT_EXCLUDE_PREFIX = 256, OPT_BOOT, OPT_PREFIX, + OPT_CAT_CONFIG, }; int main(int argc, char *argv[]) { struct option long_options[] = { { "boot", 0, NULL, OPT_BOOT }, + { "cat-config", 0, NULL, OPT_CAT_CONFIG }, { "clean", 0, NULL, 'C' }, { "create", 0, NULL, 'c' }, { "debug", 0, NULL, 'd' }, @@ -2093,6 +2105,10 @@ int main(int argc, char *argv[]) add_prefix(optarg); break; + case OPT_CAT_CONFIG: + cat_config = 1; + break; + case OPT_EXCLUDE_PREFIX: add_exclude_prefix(optarg); break; @@ -2110,6 +2126,11 @@ int main(int argc, char *argv[]) } } + if (cat_config) { + process(argc - optind, &argv[optind]); + return 0; + } + if (create_flag + clean_flag + remove_flag == 0) { fprintf(stderr, "You need to specify at least one of --clean, --create, or --remove.\n"); return 1; diff --git a/test/tmpfiles-arg.sh b/test/tmpfiles-arg.sh index 97e2ceba..6b8c590c 100755 --- a/test/tmpfiles-arg.sh +++ b/test/tmpfiles-arg.sh @@ -117,3 +117,7 @@ assert "Decoded, no specifiers" "$(texec cat $DIR/b64)" = "hello %t" assert "Padded" "$(texec cat $DIR/b64pad)" = "hi" assert "Written with w" "$(texec cat $DIR/w1)" = "XYcdef" assert "Skipped when not Base64" "$(texec sh -c "ls $DIR | grep -c b64bad")" = "0" + +sep +say '--cat-config shows the files that would be read' +assert "Files with their name" "$(texec /libexec/finit/tmpfiles --cat-config $CONF | head -2 | tr '\n' ' ')" = "# $CONF f~ /tmp/arg/b64 - - - - aGVsbG8gJXQK "