half close of EXEC and SYSTEM addresses did not work with pipes and sometimes socketpair

This commit is contained in:
Gerhard Rieger 2009-03-31 22:46:41 +02:00
parent 5999bbc1b8
commit 13fce17ad8
4 changed files with 35 additions and 29 deletions

View file

@ -1,5 +1,8 @@
corrections: corrections:
half close of EXEC and SYSTEM addresses did not work for pipes and
sometimes socketpair
help displayed some option types wrong help displayed some option types wrong
under some circumstances shutdown was called multiple times for the under some circumstances shutdown was called multiple times for the

View file

@ -1 +1 @@
"1.7.0.0" "1.7.0.0+execshut"

45
test.sh
View file

@ -2272,14 +2272,13 @@ esac
N=$((N+1)) N=$((N+1))
## LATER: NAME=SYSTEMPIPESFLUSH
#NAME=SYSTEMPIPESFLUSH case "$TESTS" in
#case "$TESTS" in *%functions%*|*%system%*|*%$NAME%*)
#*%functions%*|*%system%*|*%$NAME%*) TEST="$NAME: call to od via system() with pipes"
#TEST="$NAME: call to od via system() with pipes" testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" "$val_t"
#testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" esac
#esac N=$((N+1))
#N=$((N+1))
## LATER: ## LATER:
@ -2312,24 +2311,22 @@ N=$((N+1))
#N=$((N+1)) #N=$((N+1))
## LATER: NAME=SYSTEMPIPESFDSFLUSH
#NAME=SYSTEMPIPESFDSFLUSH case "$TESTS" in
#case "$TESTS" in *%functions%*|*%system%*|*%$NAME%*)
#*%functions%*|*%system%*|*%$NAME%*) TEST="$NAME: call to od via system() with pipes, non stdio"
#TEST="$NAME: call to od via system() with pipes, non stdio" testod "$N" "$TEST" "" "system:$OD_C>&9 <&8,pipes,fdin=8,fdout=9" "$opts" "$val_t"
#testod "$N" "$TEST" "" "system:$OD_C>&9 <&8,pipes,fdin=8,fdout=9" "$opts" esac
#esac N=$((N+1))
#N=$((N+1))
## LATER: NAME=DUALSYSTEMFDSFLUSH
#NAME=DUALSYSTEMFDSFLUSH case "$TESTS" in
#case "$TESTS" in *%functions%*|*%system%*|*%$NAME%*)
#*%functions%*|*%system%*|*%$NAME%*) TEST="$NAME: call to od via dual system()"
#TEST="$NAME: call to od via dual system()" testod "$N" "$TEST" "system:$OD_C>&6,fdout=6!!system:$CAT<&7,fdin=7" "pipe" "$opts" "$val_t"
#testecho "$N" "$TEST" "system:$OD_C>&6,fdout=6!!system:$CAT<&7,fdin=7" "" "$opts" esac
#esac N=$((N+1))
#N=$((N+1))
case "$UNAME" in case "$UNAME" in

View file

@ -1,5 +1,5 @@
/* source: xio-progcall.c */ /* source: xio-progcall.c */
/* Copyright Gerhard Rieger 2001-2008 */ /* Copyright Gerhard Rieger 2001-2009 */
/* 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 common code dealing with program calls (exec, system) */ /* this file contains common code dealing with program calls (exec, system) */
@ -420,6 +420,7 @@ int _xioopen_foxec(int xioflags, /* XIO_RDONLY etc. */
#if HAVE_PTY #if HAVE_PTY
if (usepty) { if (usepty) {
Close(ptyfd);
if (rw != XIO_RDONLY && fdi != ttyfd) { if (rw != XIO_RDONLY && fdi != ttyfd) {
if (Dup2(ttyfd, fdi) < 0) { if (Dup2(ttyfd, fdi) < 0) {
Error3("dup2(%d, %d): %s", ttyfd, fdi, strerror(errno)); Error3("dup2(%d, %d): %s", ttyfd, fdi, strerror(errno));
@ -448,6 +449,8 @@ int _xioopen_foxec(int xioflags, /* XIO_RDONLY etc. */
a graceful solution via temporary descriptors */ a graceful solution via temporary descriptors */
int tmpi, tmpo; int tmpi, tmpo;
if (rw != XIO_WRONLY) Close(rdpip[0]);
if (rw != XIO_RDONLY) Close(wrpip[1]);
if (fdi == rdpip[1]) { /* a conflict here */ if (fdi == rdpip[1]) { /* a conflict here */
if ((tmpi = Dup(wrpip[0])) < 0) { if ((tmpi = Dup(wrpip[0])) < 0) {
Error2("dup(%d): %s", wrpip[0], strerror(errno)); Error2("dup(%d): %s", wrpip[0], strerror(errno));
@ -491,6 +494,7 @@ int _xioopen_foxec(int xioflags, /* XIO_RDONLY etc. */
applyopts(fdo, *copts, PH_LATE2); applyopts(fdo, *copts, PH_LATE2);
} else { /* socketpair */ } else { /* socketpair */
Close(sv[0]);
if (rw != XIO_RDONLY && fdi != sv[1]) { if (rw != XIO_RDONLY && fdi != sv[1]) {
if (Dup2(sv[1], fdi) < 0) { if (Dup2(sv[1], fdi) < 0) {
Error3("dup2(%d, %d): %s", sv[1], fdi, strerror(errno)); Error3("dup2(%d, %d): %s", sv[1], fdi, strerror(errno));
@ -505,6 +509,7 @@ int _xioopen_foxec(int xioflags, /* XIO_RDONLY etc. */
} }
if (fdi != sv[1] && fdo != sv[1]) { if (fdi != sv[1] && fdo != sv[1]) {
applyopts_cloexec(sv[1], *copts); applyopts_cloexec(sv[1], *copts);
Close(sv[1]);
} }
applyopts(fdi, *copts, PH_LATE); applyopts(fdi, *copts, PH_LATE);
@ -546,13 +551,14 @@ int _xioopen_foxec(int xioflags, /* XIO_RDONLY etc. */
if (Close(ttyfd) < 0) { if (Close(ttyfd) < 0) {
Info2("close(%d): %s", ttyfd, strerror(errno)); Info2("close(%d): %s", ttyfd, strerror(errno));
} }
} /*0 else*/ } else
#endif /* HAVE_PTY */ #endif /* HAVE_PTY */
#if 0
if (usepipes) { if (usepipes) {
Close(rdpip[1]);
Close(wrpip[0]);
} else { } else {
Close(sv[1]);
} }
#endif
fd->para.exec.pid = pid; fd->para.exec.pid = pid;
if (applyopts_single(fd, popts, PH_LATE) < 0) return -1; if (applyopts_single(fd, popts, PH_LATE) < 0) return -1;