Skip to content

Commit

Permalink
test: use quotes where necessary
Browse files Browse the repository at this point in the history
to avoid possible word splitting.
  • Loading branch information
mrc0mmand committed Apr 13, 2021
1 parent 084575f commit 3882526
Show file tree
Hide file tree
Showing 20 changed files with 305 additions and 293 deletions.
1 change: 1 addition & 0 deletions test/TEST-50-DISSECT/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test_append_files() {
install_dmevent
generate_module_dependencies
inst_binary losetup
inst_binary wc
install_verity_minimal
)
}
Expand Down
4 changes: 2 additions & 2 deletions test/units/testsuite-02.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ for task in "${TEST_LIST[@]}"; do
# until one of the tasks finishes, so we can replace it.
while [[ ${#running[@]} -ge $MAX_QUEUE_SIZE ]]; do
for key in "${!running[@]}"; do
if ! kill -0 ${running[$key]} &>/dev/null; then
if ! kill -0 "${running[$key]}" &>/dev/null; then
# Task has finished, report its result and drop it from the queue
wait ${running[$key]}
wait "${running[$key]}"
ec=$?
report_result "$key" $ec
unset running["$key"]
Expand Down
2 changes: 1 addition & 1 deletion test/units/testsuite-13.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ EOF
sleep 0.1
done

return $(systemctl show -P ExecMainStatus nspawn_machinectl_bind.service)
return "$(systemctl show -P ExecMainStatus nspawn_machinectl_bind.service)"
}

function run {
Expand Down
10 changes: 5 additions & 5 deletions test/units/testsuite-14.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ r="$(pwd)/overwrite-broken-machine-id"
setup_root "$r"
systemd-machine-id-setup --print --root "$r"
echo abc >>"$r/etc/machine-id"
id=$(systemd-machine-id-setup --print --root "$r")
echo $id >expected
id="$(systemd-machine-id-setup --print --root "$r")"
echo "$id" >expected
check expected "$r/etc/machine-id"

r="$(pwd)/transient-machine-id"
r="$PWD/transient-machine-id"
setup_root "$r"
systemd-machine-id-setup --print --root "$r"
echo abc >>"$r/etc/machine-id"
mount -o remount,ro "$r"
mount -t tmpfs tmpfs "$r/run"
transient_id=$(systemd-machine-id-setup --print --root "$r")
transient_id="$(systemd-machine-id-setup --print --root "$r")"
mount -o remount,rw "$r"
commited_id=$(systemd-machine-id-setup --print --commit --root "$r")
commited_id="$(systemd-machine-id-setup --print --commit --root "$r")"
[[ "$transient_id" = "$commited_id" ]]
check "$r/etc/machine-id" "$r/run/machine-id"
44 changes: 23 additions & 21 deletions test/units/testsuite-15.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,53 @@ set -eux
set -o pipefail

_clear_service () {
systemctl stop $1.service 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/$1.service
rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.d
rm -fr /{etc,run,usr/lib}/systemd/system/$1.service.{wants,requires}
if [[ $1 == *@ ]]; then
systemctl stop $1*.service 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/$1*.service
rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.d
rm -fr /{etc,run,usr/lib}/systemd/system/$1*.service.{wants,requires}
local SERVICE_NAME="${1:?_clear_service: missing argument}"
systemctl stop "$SERVICE_NAME.service" 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service
rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d
rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{wants,requires}
if [[ $SERVICE_NAME == *@ ]]; then
systemctl stop "$SERVICE_NAME"*.service 2>/dev/null || :
rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service
rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.d
rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.{wants,requires}
fi
}

clear_services () {
for u in $*; do
_clear_service $u
for u in "$@"; do
_clear_service "$u"
done
systemctl daemon-reload
}

create_service () {
clear_services $1
local SERVICE_NAME="${1:?create_service: missing argument}"
clear_services "$SERVICE_NAME"

cat >/etc/systemd/system/$1.service<<EOF
cat >/etc/systemd/system/"$SERVICE_NAME".service <<EOF
[Unit]
Description=$1 unit
Description=$SERVICE_NAME unit
[Service]
ExecStart=/bin/sleep 100000
EOF
mkdir -p /{etc,run,usr/lib}/systemd/system/$1.service.d
mkdir -p /etc/systemd/system/$1.service.{wants,requires}
mkdir -p /run/systemd/system/$1.service.{wants,requires}
mkdir -p /usr/lib/systemd/system/$1.service.{wants,requires}
mkdir -p /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d
mkdir -p /etc/systemd/system/"$SERVICE_NAME".service.{wants,requires}
mkdir -p /run/systemd/system/"$SERVICE_NAME".service.{wants,requires}
mkdir -p /usr/lib/systemd/system/"$SERVICE_NAME".service.{wants,requires}
}

create_services () {
for u in $*; do
create_service $u
for u in "$@"; do
create_service "$u"
done
}

check_ok () {
[ $# -eq 3 ] || return

x="$(systemctl show --value -p $2 $1)"
x="$(systemctl show --value -p "$2" "$1")"
case "$x" in
*$3*) return 0 ;;
*) return 1 ;;
Expand Down
29 changes: 13 additions & 16 deletions test/units/testsuite-16.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ set -o pipefail

rm -f /test.log

TL=/test.log.XXXXXXXX
TESTLOG=/test.log.XXXXXXXX

function wait_for()
{
service=${1}
result=${2:-success}
time=${3:-45}
local service="${1:-wait_for: missing service argument}"
local result="${2:-success}"
local time="${3:-45}"

while [[ ! -f /${service}.terminated && ! -f /${service}.success && $time -gt 0 ]]
do
while [[ ! -f /${service}.terminated && ! -f /${service}.success && $time -gt 0 ]]; do
sleep 1
time=$(( $time - 1 ))
time=$((time - 1))
done

if [[ ! -f /${service}.${result} ]]
then
journalctl -u ${service/_/-}.service >> "${TL}"
if [[ ! -f /${service}.${result} ]]; then
journalctl -u "${service/_/-}.service" >>"$TESTLOG"
fi
}

Expand All @@ -45,12 +43,11 @@ wait_for fail_start startfail
wait_for fail_stop stopfail
wait_for fail_runtime runtimefail

if [[ -f "${TL}" ]]
then
if [[ -f "$TESTLOG" ]]; then
# no mv
cp "${TL}" /test.log
cp "$TESTLOG" /test.log
exit 1
else
touch /testok
exit 0
fi

touch /testok
exit 0
4 changes: 2 additions & 2 deletions test/units/testsuite-17.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set -o pipefail

>/failed

for t in ${0%.sh}.*.sh; do
echo "Running $t"; ./$t
for t in "${0%.sh}".*.sh; do
echo "Running $t"; ./"$t"
done

touch /testok
Expand Down
2 changes: 1 addition & 1 deletion test/units/testsuite-20.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ systemd-run --unit=test20-mainpidsh3.service \
&& { echo 'unexpected success'; exit 1; }

# Test that this failed due to timeout, and not some other error
test $(systemctl show -P Result test20-mainpidsh3.service) = timeout
test "$(systemctl show -P Result test20-mainpidsh3.service)" = timeout

systemd-analyze log-level info

Expand Down
26 changes: 13 additions & 13 deletions test/units/testsuite-22.02.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ 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 "$(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"
test "$(stat -c %U:%G:%a /tmp/d/2)" = "daemon:daemon:755"

#
# 'D'
Expand All @@ -39,10 +39,10 @@ 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 "$(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"
test "$(stat -c %U:%G:%a /tmp/D/2)" = "daemon:daemon:755"

systemd-tmpfiles --remove - <<EOF
D /tmp/D/2 0755 daemon daemon - -
Expand All @@ -66,12 +66,12 @@ EOF
test ! -d /tmp/e/1

test -d /tmp/e/2
test $(stat -c %U:%G:%a /tmp/e/2) = "root:root:777"
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 "$(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"
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}
Expand All @@ -87,12 +87,12 @@ 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 "$(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 "$(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"
test "$(stat -c %U:%G:%a /tmp/e/3/f1)" = "root:root:644"

#
# 'C'
Expand All @@ -111,12 +111,12 @@ 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 "$(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"
test "$(stat -c %U:%G:%a /tmp/C/2/f1)" = "daemon:daemon:755"

systemd-tmpfiles --create - <<EOF
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"
test "$(stat -c %U:%G:%a /tmp/C/3/f1)" = "root:root:644"
20 changes: 10 additions & 10 deletions test/units/testsuite-22.03.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ EOF

### '1' should exist and be empty
test -f /tmp/f/1; test ! -s /tmp/f/1
test $(stat -c %U:%G:%a /tmp/f/1) = "root:root:644"
test "$(stat -c %U:%G:%a /tmp/f/1)" = "root:root:644"

test $(stat -c %U:%G:%a /tmp/f/2) = "root:root:644"
test "$(stat -c %U:%G:%a /tmp/f/2)" = "root:root:644"
test "$(< /tmp/f/2)" = "This string should be written"

### The perms are supposed to be updated even if the file already exists.
Expand All @@ -32,7 +32,7 @@ EOF

# file should be empty
test ! -s /tmp/f/1
test $(stat -c %U:%G:%a /tmp/f/1) = "daemon:daemon:666"
test "$(stat -c %U:%G:%a /tmp/f/1)" = "daemon:daemon:666"

### But we shouldn't try to set perms on an existing file which is not a
### regular one.
Expand All @@ -44,7 +44,7 @@ f /tmp/f/fifo 0666 daemon daemon - This string should not be written
EOF

test -p /tmp/f/fifo
test $(stat -c %U:%G:%a /tmp/f/fifo) = "root:root:644"
test "$(stat -c %U:%G:%a /tmp/f/fifo)" = "root:root:644"

### 'f' should not follow symlinks.
ln -s missing /tmp/f/dangling
Expand All @@ -55,7 +55,7 @@ f /tmp/f/dangling 0644 daemon daemon - -
f /tmp/f/symlink 0644 daemon daemon - -
EOF
test ! -e /tmp/f/missing
test $(stat -c %U:%G:%a /tmp/file-owned-by-root) = "root:root:644"
test "$(stat -c %U:%G:%a /tmp/file-owned-by-root)" = "root:root:644"

### Handle read-only filesystem gracefully: we shouldn't fail if the target
### already exists and have the correct perms.
Expand All @@ -75,7 +75,7 @@ test -f /tmp/f/ro-fs/foo; test ! -s /tmp/f/ro-fs/foo
systemd-tmpfiles --create - <<EOF && { echo 'unexpected success'; exit 1; }
f /tmp/f/ro-fs/foo 0666 - - - -
EOF
test $(stat -c %U:%G:%a /tmp/f/fifo) = "root:root:644"
test "$(stat -c %U:%G:%a /tmp/f/fifo)" = "root:root:644"

systemd-tmpfiles --create - <<EOF && { echo 'unexpected success'; exit 1; }
f /tmp/f/ro-fs/bar 0644 - - - -
Expand Down Expand Up @@ -109,9 +109,9 @@ test -f /tmp/F/created; test ! -s /tmp/F/created
test -f /tmp/F/created-with-content
test "$(< /tmp/F/created-with-content)" = "new content"
test -f /tmp/F/truncated; test ! -s /tmp/F/truncated
test $(stat -c %U:%G:%a /tmp/F/truncated) = "daemon:daemon:666"
test "$(stat -c %U:%G:%a /tmp/F/truncated)" = "daemon:daemon:666"
test -s /tmp/F/truncated-with-content
test $(stat -c %U:%G:%a /tmp/F/truncated-with-content) = "daemon:daemon:666"
test "$(stat -c %U:%G:%a /tmp/F/truncated-with-content)" = "daemon:daemon:666"

### We shouldn't try to truncate anything but regular files since the behavior is
### unspecified in the other cases.
Expand All @@ -132,7 +132,7 @@ f /tmp/F/dangling 0644 daemon daemon - -
f /tmp/F/symlink 0644 daemon daemon - -
EOF
test ! -e /tmp/F/missing
test $(stat -c %U:%G:%a /tmp/file-owned-by-root) = "root:root:644"
test "$(stat -c %U:%G:%a /tmp/file-owned-by-root)" = "root:root:644"

### Handle read-only filesystem gracefully: we shouldn't fail if the target
### already exists and is empty.
Expand Down Expand Up @@ -165,7 +165,7 @@ grep -q 'truncating is not allowed' /tmp/F/ro-fs/foo
systemd-tmpfiles --create - <<EOF && { echo 'unexpected success'; exit 1; }
F /tmp/F/ro-fs/foo 0666 - - - -
EOF
test $(stat -c %U:%G:%a /tmp/F/ro-fs/foo) = "root:root:644"
test "$(stat -c %U:%G:%a /tmp/F/ro-fs/foo)" = "root:root:644"

### Try to create a new file.
systemd-tmpfiles --create - <<EOF && { echo 'unexpected success'; exit 1; }
Expand Down
4 changes: 2 additions & 2 deletions test/units/testsuite-22.04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ p /tmp/p/fifo1 0666 - - - -
EOF

test -p /tmp/p/fifo1
test $(stat -c %U:%G:%a /tmp/p/fifo1) = "root:root:666"
test "$(stat -c %U:%G:%a /tmp/p/fifo1)" = "root:root:666"

# Refuse to overwrite an existing file. Error is not propagated.
systemd-tmpfiles --create - <<EOF
Expand All @@ -30,7 +30,7 @@ p+ /tmp/p/f1 0666 - - - -
EOF

test -p /tmp/p/f1
test $(stat -c %U:%G:%a /tmp/p/f1) = "root:root:666"
test "$(stat -c %U:%G:%a /tmp/p/f1)" = "root:root:666"

#
# Must be fixed
Expand Down
Loading

0 comments on commit 3882526

Please sign in to comment.