1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-06-10 03:36:52 +00:00

Corrected regression of ignoreeof

This commit is contained in:
Gerhard Rieger 2025-01-29 21:55:18 +01:00
parent 9968ca4c5b
commit fa67d7d380
3 changed files with 71 additions and 23 deletions

View file

@ -10,6 +10,10 @@ Corrections:
filan -s displayed "(stream)" instead of "tcp" with addresses
(regression).
Fixed a bug that made ignoreeof fail in 1.8.0.0 and 1.8.0.1;
corrected test IGNOREEOF.
Thanks to Rusty Bird for the precise problem report.
Building:
Disabling certain features during configure could break build process.

View file

@ -1013,7 +1013,7 @@ int _socat(void) {
/* for ignoreeof */
if (polling) {
if (!wasaction) {
if (socat_opts.total_timeout.tv_usec <= 1000000) {
if (socat_opts.total_timeout.tv_usec < 1000000) {
if (total_timeout.tv_usec < socat_opts.pollintv.tv_usec) {
total_timeout.tv_usec += 1000000;
total_timeout.tv_sec -= 1;

88
test.sh
View file

@ -3521,67 +3521,110 @@ esac
N=$((N+1))
# Test the ignoreeof option in forward (left to right) direction
NAME=IGNOREEOF
case "$TESTS" in
*%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
TEST="$NAME: ignoreeof on file"
if ! eval $NUMCOND; then :; else
# Let Socat read from an empty file, this would terminate immediately due to
# EOF. Wait for more than one second, then append data to the file; when Socat
# transfers this data the test succeeded.
if ! eval $NUMCOND; then :;
elif ! cond=$(checkconds \
"" \
"" \
"" \
"STDIO FILE" \
"STDOUT FILE" \
"ignoreeof" \
"" ); then
$PRINTF "test $F_n $TEST... ${YELLOW}$cond${NORMAL}\n" $N
numCANT=$((numCANT+1))
listCANT="$listCANT $N"
else
ti="$td/test$N.file"
tf="$td/test$N.stdout"
te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
da="test$N $(date) $RANDOM"
CMD="$TRACE $SOCAT $opts -u file:\"$ti\",ignoreeof -"
# Note: the bug in 1.8.0.0 and 1.8.0.1 let Socat terminate in unidirectional
# mode after 1s, in bidirectional mode with traffic in reverse direction
# (var wasaction) immediately
CMD="$TRACE $SOCAT $opts -u FILE:\"$ti\",ignoreeof -"
printf "test $F_n $TEST... " $N
touch "$ti"
$CMD >"$tf" 2>"$te" &
bg=$!
sleep 0.1
# Up to 1.8.0.1 this sleep was 0.1 and thus the test said OK despite the bug
sleep 1.1
echo "$da" >>"$ti"
sleep 1
kill $bg 2>/dev/null; wait
if ! echo "$da" |diff - "$tf" >"$tdiff"; then
$PRINTF "$FAILED: diff:\n"
cat "$tdiff"
$PRINTF "$FAILED (diff)\n"
echo "$CMD"
cat "$te" >&2
echo "// diff:" >&2
cat "$tdiff" >&2
failed
else
$PRINTF "$OK\n"
if [ -n "$debug" ]; then cat $te; fi
ok
$PRINTF "$OK\n"
if [ -n "$VERBOSE" ]; then echo "$CMD"; fi
if [ -n "$DEBUG" ]; then cat "$te" >&2; fi
ok
fi
fi ;; # NUMCOND
esac
N=$((N+1))
# Test the ignoreeof option in reverse (right to left) direction
NAME=IGNOREEOF_REV
case "$TESTS" in
*%$N%*|*%functions%*|*%engine%*|*%ignoreeof%*|*%$NAME%*)
TEST="$NAME: ignoreeof on file right-to-left"
if ! eval $NUMCOND; then :; else
if ! eval $NUMCOND; then :;
elif ! cond=$(checkconds \
"" \
"" \
"" \
"STDIO FILE" \
"STDOUT FILE" \
"ignoreeof" \
"" ); then
$PRINTF "test $F_n $TEST... ${YELLOW}$cond${NORMAL}\n" $N
numCANT=$((numCANT+1))
listCANT="$listCANT $N"
else
# Let Socat read from an empty file, this would terminate immediately due to
# EOF. Wait for more than one second, then append data to the file; when Socat
# transfers this data the test succeeded.
ti="$td/test$N.file"
tf="$td/test$N.stdout"
te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
da="test$N $(date) $RANDOM"
CMD="$SOCAT $opts -U - file:\"$ti\",ignoreeof"
CMD="$SOCAT $opts -U - FILE:\"$ti\",ignoreeof"
printf "test $F_n $TEST... " $N
touch "$ti"
$CMD >"$tf" 2>"$te" &
bg=$!
relsleep 1
sleep 1.1
echo "$da" >>"$ti"
sleep 1
kill $bg 2>/dev/null
kill $bg 2>/dev/null; wait
if ! echo "$da" |diff - "$tf" >"$tdiff"; then
$PRINTF "$FAILED: diff:\n"
cat "$tdiff"
$PRINTF "$FAILED (diff)\n"
echo "$CMD"
cat "$te" >&2
echo "// diff:" >&2
cat "$tdiff" >&2
failed
else
$PRINTF "$OK\n"
if [ -n "$debug" ]; then cat $te; fi
ok
$PRINTF "$OK\n"
if [ -n "$VERBOSE" ]; then echo "$CMD"; fi
if [ -n "$DEBUG" ]; then cat "$te" >&2; fi
ok
fi
wait
fi ;; # NUMCOND
esac
N=$((N+1))
@ -3601,12 +3644,13 @@ $CMD >"$tf" 2>"$te"
if [ -s "$te" ]; then
$PRINTF "$FAILED: $TRACE $SOCAT:\n"
echo "$CMD"
cat "$te"
cat "$te" >&2
failed
else
$PRINTF "$OK\n"
if [ -n "$debug" ]; then cat $te; fi
ok
$PRINTF "$OK\n"
if [ -n "$VERBOSE" ]; then echo "$CMD"; fi
if [ -n "$DEBUG" ]; then cat "$te" >&2; fi
ok
fi
fi ;; # NUMCOND
esac