Fix the standalone port check on the bsds, macos and haiku

This commit is contained in:
neil
2026-08-30 17:39:57 +08:00 Unverified
parent 4756183e30
commit cce4a28b99
2 changed files with 50 additions and 19 deletions
+9 -1
View File
@@ -56,7 +56,15 @@ jobs:
envs: 'TEST_LOCAL TestingDomain TEST_ACME_Server CA_ECDSA CA CA_EMAIL TEST_PREFERRED_CHAIN'
nat: |
"8080": "80"
prepare: dnf install -y curl socat cronie tar gzip
prepare: |
# openEuler ships every repo with both a baseurl and a metalink.
# The metalink mirror pool is split-brain (dl-cdn.openeuler.openatom.cn
# froze at the 2026-08-20 snapshot while repo.openeuler.org moved on),
# so dnf takes repomd.xml from the stale mirror and then 404s fetching
# the checksummed metadata it names from the fresh ones. Keep only the
# vendor baseurl, which is self-consistent.
sed -i '/^metalink=/d' /etc/yum.repos.d/*.repo
dnf install -y curl socat cronie tar gzip
usesh: true
sync: rsync
copyback: false
+41 -18
View File
@@ -1482,39 +1482,57 @@ _readKeyLengthFromCSR() {
fi
}
#port
#Reads a netstat or ss listing on stdin, prints the lines that show a socket
#listening on port.
#Linux and windows print the local address as "addr:port", aix, macos, the
#bsds and solaris print it as "addr.port", so both separators must match.
#The state is "LISTEN" nearly everywhere, "LISTENING" on windows and lower
#case "listen" on haiku, hence the substring match and the -i.
_filter_listen_port() {
_flp_port="$1"
if [ -z "$_flp_port" ]; then
return
fi
grep -i "LISTEN" | grep "[:.]$_flp_port "
}
#port
_ss() {
_port="$1"
if _exists "ss"; then
_debug "Using: ss"
ss -ntpl 2>/dev/null | grep ":$_port "
ss -ntpl 2>/dev/null | _filter_listen_port "$_port"
return 0
fi
if [ "$(uname)" = "AIX" ]; then
_debug "Using: AIX netstat"
netstat -an | grep "^tcp" | grep "LISTEN" | grep "\.$_port "
#aix, macos and the bsds have no "-p protocol" socket listing that works on
#all of them: on netbsd "-p" is "Show statistics about protocol" instead
#(netstat(1), NetBSD 10.1). Their default display does show "the state of
#all sockets" with -a, so use that and keep only the tcp lines.
case "$(uname)" in
AIX | Darwin | DragonFly | *BSD*)
_debug "Using: AIX/BSD netstat"
netstat -an | grep "^tcp" | _filter_listen_port "$_port"
return 0
fi
;;
esac
if _exists "netstat"; then
_debug "Using: netstat"
if netstat -help 2>&1 | grep "\-p proto" >/dev/null; then
#for windows version netstat tool
netstat -an -p tcp | grep "LISTENING" | grep ":$_port "
netstat -an -p tcp | _filter_listen_port "$_port"
elif netstat -help 2>&1 | grep -- '-P protocol' >/dev/null; then
#for solaris
netstat -an -P tcp | _filter_listen_port "$_port"
elif netstat -help 2>&1 | grep "\-p" >/dev/null; then
#for full linux
netstat -ntpl | _filter_listen_port "$_port"
else
if netstat -help 2>&1 | grep "\-p protocol" >/dev/null; then
netstat -an -p tcp | grep LISTEN | grep ":$_port "
elif netstat -help 2>&1 | grep -- '-P protocol' >/dev/null; then
#for solaris
netstat -an -P tcp | grep "\.$_port " | grep "LISTEN"
elif netstat -help 2>&1 | grep "\-p" >/dev/null; then
#for full linux
netstat -ntpl | grep ":$_port "
else
#for busybox (embedded linux; no pid support)
netstat -ntl 2>/dev/null | grep ":$_port "
fi
#for busybox (embedded linux; no pid support)
netstat -ntl 2>/dev/null | _filter_listen_port "$_port"
fi
return 0
fi
@@ -3938,6 +3956,11 @@ _on_before_issue() {
if [ -z "$netprc" ]; then
netprc="$(echo "$_netprc" | grep "$LOCAL_ANY_ADDRESS:$_checkport")"
fi
if [ -z "$netprc" ]; then
#aix, macos, the bsds and solaris print the wildcard local address as
#"*.port", not "0.0.0.0:port", and it blocks $_checkaddr just the same
netprc="$(echo "$_netprc" | grep " [*][:.]$_checkport ")"
fi
if [ "$netprc" ]; then
_err "$netprc"
_err "tcp port $_checkport is already used by $(echo "$netprc" | cut -d : -f 4)"