2023-05-16 21:31:49 +03:00
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
# shellcheck disable=SC2016
set -eux
set -o pipefail
# Test adding new BindPaths while unit is already running
at_exit( ) {
set +e
rm -f /run/testsuite-23-marker-{ fixed,runtime}
rm -fr /run/inaccessible
}
trap at_exit EXIT
echo "MARKER_FIXED" >/run/testsuite-23-marker-fixed
mkdir /run/inaccessible
systemctl start testsuite-23-namespaced.service
# Ensure that inaccessible paths aren't bypassed by the runtime setup,
( ! systemctl bind --mkdir testsuite-23-namespaced.service /run/testsuite-23-marker-fixed /run/inaccessible/testfile-marker-fixed)
2023-09-29 03:50:15 +03:00
echo "MARKER_WRONG" >/run/testsuite-23-marker-wrong
2023-05-16 21:31:49 +03:00
echo "MARKER_RUNTIME" >/run/testsuite-23-marker-runtime
2023-09-29 03:50:15 +03:00
# Mount twice to exercise mount-beneath (on kernel 6.5+, on older kernels it will just overmount)
systemctl bind --mkdir testsuite-23-namespaced.service /run/testsuite-23-marker-wrong /tmp/testfile-marker-runtime
test " $( systemctl show -P SubState testsuite-23-namespaced.service) " = "running"
2023-05-16 21:31:49 +03:00
systemctl bind --mkdir testsuite-23-namespaced.service /run/testsuite-23-marker-runtime /tmp/testfile-marker-runtime
2023-05-17 21:14:05 +03:00
timeout 10 bash -xec 'while [[ "$(systemctl show -P SubState testsuite-23-namespaced.service)" == running ]]; do sleep .5; done'
2023-05-16 21:31:49 +03:00
systemctl is-active testsuite-23-namespaced.service
# Now test that systemctl bind fails when attempted on a non-namespaced unit
systemctl start testsuite-23-non-namespaced.service
( ! systemctl bind --mkdir testsuite-49-non-namespaced.service /run/testsuite-23-marker-runtime /tmp/testfile-marker-runtime)
2023-05-17 21:14:05 +03:00
timeout 10 bash -xec 'while [[ "$(systemctl show -P SubState testsuite-23-non-namespaced.service)" == running ]]; do sleep .5; done'
2023-05-16 21:31:49 +03:00
( ! systemctl is-active testsuite-23-non-namespaced.service)