mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
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>
63 lines
1.8 KiB
Bash
Executable File
63 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# Verify how tmpfiles reads the argument, the last field of an entry
|
|
set -eu
|
|
|
|
TEST_DIR=$(dirname "$0")
|
|
|
|
DIR=/tmp/arg
|
|
CONF=/tmp/arg.conf
|
|
|
|
test_teardown()
|
|
{
|
|
say "Running test teardown."
|
|
run "rm -rf $DIR $CONF"
|
|
}
|
|
|
|
# shellcheck source=/dev/null
|
|
. "$TEST_DIR/lib/setup.sh"
|
|
|
|
run "cat > $CONF" <<CONF
|
|
d $DIR - - - - -
|
|
L $DIR/aligned - - - - /dev/null
|
|
f $DIR/dash - - - - -
|
|
f $DIR/text - - - - two words
|
|
CONF
|
|
run "/libexec/finit/tmpfiles --create $CONF"
|
|
|
|
say 'Space between the age and the argument is not part of the argument'
|
|
assert "Link target" "$(texec readlink $DIR/aligned)" = "/dev/null"
|
|
assert "File content" "$(texec cat $DIR/text)" = "two words"
|
|
|
|
say 'A lone - is no argument'
|
|
assert "Empty file" "$(texec stat -c %s $DIR/dash)" = "0"
|
|
|
|
sep
|
|
say 'L? only makes the link when what it points to is there'
|
|
run "cat > $CONF" <<CONF
|
|
L? $DIR/there - - - - /etc/passwd
|
|
L? $DIR/missing - - - - /no/such/file
|
|
CONF
|
|
run "/libexec/finit/tmpfiles --create $CONF"
|
|
assert "Link to a path that is there" "$(texec readlink $DIR/there)" = "/etc/passwd"
|
|
assert "No link to a missing path" "$(texec sh -c "ls $DIR | grep -c missing")" = "0"
|
|
|
|
sep
|
|
say 'With --prefix only the entries below it are run'
|
|
run "cat > $CONF" <<CONF
|
|
f $DIR/in/file
|
|
f $DIR/out/file
|
|
f $DIR/input
|
|
CONF
|
|
run "/libexec/finit/tmpfiles --create --prefix=$DIR/in $CONF"
|
|
assert "Only below the prefix" "$(texec sh -c "ls -d $DIR/in* $DIR/out* 2>/dev/null" | tr '\n' ' ')" = "$DIR/in "
|
|
|
|
sep
|
|
say 'w writes all of its argument to every path a glob matches'
|
|
run "touch $DIR/w1 $DIR/w2"
|
|
run "cat > $CONF" <<'CONF'
|
|
w /tmp/arg/w? - - - - one\ntwo
|
|
CONF
|
|
run "/libexec/finit/tmpfiles --create $CONF"
|
|
assert "First match" "$(texec cat $DIR/w1 | tr '\n' ' ')" = "one two"
|
|
assert "Second match" "$(texec cat $DIR/w2 | tr '\n' ' ')" = "one two"
|