Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,18 +42,17 @@ 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
mkdir temp
cd temp
tar xvf ../lsof-*.tar.gz
cd lsof-*
./configure
./configure --disable-manpages
make
DESTDIR=$PWD/prefix make install
make check
Expand Down
58 changes: 49 additions & 9 deletions tests/case-23-multi-address-hostname.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
Loading