summaryrefslogtreecommitdiff
path: root/test/units/testsuite-23.sh
blob: 5488447a87653a4de8b3ecec7035e05701830b68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
set -eux
set -o pipefail

systemd-analyze log-level debug
systemd-analyze log-target console

# 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
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; }

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
test "$(systemctl show --value -p KillSignal seven.service)" -eq 15
test "$(systemctl show --value -p RestartKillSignal seven.service)" -eq 2

systemctl restart seven.service
systemctl stop seven.service

# 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; }

systemd-analyze log-level info

echo OK >/testok

exit 0