tmpfiles: read a file named - from standard input

A package script that has its entries at hand, and not yet in a file,
gives them to systemd-tmpfiles on standard input:

    echo 'd /var/lib/app 0750 app app' | tmpfiles --create -

Finit's tmpfiles took - as the name of a file and failed to open it.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 19:23:49 +01:00
1 parent dd186287d7
commit fa430d0a02
3 files changed
+19 -10

No files matched your search

+2
View File
@@ -59,6 +59,8 @@ All relevant changes are documented in this file.
change an entry from a file in `/usr/lib/tmpfiles.d`, use a file of the
same name in `/etc/tmpfiles.d`, or one with a name that sorts before it.
`tmpfiles --dry-run` tells which entries are skipped
- tmpfiles: a file named `-` on the command line is read from standard
input
- 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`
+12 -10
View File
@@ -2351,12 +2351,14 @@ static void run_entries(int create)
static void process_file(const char *fn)
{
FILE *fp;
FILE *fp = stdin;
fp = fopen(fn, "r");
if (!fp) {
warn("Failed to open %s", fn);
return;
if (strcmp(fn, "-")) {
fp = fopen(fn, "r");
if (!fp) {
warn("Failed to open %s", fn);
return;
}
}
conf = fn;
@@ -2364,11 +2366,9 @@ static void process_file(const char *fn)
printf("# %s\n", fn);
fcopyfile(fp, stdout);
puts("");
fclose(fp);
return;
}
while (!feof(fp)) {
while (!cat_config && !feof(fp)) {
/* No comment character, a # is only a comment at the start of a line */
const char delim[3] = { '\\', '\\', 0 };
char *line;
@@ -2381,7 +2381,8 @@ static void process_file(const char *fn)
free(line);
}
fclose(fp);
if (fp != stdin)
fclose(fp);
}
static int by_name(const void *a, const void *b)
@@ -2466,7 +2467,8 @@ static int usage(int rc)
" -h, --help This help text\n"
"\n"
"If no CONFIGFILE is specified, all *.conf files in the standard\n"
"tmpfiles.d directories are processed.\n"
"tmpfiles.d directories are processed. A CONFIGFILE of - is read\n"
"from standard input.\n"
"\n");
return rc;
+5
View File
@@ -45,3 +45,8 @@ say 'Files are read by name, and the first entry for a path counts'
assert "First by file name" "$(texec cat $DIR/first)" = "one+three+four"
assert "Told about in a dry run" \
"$(texec sh -c "/libexec/finit/tmpfiles -n --create --prefix=$DIR 2>&1 | grep -c 'already has an entry'")" = "1"
sep
say 'A file named - is read from standard input'
run "echo 'f $DIR/stdin' | /libexec/finit/tmpfiles --create -"
assert "Entry on stdin" "$(texec sh -c "ls $DIR | grep -c stdin")" = "1"