1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-07-09 21:56:33 +00:00

Procan: Try to identify controlling terminal

This commit is contained in:
Gerhard Rieger 2023-11-11 17:45:02 +01:00
parent cd5673dbd0
commit 27877ea777
7 changed files with 314 additions and 36 deletions

140
test.sh
View file

@ -1148,6 +1148,90 @@ waitip4proto () {
return 1
}
# Perform a couple of checks to make sure the test has a chance of a useful
# result:
# platform is supported, features compiled in, addresses and options
# available; needs root; is allowed to access the internet
checkconds() {
local unames="$(echo "$1")" # must be one of... exa: "Linux,FreeBSD"
local root="$2" # "root" or ""
local progs="$(echo "$3" |tr 'A-Z,' 'a-z ')" # exa: "nslookup"
local feats="$(echo "$4" |tr 'a-z,' 'A-Z ')" # list of req.features (socat -V)
local addrs="$(echo "$5" |tr 'a-z,' 'A-Z ')" # list of req.addresses (socat -h)
local opts="$(echo "$6" |tr 'A-Z,' 'a-z ')" # list of req.options (socat -hhh)
local runs="$(echo "$7" |tr , ' ')" # list of req.protocols, exa: "sctp6"
local inet="$8" # when "internet": needs allowance
local i
if [ "$unames" ]; then
local uname="$(echo $UNAME |tr 'A-Z' 'a-z')"
for i in $unames; do
if [ "$uname" = "$(echo "$i" |tr 'A-Z,' 'a-z ')" ]; then
# good, mark as passed
i=
break;
fi
done
[ "$i" ] && { echo "Only on (one of) $unames"; return -1; }
fi
if [ "$root" = "root" ]; then
if [ $(id -u) -ne 0 -a "$withroot" -eq 0 ]; then
echo "Must be root"
return -1;
fi
fi
if [ "$progs" ]; then
for i in $progs; do
if ! type >/dev/null 2>&1; then
echo "Program $i not available"
return -1
fi
done
fi
if [ "$feats" ]; then
if ! F=$(testfeats $feats); then
echo "Feature $F not configured in $SOCAT"
return -1
fi
fi
if [ "$addrs" ]; then
if ! A=$(testaddrs - $addrs); then
echo "Address $A not available in $SOCAT"
return -1
fi
fi
if [ "$opts" ]; then
if ! o=$(testoptions $opts); then
echo "Option $o not available in $SOCAT"
return -1
fi
fi
if [ "$runs" ]; then
for i in $runs; do
if ! runs$i >/dev/null; then
echo "$i not available on host"
return -1;
fi
done
fi
if [ "$inet" ]; then
if [ -z "$FOREIGN" ]; then
echo "Use test.sh option -internet"
return -1
fi
fi
return 0
}
# we need this misleading function name for canonical reasons
waitip4port () {
waitip4proto "$1" "$2" "$3"
@ -17567,7 +17651,7 @@ tdiff="$td/test$N.diff"
da="$(echo test$N $(date) $RANDOM |tr ' :' '-')"
echo "$da" >"$td/test$N.da"
newport udp4 # or whatever proto, or drop this line
CMD0="$TRACE $SOCAT $opts -u UDP-RECVFROM:$PORT -"
CMD0="$TRACE $SOCAT $opts -u UDP4-RECVFROM:$PORT -"
CMD1="$TRACE $SOCAT $opts - TCP4:$da:0,res-nsaddr=$LOCALHOST:$PORT"
printf "test $F_n $TEST... " $N
$CMD0 >/dev/null 2>"${te}0" >"${tf}0" &
@ -18700,6 +18784,60 @@ UDPLITE6 UDPLITE udplite [::1] PORT shut-null
"
# Test the procan controlling terminal output
NAME=PROCAN_CTTY
case "$TESTS" in
*%$N%*|*%functions%*|*%procan%*|*%$NAME%*)
TEST="$NAME: test procan controlling terminal output"
# Run procan and compare its controlling terminal output with tty (oops)"
if ! eval $NUMCOND; then :
elif ! cond=$(checkconds \
"" \
"" \
"tty" \
"" \
"" \
"" \
"" ); then
$PRINTF "test $F_n $TEST... ${YELLOW}$cond${NORMAL}\n" $N
numCANT=$((numCANT+1))
listCANT="$listCANT $N"
else
tf="$td/test$N.stdout"
te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
CMD0="$TRACE $PROCAN"
printf "test $F_n $TEST... " $N
$CMD0 >"${tf}0" 2>"${te}0"
rc0=$?
if [ "$rc0" -ne 0 ]; then
$PRINTF "$FAILED\n"
echo "$CMD0"
cat "${te}0" >&2
numFAIL=$((numFAIL+1))
listFAIL="$listFAIL $N"
namesFAIL="$namesFAIL $NAME"
elif ! tty |diff - <(cat ${tf}0 |grep "controlling terminal" |grep -v -e '"/dev/tty"' -e none |head -n 1 |sed -e 's/controlling terminal by .*:[[:space:]]*//' -e 's/"//g') >$tdiff; then
$PRINTF "$FAILED\n"
echo "$CMD0"
cat "${te}0" >&2
echo "// diff:" >&2
cat "$tdiff" >&2
numFAIL=$((numFAIL+1))
listFAIL="$listFAIL $N"
namesFAIL="$namesFAIL $NAME"
else
$PRINTF "$OK\n"
if [ "$VERBOSE" ]; then echo "$CMD0"; fi
if [ "$DEBUG" ]; then cat "${te}0" >&2; fi
numOK=$((numOK+1))
fi
fi # NUMCOND
;;
esac
N=$((N+1))
# end of common tests
##################################################################################