#!/bin/sh set -ue PATH="/usr/bin:/bin" export PATH PORT=12345 TIMEOUT=10 if [ -n "${AUTOPKGTEST_TMP+x}" ]; then NC="$(command -v nc.openbsd)" TEMPDIR="$AUTOPKGTEST_TMP" else NC="./nc" TEMPDIR="${TMPDIR:-/tmp}" fi echo "I: Using NC=$NC and TEMPDIR=$TEMPDIR" # Basic client/server communication test check() { local timeout="$TIMEOUT" echo "Checking \`$NC [-l|-N] $*\`..." $NC -l "$@" "$TEMPDIR/stdout" & PID=$! head -c240 "$TEMPDIR/stdin" while [ $timeout -ge 0 ] && ! $NC -N "$@" <"$TEMPDIR/stdin" 2>&1; do # give the server a chance to bind(2) and listen(2) echo "Retrying..." sleep 1 timeout=$((timeout - 1)) done if [ $timeout -le 0 ]; then echo "Timeout" >&2 kill $PID exit 1 fi wait $PID diff -u -- "$TEMPDIR/stdin" "$TEMPDIR/stdout" || exit 1 } check 127.0.0.1 $PORT if $NC -z 127.0.0.1 $PORT; then echo "Still listening on $PORT" >&2 exit 1 fi # UNIX domain sockets (blindly assume "$TEMPDIR" is of length <=UNIX_PATH_MAX-23) sun_path="$TEMPDIR/nc-client-server.sock" check -U "$sun_path" if ! test -S "$sun_path"; then echo "No such socket $sun_path" >&2 exit 1 fi # abstract UNIX domain socket uname_s="$(uname -s)" if [ "$uname_s" = "Linux" ]; then check -U @"/nonexistent/netcat-openbsd/client-server" # 108-bytes long sun_path (assume UNIX_PATH_MAX is 108 on Linux) with no NUL byte other than the one at index 0 check -U @"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/autopkgtest/netcat-openbsd/client-server" fi exit 0 # vim: set filetype=sh :