From: Daniel Foster Date: Tue, 27 May 2025 03:43:39 +0000 (+1000) Subject: test: add simple tests for systemd-socket-activate tool X-Git-Tag: v258-rc1~318^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F37620%2Fhead;p=thirdparty%2Fsystemd.git test: add simple tests for systemd-socket-activate tool --- diff --git a/mkosi/mkosi.sanitizers/mkosi.postinst b/mkosi/mkosi.sanitizers/mkosi.postinst index 582a7cb99d4..ee26021c327 100755 --- a/mkosi/mkosi.sanitizers/mkosi.postinst +++ b/mkosi/mkosi.sanitizers/mkosi.postinst @@ -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 index 00000000000..b714ae46c95 --- /dev/null +++ b/test/units/TEST-74-AUX-UTILS.socket-activate.sh @@ -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 "$(