diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fae3221f..9460e706 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,7 +31,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: install dependencies - run: brew install pkg-config libtool autoconf automake groff + run: brew install libtool autoconf automake - name: configure run: LSOF_INCLUDE=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include ./Configure -n darwin - name: make @@ -42,10 +42,9 @@ jobs: run: | git clean -fdx . autoreconf -vif - ./configure + ./configure --disable-manpages make DESTDIR=$PWD/prefix make install - make check - name: dist build and test run: | make dist @@ -53,7 +52,7 @@ jobs: cd temp tar xvf ../lsof-*.tar.gz cd lsof-* - ./configure + ./configure --disable-manpages make DESTDIR=$PWD/prefix make install make check diff --git a/tests/case-23-multi-address-hostname.bash b/tests/case-23-multi-address-hostname.bash index a0b8a875..768d0f8a 100755 --- a/tests/case-23-multi-address-hostname.bash +++ b/tests/case-23-multi-address-hostname.bash @@ -13,22 +13,42 @@ if ! command -v python3 >/dev/null 2>&1; then fi host=$(hostname) +# Resolving a .local host name through mDNS can block for a long time on some +# machines. Five seconds is a pragmatic prerequisite lookup limit on all +# platforms; a timeout skips the test rather than using partial results. naddr=$(python3 - "$host" <<'PY' +import os import socket import sys +import threading host = sys.argv[1] -count = 0 -for family in (socket.AF_INET, socket.AF_INET6): - try: - infos = socket.getaddrinfo(host, None, family, socket.SOCK_STREAM) - except OSError: - continue - count = max(count, len({info[4][0] for info in infos})) -print(count) +count = [0] + +def resolve(): + for family in (socket.AF_INET, socket.AF_INET6): + try: + infos = socket.getaddrinfo(host, None, family, socket.SOCK_STREAM) + except OSError: + continue + count[0] = max(count[0], len({info[4][0] for info in infos})) + +resolver = threading.Thread(target=resolve, daemon=True) +resolver.start() +resolver.join(5) +if resolver.is_alive(): + print("timeout", flush=True) + os._exit(0) +print(count[0], flush=True) +os._exit(0) PY ) +if [ "$naddr" = timeout ]; then + echo "SKIP: hostname resolution timed out after 5 seconds" >> "$report" + exit 77 +fi + if [ "${naddr:-0}" -lt 2 ]; then echo "SKIP: $host resolves to fewer than two addresses in one family" \ >> "$report" @@ -37,7 +57,27 @@ fi { echo "host name: $host ($naddr addresses in one address family)" - $lsof -a -i@"$host" -p $$ >/dev/null 2>&1 + # Bound lsof's own lookup as well. Once the prerequisite succeeds, a hang + # is a test failure. subprocess.run kills and reaps the child on timeout. + python3 - "$lsof" "$host" "$$" <<'PY' +import subprocess +import sys + +try: + result = subprocess.run( + [sys.argv[1], "-a", "-i@" + sys.argv[2], "-p", sys.argv[3]], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + timeout=15, + ) +except subprocess.TimeoutExpired: + print("FAIL: lsof timed out after 15 seconds", flush=True) + sys.exit(124) + +# Preserve signal failures rather than mapping a negative return code to a +# shell status that could be mistaken for success or no matching files. +sys.exit(result.returncode if result.returncode >= 0 else 128 - result.returncode) +PY status=$? case $status in 0|1)