2021-04-09 20:39:41 +03:00
#!/bin/bash
2018-04-13 16:32:25 +03:00
#
# Basic tests for types creating fifos
#
2021-04-09 20:39:41 +03:00
set -eux
set -o pipefail
2018-04-13 16:32:25 +03:00
rm -fr /tmp/p
mkdir /tmp/p
touch /tmp/p/f1
systemd-tmpfiles --create - <<EOF
p /tmp/p/fifo1 0666 - - - -
EOF
test -p /tmp/p/fifo1
2021-04-09 20:49:32 +03:00
test " $( stat -c %U:%G:%a /tmp/p/fifo1) " = "root:root:666"
2018-04-13 16:32:25 +03:00
tmpfiles: make handling of existing-but-different targets more consistent
create_fifo() was added in a2fc2f8dd30c17ad1e23a31fc6ff2aeba4c6fa27, and
would always ignore failure. The test was trying to fail in this case, but
we actually don't fail, which seems to be correct. We didn't notice before
because the test was ineffective.
To make things consistent, generally log at warning level, but don't propagate
the error. For symlinks, log at debug level, as before.
For 'e', failure is not propagated now. The test is adjusted to match.
I think warning is appropriate in most cases: we do not expect a device node to
be replaced by a different device node or even a non-device file. This would
most likely be an error somewhere. An exception is made for symlinks, which are
mismatched on purpose, for example /etc/resolv.conf. With this patch, we don't
get any warnings with the any of the 74 tmpfiles.d files, which suggests that
increasing the warning levels will not cause too many unexpected warnings. If
it turns out that there are valid cases where people have expected mismatches
for non-symlink types, we can always decrease the log levels again.
2021-04-08 01:48:35 +03:00
# Refuse to overwrite an existing file. Error is not propagated.
systemd-tmpfiles --create - <<EOF
2018-04-13 16:32:25 +03:00
p /tmp/p/f1 0666 - - - -
EOF
test -f /tmp/p/f1
# unless '+' prefix is used
systemd-tmpfiles --create - <<EOF
p+ /tmp/p/f1 0666 - - - -
EOF
test -p /tmp/p/f1
2021-04-09 20:49:32 +03:00
test " $( stat -c %U:%G:%a /tmp/p/f1) " = "root:root:666"
2018-04-13 16:32:25 +03:00
#
# Must be fixed
#
2018-08-06 21:56:45 +03:00
# mkdir /tmp/p/daemon
# #ln -s /root /tmp/F/daemon/unsafe-symlink
# chown -R --no-dereference daemon:daemon /tmp/p/daemon
2018-04-13 16:32:25 +03:00
#
# systemd-tmpfiles --create - <<EOF
2018-08-06 21:56:45 +03:00
# p /tmp/p/daemon/fifo2 0666 daemon daemon - -
2018-04-13 16:32:25 +03:00
# EOF