]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add simple tests for systemd-socket-activate tool 37620/head
authorDaniel Foster <daniel@amesite.me>
Tue, 27 May 2025 03:43:39 +0000 (13:43 +1000)
committerDaniel Foster <daniel@amesite.me>
Sun, 15 Jun 2025 06:34:16 +0000 (16:34 +1000)
mkosi/mkosi.sanitizers/mkosi.postinst
test/units/TEST-74-AUX-UTILS.socket-activate.sh [new file with mode: 0755]

index 582a7cb99d4752c3534dd9e4188069000e8c250d..ee26021c3272335f55600ec0edb59fabd2747b05 100755 (executable)
@@ -77,6 +77,7 @@ wrap=(
     ps
     setfacl
     setpriv
+    socat
     sshd
     stat
     su
diff --git a/test/units/TEST-74-AUX-UTILS.socket-activate.sh b/test/units/TEST-74-AUX-UTILS.socket-activate.sh
new file mode 100755 (executable)
index 0000000..b714ae4
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+# shellcheck source=test/units/util.sh
+. "$(dirname "$0")"/util.sh
+
+CAT_PID="$(systemd-notify --fork -- systemd-socket-activate -l 1234 --accept --inetd cat)"
+assert_eq "$(echo -n hello | socat - 'TCP:localhost:1234')" hello
+kill "$CAT_PID"
+
+# Check whether socat's ACCEPT-FD is available (introduced in v1.8)
+systemd-socket-activate -l 1234 --now socat ACCEPT-FD:3 PIPE &
+sleep 1
+jobs >/dev/null
+if kill %% &>/dev/null; then
+    systemd-socket-activate -l 1234 --now socat ACCEPT-FD:3 PIPE &
+    SOCAT_PID="$!"
+
+    # unfortunately we need to sleep since socket-activate only sends sd_notify when --accept is passed,
+    # so we can't rely on that to avoid a race.
+    sleep 1
+
+    assert_in socat "$(</proc/"$SOCAT_PID"/comm)"
+    assert_eq "$(echo -n bye | socat - 'TCP:localhost:1234')" bye
+fi
+
+# --accept is not allowed with --now
+(! systemd-socket-activate -l 1234 --accept --now cat)
+
+# Multiple fds are not allowed with --inetd
+(! systemd-socket-activate -l 1234 -l 4321 --inetd cat)