Commit Graph
13 Commits
Author SHA1 Message Date
Joachim Wiberg 4bec72fcf2 tmpfiles: skip an entry with a relative path
An entry with a path like tmp/file was run on the directory tmpfiles
happened to be started in.  tmpfiles.d(5) only has absolute paths, and
systemd skips such a line.  Do the same, with a warning.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-21 19:23:48 +01:00
Joachim Wiberg c349d564d4 tmpfiles: take --graceful
Package scripts written for systemd-tmpfiles may call it with
--graceful, to not fail on an entry for a user or group that does not
exist.  tmpfiles then stops at the unknown option and prints its usage
text:

    tmpfiles --create --graceful /usr/lib/tmpfiles.d/foo.conf

Take the option and do nothing.  An entry with an unknown user is
already skipped without an error, and an unknown group left alone.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-21 17:14:02 +01:00
Joachim Wiberg 6b5a8e0386 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>
2026-11-21 17:14:02 +01:00
Joachim Wiberg 09dcf91877 tmpfiles: add the ~ modifier, an argument in Base64
In tmpfiles.d(5) a ~ after the type of an f, F, or w entry means the
argument is Base64, for content that cannot be written on a line:

    f~ /root/.ssh/authorized_keys 0600 root root - c3NoLWVkMjU1MTkg...

tmpfiles ignores the ~ and writes the argument as it is.

Decode the argument.  As in systemd it is not looked at for specifiers
or escapes, and an entry with an argument that is not Base64 is
skipped.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-21 17:14:02 +01:00
Joachim Wiberg ed96814fdc tmpfiles: read quotes and escapes in the fields before the argument
There is no way to write an entry for a path with a space in it, the
fields are split at every space.  In tmpfiles.d(5) a field can be
quoted, and have C-style escapes:

    d "/srv/my files"
    d /srv/my\sfiles

Split the fields with a function that resolves both.  The argument is
still the rest of the line as it is, quotes and all, like in systemd.
An entry with a quote left open is skipped.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-21 17:14:01 +01:00
Joachim Wiberg aa38c72044 tmpfiles: do not truncate the file of a w entry
A w entry empties the file before it writes the argument.  With a file
that holds "abcdef":

    w /tmp/file - - - - XY

leaves "XY".  With systemd-tmpfiles the file holds "XYcdef", it writes
over the start of what is there.  For a file in /proc or /sys there is
no difference.

Open the file without O_TRUNC.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-21 17:13:53 +01:00
Joachim Wiberg 309844fc11 tmpfiles: only take a # at the start of a line as a comment
An entry with a # in the argument loses it and the rest of the line:

    f /tmp/file - - - - a#b c

gives a file holding "a".  The lines are read with fparseln(), which
by default takes a # anywhere in a line as the start of a comment.  In
tmpfiles.d(5) only a line that starts with # is a comment.

Read the lines without a comment character and skip the lines that
start with one.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-21 17:13:53 +01:00
Joachim Wiberg 7ec4376eb0 tmpfiles: take 8 and 9 as hex digits in an \x escape
An f or w entry with \x39 in the argument writes the byte 3 followed
by a 9, where it should write a 9:

    f /tmp/file - - - - \x39

write_hex() only takes the digits 0 to 7, as for an octal escape.
Take all hex digits.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-21 17:13:53 +01:00
Joachim Wiberg 81ce7a2833 tmpfiles: skip an entry that takes its argument from a credential
A ^ after the type says the argument is the name of a credential to
read the real argument from.  Files from systemd have them:

    f^ /etc/hosts - - - - network.hosts

The ^ was not read, so on a system without /etc/hosts this made one
holding the text "network.hosts".

Finit has no credentials.  Skip the entry, which is what systemd does
when the credential is not set.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 19:10:04 +01:00
Joachim Wiberg af10d09762 tmpfiles: write all of the argument to every match of a w entry
A w entry with a glob wrote its whole argument to the first path
only.  The rest got it up to the first backslash:

    w /sys/class/net/eth*/queues/rx-0/rps_cpus - - - - f\n

write_arg() put a NUL in the argument at each escape as it went, so
the second call saw a shorter string.

Leave the argument as it is.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 19:10:02 +01:00
Joachim Wiberg e19e37286a tmpfiles: add the L? entry
tmpfiles.d(5) has L? for a link that is only made when what it points
to exists:

    L? /etc/localtime - - - - ../usr/share/zoneinfo/UTC

The ? was not read, so this made the link whatever was there.

Finit has had this as its own l entry.  Read L? as l.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:35:37 +01:00
Joachim Wiberg 0a2beb9b6d tmpfiles: add --prefix, to only run entries below a path
A package that ships a tmpfiles.d file wants its own paths created
when it is installed, without running every other entry on the
system:

    tmpfiles --create --prefix=/var/lib/app

Add the option, it can be given more than once.  It and
--exclude-prefix compare whole path components now, before
--exclude-prefix=/dev also left out /devices.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:35:36 +01:00
Joachim Wiberg 3bc7c83731 tmpfiles: skip the space before the argument of an entry
An entry written in aligned columns got the space after the age field
as part of its argument:

    L  /tmp/null  -  -  -  -    /dev/null

This made a link to "   /dev/null".  Only the first separator after
the age was dropped.  A lone "-" for no argument was also taken as is,
so an f entry with it made a file holding a dash.

Skip all the space before the argument, and read "-" as no argument.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 12:00:50 +01:00