Fix error message on UI when testing Opossum

As `wait_kill()` returns with 0 when a TCP reset is encountered
and the process is not killed, we need to open the socket again
in a sub shell. Which is safe in the foreground.

If then the subshell returns with 0 we can safely connect to
port 80.
This commit is contained in:
Dirk Wetter 2025-07-20 15:40:35 +02:00
parent ea3cc3789f
commit e09d79aad9

View File

@ -1942,26 +1942,31 @@ http_head_printf() {
# This is a subshell, so fd 8 is not inherited # This is a subshell, so fd 8 is not inherited
bash -c "exec 8<>/dev/tcp/$node/80" 2>/dev/null & bash -c "exec 8<>/dev/tcp/$node/80" 2>/dev/null &
wait_kill $! $HEADER_MAXSLEEP wait_kill $! $HEADER_MAXSLEEP
if [[ $? -eq 0 ]]; then if [[ $? -ne 3 ]]; then
exec 33<>/dev/tcp/$node/80 # process with pid !$ wasn't killed but was that a reject? So we try again
# not killed --> socket open. Now we connect to the virtual host "$node" # to make sure there wasn't a TCP reset
printf -- "%b" "HEAD ${proto}//${node}/${query} HTTP/1.1\r\nUser-Agent: ${useragent}\r\nHost: ${node}\r\n${request_header}\r\nAccept: */*\r\n\r\n\r\n" >&33 2>$errfile bash -c "exec 8<>/dev/tcp/$node/80" 2>/dev/null
ret=0 if [[ $? -eq 0 ]]; then
if [[ $DEBUG -eq 0 ]] ; then exec 33<>/dev/tcp/$node/80
cat <&33 # not killed --> socket open. Now we connect to the virtual host "$node"
printf -- "%b" "HEAD ${proto}//${node}/${query} HTTP/1.1\r\nUser-Agent: ${useragent}\r\nHost: ${node}\r\n${request_header}\r\nAccept: */*\r\n\r\n\r\n" >&33 2>$errfile
ret=0
if [[ $DEBUG -eq 0 ]] ; then
cat <&33
else
cat <&33 >$tmpfile
cat $tmpfile
fi
else else
cat <&33 >$tmpfile if [[ -n "$PROXY" ]]; then
cat $tmpfile ret=3
fi else
else ret=1
if [[ -n "$PROXY" ]]; then fi
ret=3
else
ret=1
fi fi
exec 33<&-
exec 33>&-
fi fi
exec 33<&-
exec 33>&-
return $ret return $ret
} }