diff --git a/check.t b/check.t index bf0a05bcb..96044891f 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.809 2018/10/20 18:48:26 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.810 2018/12/04 21:13:44 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -30,7 +30,7 @@ # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date expected-stdout: - @(#)MIRBSD KSH R56 2018/10/20 + @(#)MIRBSD KSH R56 2018/12/04 description: Check base version of full shell stdin: @@ -39,7 +39,7 @@ name: KSH_VERSION category: !shell:legacy-yes --- expected-stdout: - @(#)LEGACY KSH R56 2018/10/20 + @(#)LEGACY KSH R56 2018/12/04 description: Check base version of legacy shell stdin: @@ -11264,6 +11264,34 @@ stdin: expected-stdout: Fowl --- +name: fd-cloexec-3 +description: + Another check for close-on-exec +stdin: + print '#!'"$__progname" >ts + cat >>ts <<'EOF' + s=ERR + read -rN-1 -u$1 s 2>/dev/null; e=$? + print -r -- "($1, $((!e)), $s)" + EOF + chmod +x ts + print foo >tx + runtest() { + s=$1; shift + print -r -- $("$__progname" "$@" -c "$s") "$@" . + } + runtest 'exec 3 * * Provided that these terms and disclaimer and all copyright notices @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.203 2018/10/30 17:10:14 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.204 2018/12/04 21:13:47 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" @@ -429,6 +429,12 @@ execute(struct op * volatile t, up = makenv(); restoresigs(); cleanup_proc_env(); + /* I/O redirection cleanup to be done in child process */ + if (!Flag(FPOSIX) && !Flag(FSH) && t->left->ioact != NULL) + for (iowp = t->left->ioact; *iowp != NULL; iowp++) + if ((*iowp)->ioflag & IODUPSELF) + fcntl((*iowp)->unit, F_SETFD, 0); + /* try to execute */ { union mksh_ccphack cargs; @@ -1485,9 +1491,11 @@ iosetup(struct ioword *iop, struct tbl *tp) afree(sp, ATEMP); return (-1); } - if (u == (int)iop->unit) + if (u == (int)iop->unit) { /* "dup from" == "dup to" */ + iop->ioflag |= IODUPSELF; return (0); + } break; } } diff --git a/sh.h b/sh.h index 3ca8e5507..e61b800e6 100644 --- a/sh.h +++ b/sh.h @@ -182,9 +182,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.867 2018/10/30 17:10:16 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.868 2018/12/04 21:13:47 tg Exp $"); #endif -#define MKSH_VERSION "R56 2018/10/20" +#define MKSH_VERSION "R56 2018/12/04" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -1954,10 +1954,11 @@ struct ioword { #define IOSKIP BIT(5) /* <<-, skip ^\t* */ #define IOCLOB BIT(6) /* >|, override -o noclobber */ #define IORDUP BIT(7) /* x<&y (as opposed to x>&y) */ -#define IONAMEXP BIT(8) /* name has been expanded */ -#define IOBASH BIT(9) /* &> etc. */ -#define IOHERESTR BIT(10) /* <<< (here string) */ -#define IONDELIM BIT(11) /* null delimiter (<<) */ +#define IODUPSELF BIT(8) /* x>&x (as opposed to x>&y) */ +#define IONAMEXP BIT(9) /* name has been expanded */ +#define IOBASH BIT(10) /* &> etc. */ +#define IOHERESTR BIT(11) /* <<< (here string) */ +#define IONDELIM BIT(12) /* null delimiter (<<) */ /* execute/exchild flags */ #define XEXEC BIT(0) /* execute without forking */