1#!/usr/bin/env bash 2# SPDX-License-Identifier: LGPL-2.1-or-later 3set -eux 4set -o pipefail 5 6systemd-analyze log-level debug 7systemd-analyze log-target console 8 9# Create a binary for which execve() will fail 10touch /tmp/brokenbinary 11chmod +x /tmp/brokenbinary 12 13# These three commands should succeed. 14systemd-run --unit=one -p Type=simple /bin/sleep infinity 15systemd-run --unit=two -p Type=simple -p User=idontexist /bin/sleep infinity 16systemd-run --unit=three -p Type=simple /tmp/brokenbinary 17 18# And now, do the same with Type=exec, where the latter two should fail 19systemd-run --unit=four -p Type=exec /bin/sleep infinity 20systemd-run --unit=five -p Type=exec -p User=idontexist /bin/sleep infinity && { echo 'unexpected success'; exit 1; } 21systemd-run --unit=six -p Type=exec /tmp/brokenbinary && { echo 'unexpected success'; exit 1; } 22 23systemd-run --unit=seven -p KillSignal=SIGTERM -p RestartKillSignal=SIGINT -p Type=exec /bin/sleep infinity 24# Both TERM and SIGINT happen to have the same number on all architectures 25test "$(systemctl show --value -p KillSignal seven.service)" -eq 15 26test "$(systemctl show --value -p RestartKillSignal seven.service)" -eq 2 27 28systemctl restart seven.service 29systemctl stop seven.service 30 31# For issue #20933 32 33# Should work normally 34busctl call \ 35 org.freedesktop.systemd1 /org/freedesktop/systemd1 \ 36 org.freedesktop.systemd1.Manager StartTransientUnit \ 37 "ssa(sv)a(sa(sv))" test-20933-ok.service replace 1 \ 38 ExecStart "a(sasb)" 1 \ 39 /usr/bin/sleep 2 /usr/bin/sleep 1 true \ 40 0 41 42# DBus call should fail but not crash systemd 43busctl call \ 44 org.freedesktop.systemd1 /org/freedesktop/systemd1 \ 45 org.freedesktop.systemd1.Manager StartTransientUnit \ 46 "ssa(sv)a(sa(sv))" test-20933-bad.service replace 1 \ 47 ExecStart "a(sasb)" 1 \ 48 /usr/bin/sleep 0 true \ 49 0 && { echo 'unexpected success'; exit 1; } 50 51# Same but with the empty argv in the middle 52busctl call \ 53 org.freedesktop.systemd1 /org/freedesktop/systemd1 \ 54 org.freedesktop.systemd1.Manager StartTransientUnit \ 55 "ssa(sv)a(sa(sv))" test-20933-bad-middle.service replace 1 \ 56 ExecStart "a(sasb)" 3 \ 57 /usr/bin/sleep 2 /usr/bin/sleep 1 true \ 58 /usr/bin/sleep 0 true \ 59 /usr/bin/sleep 2 /usr/bin/sleep 1 true \ 60 0 && { echo 'unexpected success'; exit 1; } 61 62systemd-analyze log-level info 63 64echo OK >/testok 65 66exit 0 67