summaryrefslogtreecommitdiffstats
path: root/test/units
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-10-23 23:00:53 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-31 02:59:14 +0100
commite79b58c825d7c04cdd2c48c8cffbd5fed192cde3 (patch)
tree9fadd3ae79c0587fbff745569de2b2bedb77b50c /test/units
parentmachined: ACQUIRE_METADATA_NO is zero (diff)
downloadsystemd-e79b58c825d7c04cdd2c48c8cffbd5fed192cde3.tar.xz
systemd-e79b58c825d7c04cdd2c48c8cffbd5fed192cde3.zip
TEST-13-NSPAWN: fix race between container exit and varlink call
Follow-up for 3cb72c7862d8950bc2a963aaa3ca3255eea374b6. The test container exits shortly, hence when varlinkctl is called, the container may be already terminated. Let's make the container live infinitely. Also, this makes the os-release files removed after the container is started.
Diffstat (limited to 'test/units')
-rwxr-xr-xtest/units/TEST-13-NSPAWN.machined.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/units/TEST-13-NSPAWN.machined.sh b/test/units/TEST-13-NSPAWN.machined.sh
index 244582677d..24eb673af3 100755
--- a/test/units/TEST-13-NSPAWN.machined.sh
+++ b/test/units/TEST-13-NSPAWN.machined.sh
@@ -304,7 +304,26 @@ varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.Unreg
# test io.systemd.Machine.List with addresses, OSRelease, and UIDShift fields
create_dummy_container "/var/lib/machines/container-without-os-release"
+cat >>/var/lib/machines/container-without-os-release/sbin/init <<\EOF
+PID=0
+
+trap 'kill 0' RTMIN+3
+trap 'kill $PID' EXIT
+
+# We need to wait for the sleep process asynchronously in order to allow
+# bash to process signals
+sleep infinity &
+
+# notify that the process is ready
+touch /ready
+
+PID=$!
+while :; do
+ wait || :
+done
+EOF
machinectl start "container-without-os-release"
+timeout 30 bash -c "until test -e /var/lib/machines/container-without-os-release/ready; do sleep .5; done"
rm -f /var/lib/machines/container-without-os-release/etc/os-release /var/lib/machines/container-without-os-release/usr/lib/os-release
(! varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": "container-without-os-release", "acquireMetadata": "yes"}')
varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": "container-without-os-release", "acquireMetadata": "graceful"}'