mirror of
https://repo.or.cz/socat.git
synced 2024-12-22 23:42:34 +00:00
corrected option handling with stdio
This commit is contained in:
parent
3b3b004ff8
commit
edd6dae2de
4 changed files with 87 additions and 20 deletions
2
CHANGES
2
CHANGES
|
@ -27,6 +27,8 @@ corrections:
|
||||||
UDP-RECVFROM, IP-RECVFROM, UNIX-RECVFROM, ABSTRACT-RECVFROM
|
UDP-RECVFROM, IP-RECVFROM, UNIX-RECVFROM, ABSTRACT-RECVFROM
|
||||||
(thanks to Evan Borgstrom for reporting this problem)
|
(thanks to Evan Borgstrom for reporting this problem)
|
||||||
|
|
||||||
|
corrected option handling with STDIO; usecase: cool-write
|
||||||
|
|
||||||
corrected some print statements and variable names
|
corrected some print statements and variable names
|
||||||
|
|
||||||
make uninstall did not uninstall procan
|
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
|
NAME=COOLWRITE
|
||||||
case "$TESTS" in
|
case "$TESTS" in
|
||||||
*%functions%*|*%timeout%*|*%ignoreeof%*|*%$NAME%*)
|
*%functions%*|*%timeout%*|*%ignoreeof%*|*%coolwrite%*|*%$NAME%*)
|
||||||
TEST="$NAME: option cool-write"
|
TEST="$NAME: option cool-write"
|
||||||
if ! testoptions cool-write >/dev/null; then
|
if ! testoptions cool-write >/dev/null; then
|
||||||
$PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
|
$PRINTF "test $F_n $TEST... ${YELLOW}option cool-write not available${NORMAL}\n" $N
|
||||||
|
@ -6932,6 +6932,53 @@ esac
|
||||||
N=$((N+1))
|
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
|
NAME=TCP4ENDCLOSE
|
||||||
case "$TESTS" in
|
case "$TESTS" in
|
||||||
*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
|
*%functions%*|*%ip4%*|*%ipapp%*|*%tcp%*|*%$NAME%*)
|
||||||
|
|
54
xio-stdio.c
54
xio-stdio.c
|
@ -1,5 +1,5 @@
|
||||||
/* source: xio-stdio.c */
|
/* 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 */
|
/* Published under the GNU General Public License V.2, see file COPYING */
|
||||||
|
|
||||||
/* this file contains the source for opening addresses stdio type */
|
/* 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.
|
/* process a bidirectional "stdio" or "-" argument with options.
|
||||||
generate a dual address. */
|
generate a dual address. */
|
||||||
int xioopen_stdio_bi(xiofile_t *sock) {
|
int xioopen_stdio_bi(xiofile_t *sock) {
|
||||||
struct opt *opts1, *opts2, *optspr;
|
struct opt *optspr;
|
||||||
unsigned int groups1 = addr_stdio.groups, groups2 = addr_stdio.groups;
|
unsigned int groups1 = addr_stdio.groups;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (xioopen_makedual(sock) < 0) {
|
if (xioopen_makedual(sock) < 0) {
|
||||||
|
@ -67,9 +67,6 @@ int xioopen_stdio_bi(xiofile_t *sock) {
|
||||||
}
|
}
|
||||||
#endif /* WITH_TERMIOS */
|
#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 */
|
/* options here are one-time and one-direction, no second use */
|
||||||
retropt_bool(sock->stream.opts, OPT_IGNOREEOF, &sock->dual.stream[0]->ignoreeof);
|
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) {
|
if ((optspr = copyopts(sock->stream.opts, GROUP_PROCESS)) == NULL) {
|
||||||
return -1;
|
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)
|
if ((result = applyopts(-1, optspr, PH_EARLY)) < 0)
|
||||||
return result;
|
return result;
|
||||||
if ((result = applyopts(-1, optspr, PH_PREOPEN)) < 0)
|
if ((result = applyopts(-1, optspr, PH_PREOPEN)) < 0)
|
||||||
return result;
|
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 */
|
/* 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;
|
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;
|
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 */
|
/* 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;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
if ((result = _xio_openlate(sock->dual.stream[1], optspr)) < 0) {
|
if ((result = _xio_openlate(sock->dual.stream[1], optspr)) < 0) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Notice("reading from and writing to stdio");
|
Notice("reading from and writing to stdio");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue