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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 17:14:02 +01:00
1 parent 09dcf91877
commit 6b5a8e0386
4 files changed
+28 -2

No files matched your search

+2
View File
@@ -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`
+1 -2
View File
@@ -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
+21
View File
@@ -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;
+4
View File
@@ -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 "