From 13fce17ad80c5d2cac7f7f1501f48a8c091d64f2 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Tue, 31 Mar 2009 22:46:41 +0200 Subject: [PATCH] half close of EXEC and SYSTEM addresses did not work with pipes and sometimes socketpair --- CHANGES | 3 +++ VERSION | 2 +- test.sh | 45 +++++++++++++++++++++------------------------ xio-progcall.c | 14 ++++++++++---- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/CHANGES b/CHANGES index 0d341a1..6c12c70 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ corrections: + half close of EXEC and SYSTEM addresses did not work for pipes and + sometimes socketpair + help displayed some option types wrong under some circumstances shutdown was called multiple times for the diff --git a/VERSION b/VERSION index bd51149..e286481 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -"1.7.0.0" +"1.7.0.0+execshut" diff --git a/test.sh b/test.sh index 66ed015..062ad6f 100755 --- a/test.sh +++ b/test.sh @@ -2272,14 +2272,13 @@ esac N=$((N+1)) -## LATER: -#NAME=SYSTEMPIPESFLUSH -#case "$TESTS" in -#*%functions%*|*%system%*|*%$NAME%*) -#TEST="$NAME: call to od via system() with pipes" -#testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" -#esac -#N=$((N+1)) +NAME=SYSTEMPIPESFLUSH +case "$TESTS" in +*%functions%*|*%system%*|*%$NAME%*) +TEST="$NAME: call to od via system() with pipes" +testod "$N" "$TEST" "" "system:$OD_C,pipes" "$opts" "$val_t" +esac +N=$((N+1)) ## LATER: @@ -2312,24 +2311,22 @@ N=$((N+1)) #N=$((N+1)) -## LATER: -#NAME=SYSTEMPIPESFDSFLUSH -#case "$TESTS" in -#*%functions%*|*%system%*|*%$NAME%*) -#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" -#esac -#N=$((N+1)) +NAME=SYSTEMPIPESFDSFLUSH +case "$TESTS" in +*%functions%*|*%system%*|*%$NAME%*) +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" +esac +N=$((N+1)) -## LATER: -#NAME=DUALSYSTEMFDSFLUSH -#case "$TESTS" in -#*%functions%*|*%system%*|*%$NAME%*) -#TEST="$NAME: call to od via dual system()" -#testecho "$N" "$TEST" "system:$OD_C>&6,fdout=6!!system:$CAT<&7,fdin=7" "" "$opts" -#esac -#N=$((N+1)) +NAME=DUALSYSTEMFDSFLUSH +case "$TESTS" in +*%functions%*|*%system%*|*%$NAME%*) +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" +esac +N=$((N+1)) case "$UNAME" in diff --git a/xio-progcall.c b/xio-progcall.c index fd5d3ad..8217298 100644 --- a/xio-progcall.c +++ b/xio-progcall.c @@ -1,5 +1,5 @@ /* 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 */ /* 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 (usepty) { + Close(ptyfd); if (rw != XIO_RDONLY && fdi != ttyfd) { if (Dup2(ttyfd, fdi) < 0) { 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 */ 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 ((tmpi = Dup(wrpip[0])) < 0) { 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); } else { /* socketpair */ + Close(sv[0]); if (rw != XIO_RDONLY && fdi != sv[1]) { if (Dup2(sv[1], fdi) < 0) { 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]) { applyopts_cloexec(sv[1], *copts); + Close(sv[1]); } applyopts(fdi, *copts, PH_LATE); @@ -546,13 +551,14 @@ int _xioopen_foxec(int xioflags, /* XIO_RDONLY etc. */ if (Close(ttyfd) < 0) { Info2("close(%d): %s", ttyfd, strerror(errno)); } - } /*0 else*/ + } else #endif /* HAVE_PTY */ -#if 0 if (usepipes) { + Close(rdpip[1]); + Close(wrpip[0]); } else { + Close(sv[1]); } -#endif fd->para.exec.pid = pid; if (applyopts_single(fd, popts, PH_LATE) < 0) return -1;