5 systemd-analyze log-level debug
6 systemd-analyze log-target console
8 test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$
10 # Start a test process inside of our own cgroup
15 # Start a test process outside of our own cgroup
16 systemd-run
-p DynamicUser
=1 --unit=test20-sleep.service
/bin
/sleep infinity
17 EXTERNALPID
="$(systemctl show -P MainPID test20-sleep.service)"
19 # Update our own main PID to the external test PID, this should work
20 systemd-notify MAINPID
="$EXTERNALPID"
21 test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$EXTERNALPID"
23 # Update our own main PID to the internal test PID, this should work, too
24 systemd-notify MAINPID
=$INTERNALPID
25 test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$INTERNALPID"
27 # Update it back to our own PID, this should also work
28 systemd-notify MAINPID
=$$
29 test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$
31 # Try to set it to PID 1, which it should ignore, because that's the manager
32 systemd-notify MAINPID
=1
33 test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$
35 # Try to set it to PID 0, which is invalid and should be ignored
36 systemd-notify MAINPID
=0
37 test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$
39 # Try to set it to a valid but non-existing PID, which should be ignored. (Note
40 # that we set the PID to a value well above any known /proc/sys/kernel/pid_max,
41 # which means we can be pretty sure it doesn't exist by coincidence)
42 systemd-notify MAINPID
=1073741824
43 test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$
45 # Change it again to the external PID, without privileges this time. This should be ignored, because the PID is from outside of our cgroup and we lack privileges.
46 systemd-notify
--uid=1000 MAINPID
="$EXTERNALPID"
47 test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$
49 # Change it again to the internal PID, without privileges this time. This should work, as the process is on our cgroup, and that's enough even if we lack privileges.
50 systemd-notify
--uid=1000 MAINPID
="$INTERNALPID"
51 test "$(systemctl show -P MainPID testsuite-20.service)" -eq "$INTERNALPID"
53 # Update it back to our own PID, this should also work
54 systemd-notify
--uid=1000 MAINPID
=$$
55 test "$(systemctl show -P MainPID testsuite-20.service)" -eq $$
57 cat >/tmp
/test20-mainpid.sh
<<EOF
63 # Create a number of children, and make one the main one
74 echo \$MAINPID >/run/mainpidsh/pid
76 chmod +x
/tmp
/test20-mainpid.sh
78 systemd-run
--unit=test20-mainpidsh.service
-p StandardOutput
=tty
-p StandardError
=tty
-p Type
=forking
-p RuntimeDirectory
=mainpidsh
-p PIDFile
=/run
/mainpidsh
/pid
/tmp
/test20-mainpid.sh
79 test "$(systemctl show -P MainPID test20-mainpidsh.service)" -eq "$(cat /run/mainpidsh/pid)"
81 cat >/tmp
/test20-mainpid2.sh
<<EOF
87 # Create a number of children, and make one the main one
98 echo \$MAINPID >/run/mainpidsh2/pid
99 chown 1001:1001 /run/mainpidsh2/pid
101 chmod +x
/tmp
/test20-mainpid2.sh
103 systemd-run
--unit=test20-mainpidsh2.service
-p StandardOutput
=tty
-p StandardError
=tty
-p Type
=forking
-p RuntimeDirectory
=mainpidsh2
-p PIDFile
=/run
/mainpidsh
2/pid
/tmp
/test20-mainpid2.sh
104 test "$(systemctl show -P MainPID test20-mainpidsh2.service)" -eq "$(cat /run/mainpidsh2/pid)"
106 cat >/dev
/shm
/test20-mainpid3.sh
<<EOF
121 # Let's try to play games, and link up a privileged PID file
122 ln -s ../mainpidsh/pid /run/mainpidsh3/pid
124 # Quick assertion that the link isn't dead
125 test -f /run/mainpidsh3/pid
127 chmod 755 /dev
/shm
/test20-mainpid3.sh
129 # This has to fail, as we shouldn't accept the dangerous PID file, and then
130 # inotify-wait on it to be corrected which we never do.
131 systemd-run
--unit=test20-mainpidsh3.service \
132 -p StandardOutput
=tty \
133 -p StandardError
=tty \
135 -p RuntimeDirectory
=mainpidsh3 \
136 -p PIDFile
=/run
/mainpidsh
3/pid \
138 -p TimeoutStartSec
=2s \
139 /dev
/shm
/test20-mainpid3.sh \
140 && { echo 'unexpected success'; exit 1; }
142 # Test that this failed due to timeout, and not some other error
143 test "$(systemctl show -P Result test20-mainpidsh3.service)" = timeout
145 systemd-analyze log-level info