tmpfiles: add --dry-run, to show what would be run

There was no way to see what the tmpfiles.d files on a system amount
to, short of running them:

    tmpfiles --dry-run --create --remove --boot

With -n or --dry-run each entry that would be run is printed, with
what would be done, remove, clean, or create, in the order it would
be.  Nothing is changed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-20 19:10:04 +01:00
1 parent a27c0d40f3
commit ddb4f18fa9
5 files changed
+47 -5

No files matched your search

+2
View File
@@ -22,6 +22,8 @@ All relevant changes are documented in this file.
`%w`, `%W`, `%B`, `%M`, and `%A`. Before, an entry with a `%`
in the path was skipped. **Note:** a literal `%` in such an argument,
e.g. in a `w` entry for `core_pattern`, must now be written `%%`
- tmpfiles: add `-n`, `--dry-run`, to show the entries that would be run,
in the order they would be, without doing anything
- tmpfiles: add the `t` and `T` entries, to set extended attributes on
a path, `T` also on everything below it
- tmpfiles: add the `h` and `H` entries, to set file attributes as with
+5
View File
@@ -31,6 +31,11 @@ For your convenience a set of *optional* plugins are available:
files distributed with Finit. It is read first but can be overridden
by any of the standard tmpfiles.d directories, e.g. `/etc/tmpfiles.d`.
To see what the files on a system amount to, without anything being
done, add `--dry-run`:
/libexec/finit/tmpfiles --dry-run --create --remove --boot
The age of an entry, e.g. `10d` below, is used only by `tmpfiles
--clean`, which Finit never runs on its own:
+5 -4
View File
@@ -13,16 +13,17 @@ files or common packages already rely on, last what few will miss.
* `C+`, which is read as `C`
* `z` and `Z` only set the SELinux label when `restorecon` is installed
* Modifiers `-` (do not fail), `=` (remove what is of another type),
`~` (base64 argument), and `^` (credential as argument)
* Modifiers `=` (remove what is of another type), `~` (base64
argument), and `^` (credential as argument). `-` (do not fail) has
nothing to do, tmpfiles never exits with an error for an entry
* Quoted paths, a path with a space in it cannot be written
2. Command line
---------------
Missing options: `--root`, `--replace`, `--dry-run`, `--purge`,
`--graceful`, and `--cat-config`.
Missing options: `--root`, `--replace`, `--purge`, `--graceful`, and
`--cat-config`.
3. Smaller things
+24 -1
View File
@@ -61,6 +61,7 @@ int create_flag = 0;
int clean_flag = 0;
int remove_flag = 0;
int boot_flag = 0;
int dry_run = 0;
/* Set for the first of two passes, the second one does the complaining */
static int quiet;
@@ -1469,6 +1470,22 @@ static void tmpfiles(char *line)
}
}
if (dry_run) {
if (!strchr("aAbcCdDefFhHlLprRtTwxXzZ", type[0])) {
if (!quiet)
warnx("Unsupported tmpfiles command '%s', skipping %s", type, path);
return;
}
if (remove_flag && strchr("DrR", type[0]))
printf("remove %s %s\n", type, path);
if (clean_flag && strchr("CdDe", type[0]) && !parse_age(age, &clean_age))
printf("clean %s %s, older than %s\n", type, path, age);
if (create_flag && !strchr("rRxX", type[0]))
printf("create %s %s%s%s\n", type, path, arg ? " " : "", arg ?: "");
return;
}
strc = stat(path, &st);
// file and directory removal logic
@@ -1878,6 +1895,7 @@ static int usage(int rc)
" -C, --clean Clean files and directories based on age\n"
" -c, --create Create files and directories\n"
" -d, --debug Show developer debug messages\n"
" -n, --dry-run Only show the entries that would be run\n"
" -E Exclude /dev, /proc, /run, and /sys\n"
" --exclude-prefix=PFX Ignore rules for paths starting with PFX\n"
" --prefix=PFX Only apply rules for paths starting with PFX\n"
@@ -1904,6 +1922,7 @@ int main(int argc, char *argv[])
{ "clean", 0, NULL, 'C' },
{ "create", 0, NULL, 'c' },
{ "debug", 0, NULL, 'd' },
{ "dry-run", 0, NULL, 'n' },
{ "exclude-prefix", 1, NULL, OPT_EXCLUDE_PREFIX },
{ "prefix", 1, NULL, OPT_PREFIX },
{ "remove", 0, NULL, 'r' },
@@ -1913,7 +1932,7 @@ int main(int argc, char *argv[])
int c;
while ((c = getopt_long(argc, argv, "CcdrEh?", long_options, NULL)) != EOF) {
while ((c = getopt_long(argc, argv, "CcdnrEh?", long_options, NULL)) != EOF) {
switch(c) {
case 'C':
clean_flag = 1;
@@ -1927,6 +1946,10 @@ int main(int argc, char *argv[])
debug = 1;
break;
case 'n':
dry_run = 1;
break;
case 'E':
add_exclude_prefix("/dev");
add_exclude_prefix("/proc");
+11
View File
@@ -25,3 +25,14 @@ run "mkdir $DIR; echo old > $DIR/file"
run "/libexec/finit/tmpfiles --create --remove $CONF"
assert "The old file is removed, a new one created" "$(texec cat $DIR/file)" = "new"
sep
say 'With --dry-run it only tells what it would do, in that order'
run "cat > $CONF" <<CONF
f $DIR/dry - - - - text
r $DIR/file
d $DIR/sub - - - 1d
CONF
out=$(texec /libexec/finit/tmpfiles --dry-run --create --remove --clean "$CONF")
assert "What it would do" "$(echo "$out" | tr '\n' ';')" = "remove r $DIR/file;clean d $DIR/sub, older than 1d;create f $DIR/dry text;create d $DIR/sub;"
assert "Nothing is done" "$(texec ls $DIR)" = "file"