Files
finit/test/tmpfiles-specifier.sh
T
Joachim Wiberg 9ea64e5c3c tmpfiles: let %T and %V follow $TMPDIR
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>
2026-11-21 17:14:03 +01:00

63 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# Verify the % specifiers of tmpfiles.d(5), in the path and the argument
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/specifier
CONF=/tmp/specifier.conf
test_teardown()
{
say "Running test teardown."
run "rm -rf $DIR $CONF /etc/os-release"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
run "cat > /etc/os-release" <<OS
NAME="Finit Test"
ID=finit-test
VERSION_ID="1.2"
OS
run "cat > $CONF" <<CONF
d $DIR
f $DIR/os-%o-%w
f $DIR/arch-%a
f $DIR/variant-%W
f $DIR/host-%H
f $DIR/kernel-%v
f $DIR/machine-%m
f $DIR/boot-%b
f $DIR/100%%
f $DIR/end%
f $DIR/unknown - - - - %!
f $DIR/arg - - - - %T %V %t %S %C %L %h %u %U %g %G %l
CONF
run "/libexec/finit/tmpfiles --create $CONF"
host=$(texec hostname)
assert "Hostname" "$(texec ls $DIR/host-"$host")" = "$DIR/host-$host"
assert "Kernel release" "$(texec ls $DIR/kernel-"$(texec uname -r)")" = "$DIR/kernel-$(texec uname -r)"
assert "Machine ID" "$(texec ls $DIR/machine-"$(texec cat /etc/machine-id)")" = "$DIR/machine-$(texec cat /etc/machine-id)"
boot=$(texec cat /proc/sys/kernel/random/boot_id | tr -d -)
assert "Boot ID" "$(texec ls $DIR/boot-"$boot")" = "$DIR/boot-$boot"
assert "Percent" "$(texec ls $DIR/100%)" = "$DIR/100%"
assert "In the argument" "$(texec cat $DIR/arg)" = "/tmp /var/tmp /run /var/lib /var/cache /var/log /root root 0 root 0 ${host%%.*}"
assert "Skipped: a lone % and an unknown specifier" "$(texec sh -c "ls $DIR | grep -c -e end -e unknown")" = "0"
assert "OS ID and version" "$(texec ls $DIR/os-finit-test-1.2)" = "$DIR/os-finit-test-1.2"
assert "Architecture" "$(texec sh -c "ls $DIR | grep -c '^arch-.'")" = "1"
assert "Empty when not in os-release" "$(texec ls $DIR/variant-)" = "$DIR/variant-"
sep
say "%T and %V follow \$TMPDIR when it is a directory"
run "cat > $CONF" <<CONF
f $DIR/tmpdir - - - - %T %V
CONF
run "TMPDIR=$DIR /libexec/finit/tmpfiles --create $CONF"
assert "From the environment" "$(texec cat $DIR/tmpdir)" = "$DIR $DIR"
run "rm $DIR/tmpdir; TMPDIR=/no/such/dir /libexec/finit/tmpfiles --create $CONF"
assert "Not a directory" "$(texec cat $DIR/tmpdir)" = "/tmp /var/tmp"