The argument of a C entry was used as it is, so a relative one was
copied from the directory tmpfiles happened to be started in. With
--root that directory is outside the new root, and
C /etc/copy - - - - ../../../etc/shadow
in a file below the root copied a file of the running system into it.
systemd skips a C line when the path to copy from is not absolute.
Do the same, with a warning.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
There was no way to run the tmpfiles.d files of a root file system
that is not the running one, for example an image that is being put
together.
systemd-tmpfiles has --root=DIR for that. Add the same:
tmpfiles --create --root=/mnt/target
The tmpfiles.d files, users, and groups are those below DIR, and so is
every path, also what an absolute link there points to. A file on the
command line is opened before the root is changed, as systemd does.
It is done with chroot(2), so tmpfiles must be run as root. The new
root most likely has no /proc, which is needed to set the mode, ACL,
or attributes of a path opened with O_PATH. The work directory is
therefore left in the /proc/self/fd of the old root. Users and groups
are read from /etc/passwd and /etc/group, NSS would be that of the old
root.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
When a package is removed, the state its tmpfiles.d file made is left
behind, there was no way to ask for it to be removed.
systemd-tmpfiles has --purge for that, which removes what the entries
marked with a $ after the type make:
d$ /var/lib/app 0750 app app
tmpfiles --purge /usr/lib/tmpfiles.d/app.conf
Add the same. It only takes the entries of files on the command line,
never all of the tmpfiles.d files, and a path is removed before the
one above it. A $ was until now read and ignored.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A package script may run before the package's tmpfiles.d file is on
disk, and gives the entries on the command line or on standard input.
Then only those entries were read, so one that the admin has changed
in /etc/tmpfiles.d was run as the package has it.
With --replace=PATH all the tmpfiles.d files are read, and the ones on
the command line are read where the file PATH would be, as in
systemd-tmpfiles:
tmpfiles --create --replace=/usr/lib/tmpfiles.d/app.conf -
They are not read at all when a later directory has a file of that
name, as with a file that is installed.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
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>
The files were read one directory at a time, Finit's own first and
/etc/tmpfiles.d last, and every entry for a path was run. With two
entries for a path the last one read won, so an entry in /etc won over
one in /usr/lib whatever the files were called.
tmpfiles.d(5) reads the files in the order of their names, whatever
directory they are in, and goes by the first entry that makes a path.
A package relies on that when it names its file to sort before or
after another. Do the same. As before, a file in a later directory
is read in place of one of the same name in an earlier one.
A later entry is skipped when it makes a path an earlier one makes, or
when both take a glob and remove, write to, or keep the path. Several
w+ entries may add to one file. The skip is only told about with
--dry-run or --debug, since Finit's files and those of other packages
overlap on most systems.
Finit's own files had two entries for some paths, and relied on the
last one. Drop the ones that lost: /run/lock, /run/lock/subsys, and
/var/lock in legacy.conf, and /var/run and a second /var/spool in
var.conf.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
An entry was run as its line was read, so the outcome followed the
order of the lines and of the files. With
f /var/run/app/file
L /var/run - - - - ../run
the f entry made /var/run a directory, and the link was never made.
An entry like z or w, placed before the one that makes its path, found
nothing to change.
tmpfiles.d(5) has a path created after the paths above it and removed
after those below it, and runs the entries that take a glob after the
others. Do the same. Every entry is now read before the first one is
run, which also means a line is parsed once, not once per pass, and
the pass that only gathered the x and X entries is gone.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
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>
When there is a file where an entry wants a directory, or the other
way around, the entry fails or leaves the path as it is. In
tmpfiles.d(5) an = after the type has the path removed first when it
is of another kind than the entry makes:
d= /var/lib/foo 0755 foo foo
The same goes for the directories above the path, anything else in
place of one is removed. tmpfiles ignores the =.
Remove what does not match before the b, c, d, D, f, F, L, and p
entries, the ones that make a path of one kind.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A C entry leaves a directory alone when there is something in it. In
tmpfiles.d(5) a C+ entry copies to it anyway: what the directory lacks
is added, and what it has is not overwritten.
C+ /etc/skel - - - - /usr/share/factory/etc/skel
tmpfiles reads C+ as C. Let the + through to copy_tree().
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A C entry for a directory does the opposite of tmpfiles.d(5):
C /etc/pam.d - - - -
When /etc/pam.d does not exist the entry fails with "Not a directory",
the files of the source are copied to a file with the name of the
path, one over the other. When it is an empty directory nothing is
copied. When it has files in it, they are overwritten with the ones
from /usr/share/factory, at every boot. For a file, an existing one
is overwritten as well.
is_dir_empty() returns true for a directory that is not empty, and
rsync() from libite copies over what is there and needs a slash at the
end of a destination directory that is missing.
Copy with a tree walk of our own instead. It copies to a path that
is missing or an empty directory, overwrites nothing, and does not
follow links. Mode, owner, and modification time are those of the
source.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
An x or X entry can have an age of its own in tmpfiles.d(5). What it
keeps from the cleaning of the directory above is then cleaned by that
age instead:
d /tmp 1777 root root 10d
x /tmp/build - - - 30d
tmpfiles does not read the age, so /tmp/build is never cleaned.
Clean the paths of such an entry by its age, with the entry itself
left out of what is kept.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The %T and %V specifiers are always /tmp and /var/tmp. In systemd
both are the first of $TMPDIR, $TEMP, and $TMP that is set to an
absolute path of a directory, and only otherwise /tmp and /var/tmp.
Do the same. At boot none of them are set, so nothing changes there.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
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>
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>
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>
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>
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>
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>
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>
On a system with systemd's tmpfiles.d files installed, only root can
log in after boot. The files have a boot-only entry:
f+! /run/nologin 0644 - - - "System is booting up. ..."
On systemd the file is removed by systemd-user-sessions when boot is
done. Finit runs the entry, but only removes /etc/nologin, so
pam_nologin keeps refusing everyone but root.
Remove /run/nologin too when leaving runlevel S.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
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>
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>
A file from an f entry without a mode got what the umask left of
0666, so the result depended on who called tmpfiles:
f /run/app/state
tmpfiles.d(5) has 0644 as the default. Use that for a file the entry
creates.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
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>
tmpfiles.d(5) has h to set file attributes, as chattr(1) does, and H
for the path and everything below it:
h /var/log/journal - - - - +C
tmpfiles skipped them as unsupported.
Add both. The argument is the letters chattr(1) has, after a + to
add them, which is the default, a - to remove them, or a = to have
just these set. Only files and directories have such attributes,
anything else is left alone.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
tmpfiles.d(5) has t to set extended attributes on a path, and T for
the path and everything below it:
t /srv/www - - - - user.mime_type=text/html
tmpfiles skipped them as unsupported.
Add both. The argument is one or more NAME=VALUE with space between,
a value with space in it goes in quotes. They are set with
lsetxattr(), a link is never followed.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
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>
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>
An entry with %a, or one of the specifiers that come from os-release,
was skipped as unsupported:
d /var/lib/app/%o-%w 0755 - - -
Add %o, %w, %W, %B, %M, and %A, read from /etc/os-release with
/usr/lib/os-release as fallback, and %a with the names tmpfiles.d(5)
has for the architectures. A field that os-release lacks gives an
empty string, as in tmpfiles.d(5). An entry is still skipped when
the architecture is not one of those known.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
An e entry takes a glob, but cleaning looked for a directory with
the pattern as its name:
e /var/cache/* - - - 10d
tmpfiles --clean t.conf
This cleaned nothing.
Expand the glob and clean each directory it matches. Also use the
age of a C entry, tmpfiles.d(5) has it clean what it copied.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Only one number with one unit was read from the age of an entry. An
age like this one was taken as two days:
d /var/tmp 1777 root root 2d12h
What came after the first unit was not looked at. ms and us were not
known, so 500ms gave no cleaning at all.
Read any number of values with units, us, ms, s, m or min, h, d, and
w, and refuse an age that cannot be read or that overflows. Add the ~
prefix, which keeps what is right in the directory, and the prefix
that says which timestamps to go by, e.g. "aAmM:" for access and
modification time of files and directories.
Without that prefix the birth time of a file now counts too, as in
tmpfiles.d(5). It is read with statx(), where the C library has it,
and left out on a file system that has none.
A prefix that names timestamps for files only, or directories only,
leaves the default set for the other. The age is capped at what a 32
bit time_t holds, and nothing is cleaned when it reaches back past
the epoch.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
An entry with a % in the path was skipped, and files from
distributions have them:
d /run/log/journal/%m 2755 root systemd-journal - -
Expand the specifiers that do not need the OS release or the
architecture: %b, %m, %H, %l, %v, the directories %t, %T, %V, %S, %C,
%L, %h, and the user ones %u, %U, %g, %G. tmpfiles runs as root, so
the last ones are fixed. An entry with any other specifier is still
skipped.
The argument of C, f, F, L, and w entries is expanded too, as in
tmpfiles.d(5). A literal % in such an argument must from now on be
written %%.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Files from distributions use v, q, and Q for directories that should
be btrfs subvolumes when that is possible:
v /var/lib/machines 0700 - - -
tmpfiles skipped them as unsupported, so the directory was missing.
On a file system without subvolumes tmpfiles.d(5) has them make a
plain directory. Do that everywhere, read them as d.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
An entry for a device with a 0 in its number was skipped:
c /dev/tty 0666 root tty - 5:0
parse_mm() took 0 to mean atoi() could not read the number.
Use atonum(), which tells the two apart.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Several types read the mode and owner of an entry and did nothing
with them. An f entry was skipped when the file was there:
f /var/log/app.log 0640 app adm
This left a file with another mode or owner as it was. The owner of
p, b, and c entries was never set, and their mode was cut by the
umask. C, z, and Z entries had neither applied.
Set them for all of these, Z for everything below the path. Fifos
and device nodes are opened with O_PATH, so nothing is opened for
real. A path that is not what the entry makes, like a directory
where a p entry wants a fifo, is left alone.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A mode with a prefix was not read as a number, so the entry was taken
to have no mode, and a user with one was looked up with the colon in
the name, which skipped the entry:
d /var/lib/app :0750 :app :app
With : the mode, user, or group is only set on a path the entry
creates, an existing one keeps what it has. With ~ the mode loses
read, write, or execute when no one has that on the existing path,
and setuid, setgid, and sticky when it is not a directory.
Mode and owner now go through perm_set() in tmpfiles, which knows the
entry created the path or not.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
What an unknown user in an entry did depended on the type. A d entry
was skipped, but this one made a file owned by root:
f /run/frr/state 0640 frr frr
The user was looked up in each type on its own, and only d checked
the result.
Look it up once for the entry, and skip the entry when the user is
not known. An unknown group leaves the group of the path as it is,
for a new path that is the group of root, as before. Both are only
reported with --debug, Finit's own files have entries for services
that may not be installed.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
An entry with the age 0 was read as having no age, so nothing in its
directory was ever cleaned:
d /var/spool/work - - - 0
tmpfiles --clean t.conf
In tmpfiles.d(5) age 0 means everything in the directory is removed
on each clean. parse_age() returned 0 for both.
It now returns -1 for no age and for one it cannot read, and with
age 0 the timestamps are not looked at.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The x and X entries were read and ignored, so a path that a package
had marked to be left alone was cleaned like the rest:
d /var/tmp - - - 30d
x /var/tmp/keep
tmpfiles --clean t.conf
This removed what was old in /var/tmp/keep.
Gather the x and X entries of all files in a pass before the cleaning,
they may come after the entry they apply to, or in another file. x
keeps the path and what is in it, X the path alone. A directory that
is not empty afterwards is no longer warned about.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Cleaning the directory of an entry with an age went into whatever was
mounted below it:
d /srv - - - 10d
tmpfiles --clean t.conf
With a disk mounted on /srv/data this removed every file on it older
than ten days.
Give nftw() FTW_MOUNT, so it stays on the file system of the directory.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A ! after the type marks an entry that is only safe to run at boot.
Finit's own files have them, like this one in x11.conf:
D! /tmp/.X11-unix 1777 root root
tmpfiles ignored the ! and ran these entries on every call, so this
emptied the directory under a running X server:
tmpfiles --remove
Only the character right after the type was looked at, and only for
a +.
Read all the modifiers after the type, in any order, and skip an
entry with ! unless the new --boot option is given. Finit gives it
at boot, together with --remove. Before this the r, R, and D entries
were never run at boot, so "r! /forcefsck" in legacy.conf left the
file in place.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
tmpfiles exited at the first entry with a type it does not know, or
with a % specifier in the path:
h /tmp/dir - - - - +i
f /tmp/dir/after
tmpfiles --create t.conf
This never created /tmp/dir/after. At boot it meant that one such
line, in any tmpfiles.d file, stopped every entry after it, in that
file and in all the files sorted after it. The message says skipping,
but errx() exits.
Warn and go on with the next entry. With two passes, for --create
with --remove, only the second one warns.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
With both --create and --remove each entry was removed and then
created before the next one was read. An r entry took what an entry
above it had just created:
f /tmp/file - - - - new
r /tmp/file
tmpfiles --create --remove t.conf
This left no /tmp/file. The same goes for --clean.
Run all the files twice in that case, first to remove and clean, then
to create.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The tpm2-tss package sets a default ACL on its keystore:
d /var/lib/tpm2-tss/system/keystore 2775 tss tss - -
a+ /var/lib/tpm2-tss/system/keystore - - - - default:group:tss:rwx
tmpfiles skipped the a+ line as unsupported, so what was created in
the keystore did not get the group access it relies on.
Add a and A, the latter recursive, with and without +. With + the
entries are added to the ACL of the path, without it they replace it.
The ACL is written to the system.posix_acl_access and _default
extended attributes in the format the kernel uses, which saves a
dependency on libacl. As with setfacl, the mask is made to cover the
named entries unless the entry sets one.
An ACL can have at most 32 entries. A path with more is left as it
is, with a warning.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
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>
An entry without a user or group, or with "-", made root the owner of
an existing directory or file:
mkdir -p /tmp/t && chown daemon:daemon /tmp/t
echo 'd /tmp/t' > t.conf
tmpfiles --create t.conf
stat -c %U:%G /tmp/t
This gave root:root. A missing field was read as "root" when parsing
the entry, the same as if it had been written out. tmpfiles.d(5)
only adjusts the owner when the entry gives one.
A missing user or group is now -1, and fdperm() looks at the two ids
separately, so "d /tmp/t - - sys" changes the group and keeps the
owner. mksubsys() and the service directories used uid -1 to skip
the chown altogether, they now pass -1 for the group as well.
Issue #523
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
A d entry without a mode reset an existing directory to 0755. On
finix a bare "d /tmp" line took the sticky bit and the write
permission for others off the /tmp mount, so nobody but root could
create files there:
mkdir -p /tmp/t && chmod 1777 /tmp/t
echo 'd /tmp/t' > t.conf
tmpfiles --create t.conf
stat -c %a /tmp/t
This gave 755. Commit 9bfbdc6b made the chmod of an existing
directory work, and it used the 0755 default for a new directory as
the mode to set.
The default is now only for creating the directory. With no mode in
the entry, dirperm() leaves the mode alone.
Fixes#523
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
initctl -j status had the state of a service but little of how it is
set up. A program reading it could not tell how the service is
stopped, what scripts it runs, or how it signals readiness.
Add the settings: stop, reload, notify, remain, scripts, directories,
cgroup-config, rlimits, log or tty, provides, conflicts, if, groups,
capabilities, pam, name, id, protected, and nowarn. The restart
object also gets sec, respawn, and oncrash, and the state Finit keeps
for its own use goes in internal:
"stop": {
"signal": "SIGTERM",
"timeout": 3,
"scope": "pgroup"
},
"scripts": {
"exec-stop-post": { "command": "/bin/true", "timeout": 7 }
},
initctl reads the status over D-Bus first, so each setting is also a
property of org.finit.Service1. The new test checks that the JSON is
the same over D-Bus as over the initctl socket.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>