2020-03-04 12:35:06 +03:00
#!/usr/bin/env bash
2021-10-17 19:13:06 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2021-04-09 20:39:41 +03:00
set -eux
2018-07-17 13:35:12 +03:00
set -o pipefail
2019-04-03 09:19:08 +03:00
systemd-analyze log-level debug
systemd-analyze log-target console
2018-07-17 13:35:12 +03:00
# Create a binary for which execve() will fail
touch /tmp/brokenbinary
chmod +x /tmp/brokenbinary
# These three commands should succeed.
systemd-run --unit= one -p Type = simple /bin/sleep infinity
systemd-run --unit= two -p Type = simple -p User = idontexist /bin/sleep infinity
systemd-run --unit= three -p Type = simple /tmp/brokenbinary
# And now, do the same with Type=exec, where the latter two should fail
systemd-run --unit= four -p Type = exec /bin/sleep infinity
2021-04-08 02:27:33 +03:00
systemd-run --unit= five -p Type = exec -p User = idontexist /bin/sleep infinity && { echo 'unexpected success' ; exit 1; }
systemd-run --unit= six -p Type = exec /tmp/brokenbinary && { echo 'unexpected success' ; exit 1; }
2018-07-17 13:35:12 +03:00
2019-10-01 16:15:06 +03:00
systemd-run --unit= seven -p KillSignal = SIGTERM -p RestartKillSignal = SIGINT -p Type = exec /bin/sleep infinity
# Both TERM and SIGINT happen to have the same number on all architectures
2021-04-09 20:49:32 +03:00
test " $( systemctl show --value -p KillSignal seven.service) " -eq 15
test " $( systemctl show --value -p RestartKillSignal seven.service) " -eq 2
2019-10-01 16:15:06 +03:00
systemctl restart seven.service
systemctl stop seven.service
2021-10-05 14:10:31 +03:00
# For issue #20933
# Should work normally
busctl call \
org.freedesktop.systemd1 /org/freedesktop/systemd1 \
org.freedesktop.systemd1.Manager StartTransientUnit \
"ssa(sv)a(sa(sv))" test-20933-ok.service replace 1 \
ExecStart "a(sasb)" 1 \
/usr/bin/sleep 2 /usr/bin/sleep 1 true \
0
# DBus call should fail but not crash systemd
busctl call \
org.freedesktop.systemd1 /org/freedesktop/systemd1 \
org.freedesktop.systemd1.Manager StartTransientUnit \
"ssa(sv)a(sa(sv))" test-20933-bad.service replace 1 \
ExecStart "a(sasb)" 1 \
/usr/bin/sleep 0 true \
0 && { echo 'unexpected success' ; exit 1; }
# Same but with the empty argv in the middle
busctl call \
org.freedesktop.systemd1 /org/freedesktop/systemd1 \
org.freedesktop.systemd1.Manager StartTransientUnit \
"ssa(sv)a(sa(sv))" test-20933-bad-middle.service replace 1 \
ExecStart "a(sasb)" 3 \
/usr/bin/sleep 2 /usr/bin/sleep 1 true \
/usr/bin/sleep 0 true \
/usr/bin/sleep 2 /usr/bin/sleep 1 true \
0 && { echo 'unexpected success' ; exit 1; }
2019-04-03 09:19:08 +03:00
systemd-analyze log-level info
2018-07-17 13:35:12 +03:00
2021-04-08 01:09:55 +03:00
echo OK >/testok
2018-07-17 13:35:12 +03:00
exit 0