mirror of
https://github.com/moparisthebest/socat
synced 2024-12-21 14:38:48 -05:00
corrected option handling with stdio
This commit is contained in:
parent
3b3b004ff8
commit
edd6dae2de
2
CHANGES
2
CHANGES
@ -27,6 +27,8 @@ corrections:
|
||||
UDP-RECVFROM, IP-RECVFROM, UNIX-RECVFROM, ABSTRACT-RECVFROM
|
||||
(thanks to Evan Borgstrom for reporting this problem)
|
||||
|
||||
corrected option handling with STDIO; usecase: cool-write
|
||||
|
||||
corrected some print statements and variable names
|
||||
|
||||
make uninstall did not uninstall procan
|
||||
|
2
VERSION
2
VERSION
@ -1 +1 @@
|
||||
"1.6.0.0+execpty+servres+fd_setsize+udp_sigchld"
|
||||
"1.6.0.0+execpty+servres+fd_setsize+udp_sigchld+stdio_opts"
|
||||
|
49
test.sh
49
test.sh
@ -6895,7 +6895,7 @@ N=$((N+1))
|
||||
|
||||
NAME=COOLWRITE
|
||||
case "$TESTS" in
|
||||
*%functions%*|*%timeout%*|*%ignoreeof%*|*%$NAME%*)
|
||||
*%functions%*|*%timeout%*|*%ignoreeof%*|*%coolwrite%*|*%$NAME%*)
|
||||
TEST="$NAME: option cool-write"
|
||||
if ! testoptions cool-write >/dev/null; then
|
||||
$PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
|
||||
@ -6932,6 +6932,53 @@ esac
|
||||
N=$((N+1))
|
||||
|
||||
|
||||
# test if option coolwrite can be applied to bidirectional address stdio
|
||||
# this failed up to socat 1.6.0.0
|
||||
NAME=COOLSTDIO
|
||||
case "$TESTS" in
|
||||
*%functions%*|*%timeout%*|*%ignoreeof%*|*%coolwrite%*|*%$NAME%*)
|
||||
TEST="$NAME: option cool-write on bidirectional stdio"
|
||||
# this test starts a socat reader that terminates after receiving one+
|
||||
# bytes (option readbytes); and a test process that sends two bytes via
|
||||
# named pipe to the receiving process and, a second later, sends another
|
||||
# byte. The last write will fail with "broken pipe"; if option coolwrite
|
||||
# has been applied successfully, socat will terminate with 0 (OK),
|
||||
# otherwise with error.
|
||||
if ! testoptions cool-write >/dev/null; then
|
||||
$PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
|
||||
numCANT=$((numCANT+1))
|
||||
else
|
||||
#set -vx
|
||||
ti="$td/test$N.pipe"
|
||||
tf="$td/test$N.stdout"
|
||||
te="$td/test$N.stderr"
|
||||
tdiff="$td/test$N.diff"
|
||||
da="$(date) $RANDOM"
|
||||
# a reader that will terminate after 1 byte
|
||||
CMD1="$SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null"
|
||||
CMD="$SOCAT $opts -,cool-write pipe >\"$ti\""
|
||||
printf "test $F_n $TEST... " $N
|
||||
$CMD1 2>"${te}1" &
|
||||
bg=$! # background process id
|
||||
sleep 1
|
||||
(echo .; sleep 1; echo) |eval "$CMD" 2>"$te"
|
||||
rc=$?
|
||||
kill $bg 2>/dev/null; wait
|
||||
if [ $rc -ne 0 ]; then
|
||||
$PRINTF "$FAILED: $SOCAT:\n"
|
||||
echo "$CMD &"
|
||||
cat "$te"
|
||||
numFAIL=$((numFAIL+1))
|
||||
else
|
||||
$PRINTF "$OK\n"
|
||||
if [ -n "$debug" ]; then cat "$te"; fi
|
||||
numOK=$((numOK+1))
|
||||
fi
|
||||
fi # testoptions
|
||||
esac
|
||||
N=$((N+1))
|
||||
|
||||
|
||||
NAME=TCP4ENDCLOSE
|
||||
case "$TESTS" in
|
||||
*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
|
||||
|
54
xio-stdio.c
54
xio-stdio.c
@ -1,5 +1,5 @@
|
||||
/* source: xio-stdio.c */
|
||||
/* Copyright Gerhard Rieger 2001-2006 */
|
||||
/* Copyright Gerhard Rieger 2001-2008 */
|
||||
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||
|
||||
/* this file contains the source for opening addresses stdio type */
|
||||
@ -29,8 +29,8 @@ const struct addrdesc addr_stderr = { "stderr", 2, xioopen_stdfd, GROUP_FD|GROUP
|
||||
/* process a bidirectional "stdio" or "-" argument with options.
|
||||
generate a dual address. */
|
||||
int xioopen_stdio_bi(xiofile_t *sock) {
|
||||
struct opt *opts1, *opts2, *optspr;
|
||||
unsigned int groups1 = addr_stdio.groups, groups2 = addr_stdio.groups;
|
||||
struct opt *optspr;
|
||||
unsigned int groups1 = addr_stdio.groups;
|
||||
int result;
|
||||
|
||||
if (xioopen_makedual(sock) < 0) {
|
||||
@ -67,9 +67,6 @@ int xioopen_stdio_bi(xiofile_t *sock) {
|
||||
}
|
||||
#endif /* WITH_TERMIOS */
|
||||
|
||||
if (applyopts_single(&sock->stream, sock->stream.opts, PH_INIT) < 0) return -1;
|
||||
applyopts(-1, sock->stream.opts, PH_INIT);
|
||||
|
||||
/* options here are one-time and one-direction, no second use */
|
||||
retropt_bool(sock->stream.opts, OPT_IGNOREEOF, &sock->dual.stream[0]->ignoreeof);
|
||||
|
||||
@ -77,38 +74,59 @@ int xioopen_stdio_bi(xiofile_t *sock) {
|
||||
if ((optspr = copyopts(sock->stream.opts, GROUP_PROCESS)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
/* here we copy opts, because most have to be applied twice! */
|
||||
if ((sock->dual.stream[1]->opts = copyopts(sock->stream.opts, GROUP_FD|GROUP_APPL|(groups1&~GROUP_PROCESS))) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
sock->dual.stream[0]->opts = sock->stream.opts;
|
||||
sock->stream.opts = NULL;
|
||||
|
||||
if (applyopts_single(sock->dual.stream[0],
|
||||
sock->dual.stream[0]->opts, PH_INIT)
|
||||
< 0)
|
||||
return -1;
|
||||
if (applyopts_single(sock->dual.stream[1],
|
||||
sock->dual.stream[1]->opts, PH_INIT)
|
||||
< 0)
|
||||
return -1;
|
||||
applyopts(-1, sock->dual.stream[0]->opts, PH_INIT);
|
||||
applyopts(-1, sock->dual.stream[1]->opts, PH_INIT);
|
||||
if ((result = applyopts(-1, optspr, PH_EARLY)) < 0)
|
||||
return result;
|
||||
if ((result = applyopts(-1, optspr, PH_PREOPEN)) < 0)
|
||||
return result;
|
||||
|
||||
/* here we copy opts, because most have to be applied twice! */
|
||||
if ((opts1 = copyopts(sock->stream.opts, GROUP_FD|GROUP_APPL|(groups1&~GROUP_PROCESS))) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* apply options to first FD */
|
||||
if ((result = applyopts(sock->dual.stream[0]->fd, opts1, PH_ALL)) < 0) {
|
||||
if ((result =
|
||||
applyopts(sock->dual.stream[0]->fd,
|
||||
sock->dual.stream[0]->opts, PH_ALL))
|
||||
< 0) {
|
||||
return result;
|
||||
}
|
||||
if ((result = _xio_openlate(sock->dual.stream[0], opts1)) < 0) {
|
||||
if ((result = _xio_openlate(sock->dual.stream[0],
|
||||
sock->dual.stream[0]->opts)) < 0) {
|
||||
return result;
|
||||
}
|
||||
#if 0
|
||||
/* ignore this opt */
|
||||
retropt_bool(sock->dual.stream[0]->opts, OPT_COOL_WRITE);
|
||||
#endif
|
||||
|
||||
if ((opts2 = copyopts(sock->stream.opts, GROUP_FD|GROUP_APPL|(groups2&~GROUP_PROCESS))) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
/* apply options to second FD */
|
||||
if ((result = applyopts(sock->dual.stream[1]->fd, opts2, PH_ALL)) < 0) {
|
||||
if ((result = applyopts(sock->dual.stream[1]->fd,
|
||||
sock->dual.stream[1]->opts, PH_ALL)) < 0) {
|
||||
return result;
|
||||
}
|
||||
if ((result = _xio_openlate(sock->dual.stream[1], opts2)) < 0) {
|
||||
if ((result = _xio_openlate(sock->dual.stream[1],
|
||||
sock->dual.stream[1]->opts)) < 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if ((result = _xio_openlate(sock->dual.stream[1], optspr)) < 0) {
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
Notice("reading from and writing to stdio");
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user