2018-04-13 16:32:25 +03:00
#! /bin/bash
#
# Basic tests for types creating directories
#
set -e
set -x
2019-01-07 03:13:13 +03:00
rm -fr /tmp/{ C,d,D,e}
mkdir /tmp/{ C,d,D,e}
2018-04-13 16:32:25 +03:00
#
# 'd'
#
mkdir /tmp/d/2
chmod 777 /tmp/d/2
systemd-tmpfiles --create - <<EOF
d /tmp/d/1 0755 daemon daemon - -
d /tmp/d/2 0755 daemon daemon - -
EOF
test -d /tmp/d/1
test $( stat -c %U:%G:%a /tmp/d/1) = "daemon:daemon:755"
test -d /tmp/d/2
test $( stat -c %U:%G:%a /tmp/d/2) = "daemon:daemon:755"
#
# 'D'
#
mkdir /tmp/D/2
chmod 777 /tmp/D/2
touch /tmp/D/2/foo
systemd-tmpfiles --create - <<EOF
D /tmp/D/1 0755 daemon daemon - -
D /tmp/D/2 0755 daemon daemon - -
EOF
test -d /tmp/D/1
test $( stat -c %U:%G:%a /tmp/D/1) = "daemon:daemon:755"
test -d /tmp/D/2
test $( stat -c %U:%G:%a /tmp/D/2) = "daemon:daemon:755"
systemd-tmpfiles --remove - <<EOF
D /tmp/D/2 0755 daemon daemon - -
EOF
# the content of '2' should be removed
test " $( echo /tmp/D/2/*) " = "/tmp/D/2/*"
#
# 'e'
#
mkdir -p /tmp/e/2/{ d1,d2}
chmod 777 /tmp/e/2
chmod 777 /tmp/e/2/d*
systemd-tmpfiles --create - <<EOF
e /tmp/e/1 0755 daemon daemon - -
e /tmp/e/2/* 0755 daemon daemon - -
EOF
2021-04-08 00:24:25 +03:00
test ! -d /tmp/e/1
2018-04-13 16:32:25 +03:00
test -d /tmp/e/2
test $( stat -c %U:%G:%a /tmp/e/2) = "root:root:777"
test -d /tmp/e/2/d1
test $( stat -c %U:%G:%a /tmp/e/2/d1) = "daemon:daemon:755"
test -d /tmp/e/2/d2
test $( stat -c %U:%G:%a /tmp/e/2/d2) = "daemon:daemon:755"
# 'e' operates on directories only
mkdir -p /tmp/e/3/{ d1,d2}
chmod 777 /tmp/e/3
chmod 777 /tmp/e/3/d*
touch /tmp/e/3/f1
chmod 644 /tmp/e/3/f1
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
systemd-tmpfiles --create - <<EOF
2018-04-13 16:32:25 +03:00
e /tmp/e/3/* 0755 daemon daemon - -
EOF
# the directories should have been processed although systemd-tmpfiles failed
# previously due to the presence of a file.
test -d /tmp/e/3/d1
test $( stat -c %U:%G:%a /tmp/e/3/d1) = "daemon:daemon:755"
test -d /tmp/e/3/d2
test $( stat -c %U:%G:%a /tmp/e/3/d2) = "daemon:daemon:755"
test -f /tmp/e/3/f1
test $( stat -c %U:%G:%a /tmp/e/3/f1) = "root:root:644"
2019-01-07 03:13:13 +03:00
#
# 'C'
#
mkdir /tmp/C/{ 1,2,3} -origin
touch /tmp/C/{ 1,2,3} -origin/f1
chmod 755 /tmp/C/{ 1,2,3} -origin/f1
mkdir /tmp/C/{ 2,3}
touch /tmp/C/3/f1
systemd-tmpfiles --create - <<EOF
C /tmp/C/1 0755 daemon daemon - /tmp/C/1-origin
C /tmp/C/2 0755 daemon daemon - /tmp/C/2-origin
EOF
test -d /tmp/C/1
test $( stat -c %U:%G:%a /tmp/C/1/f1) = "daemon:daemon:755"
test -d /tmp/C/2
test $( stat -c %U:%G:%a /tmp/C/2/f1) = "daemon:daemon:755"
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
systemd-tmpfiles --create - <<EOF
2019-01-07 03:13:13 +03:00
C /tmp/C/3 0755 daemon daemon - /tmp/C/3-origin
EOF
test $( stat -c %U:%G:%a /tmp/C/3/f1) = "root:root:644"