File: TEST-74-AUX-UTILS.socket-activate.sh

package info (click to toggle)
systemd 259-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 105,132 kB
  • sloc: ansic: 726,480; xml: 121,118; python: 36,740; sh: 35,016; cpp: 946; makefile: 273; awk: 102; lisp: 13; sed: 1
file content (36 lines) | stat: -rwxr-xr-x 1,193 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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

PID="$(systemd-notify --fork -- systemd-socket-activate -l 1234 --accept --inetd cat)"
assert_in systemd-socket "$(cat /proc/"$PID"/comm)"
assert_eq "$(echo -n hello | socat - 'TCP:localhost:1234')" hello
assert_in systemd-socket "$(cat /proc/"$PID"/comm)"
kill "$PID"
tail --pid="$PID" -f /dev/null

PID=$(systemd-notify --fork -- systemd-socket-activate -l 1234 --now socat ACCEPT-FD:3 PIPE)
for _ in {1..100}; do
    sleep 0.1
    if [[ ! -d "/proc/$PID" ]]; then
        # ACCEPT-FD is available since socat v1.8
        : "systemd-socket-activate or socat died. Maybe socat does not support ACCEPT-FD. Skipping test."
        break
    fi

    if [[ "$(cat /proc/"$PID"/comm || :)" =~ socat ]]; then
        assert_eq "$(echo -n bye | socat - 'TCP:localhost:1234')" bye
        tail --pid="$PID" -f /dev/null
        break
    fi
done

# --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)