diff --git a/check.t b/check.t index e8c3bf6..e920866 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.221 2008/09/14 20:24:57 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.222 2008/09/17 19:31:28 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -7,7 +7,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R35 2008/09/14 + @(#)MIRBSD KSH R35 2008/09/17 description: Check version of shell. stdin: @@ -4251,6 +4251,25 @@ expected-stdout: posix brex --- +name: posix-mode-2 +description: + Check that posix mode is automatically turned on +category: !smksh +stdin: + ln -s "$__progname" ksh + ln -s "$__progname" sh + ln -s "$__progname" -ksh + ln -s "$__progname" -sh + for shell in {,-}{,k}sh; do + print -- $shell $(./$shell +l -c \ + '[[ $(set +o) == *@(-o posix)@(| *) ]] && echo posix || echo noposix') + done +expected-stdout: + sh posix + ksh noposix + -sh posix + -ksh noposix +--- name: pipeline-1 description: pdksh bug: last command of a pipeline is executed in a @@ -5307,3 +5326,28 @@ stdin: exit 1 fi --- +name: fd-cloexec-1 +description: + Verify that file descriptors > 2 are private for Korn shells +file-setup: file 644 "test.sh" + print -u3 Fowl +stdin: + exec 3>&1 + "$__progname" test.sh +expected-exit: e != 0 +expected-stderr: + test.sh[1]: print: -u: 3: bad file descriptor +--- +name: fd-cloexec-2 +description: + Verify that file descriptors > 2 are not private for POSIX shells + See Debian Bug #154540, Closes: #499139 +file-setup: file 644 "test.sh" + print -u3 Fowl +stdin: + set -o posix + exec 3>&1 + "$__progname" test.sh +expected-stdout: + Fowl +--- diff --git a/funcs.c b/funcs.c index 71650ec..cb64211 100644 --- a/funcs.c +++ b/funcs.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.86 2008/08/02 17:45:11 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.87 2008/09/17 19:31:29 tg Exp $"); /* A leading = means assignments before command are kept; * a leading * means a POSIX special builtin; @@ -2308,8 +2308,8 @@ c_exec(const char **wp __unused) for (i = 0; i < NUFILE; i++) { if (e->savefd[i] > 0) close(e->savefd[i]); - /* For ksh keep anything > 2 private */ - if (i > 2 && e->savefd[i]) + /* For ksh (but not sh), keep anything > 2 private */ + if (!Flag(FPOSIX) && i > 2 && e->savefd[i]) fcntl(i, F_SETFD, FD_CLOEXEC); } e->savefd = NULL; diff --git a/main.c b/main.c index 37e76ee..d2d82f0 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.101 2008/07/10 18:34:08 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.102 2008/09/17 19:31:29 tg Exp $"); extern char **environ; @@ -173,6 +173,21 @@ main(int argc, const char *argv[]) Flag(FVITABCOMPLETE) = 1; #endif +#ifndef MKSH_SMALL + /* Set FPOSIX if we're called as -sh or /bin/sh or so */ + { + const char *cc; + + cc = kshname; + i = 0; argi = 0; + while (cc[i] != '\0') + if ((cc[i++] | 2) == '/') + argi = i; + if (((cc[argi] | 0x20) == 's') && ((cc[argi + 1] | 0x20) == 'h')) + change_flag(FPOSIX, OF_FIRSTTIME, 1); + } +#endif + /* import environment */ if (environ != NULL) for (wp = (const char **)environ; *wp != NULL; wp++) diff --git a/mksh.1 b/mksh.1 index 60f6e3b..7a996d1 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.135 2008/09/17 19:27:16 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.136 2008/09/17 19:31:30 tg Exp $ .\" $OpenBSD: ksh.1,v 1.122 2008/05/17 23:31:52 sobrado Exp $ .\"- .\" Try to make GNU groff and AT&T nroff more compatible @@ -2080,6 +2080,11 @@ pipelines are created and in the order they are given, so the following will print an error with a line number prepended to it: .Pp .D1 $ cat /foo/bar 2\*(Gt&1 \*(Gt /dev/null \*(Ba cat \-n +.Pp +File descriptors created by input/output redirections are private to the +Korn shell, but passed to sub-processes if +.Fl o Ic posix +is set. .Ss Arithmetic expressions Integer arithmetic expressions can be used with the .Ic let @@ -3580,9 +3585,11 @@ and commands above for more details. .It Ic posix Enable POSIX mode. -Currently, this just turns off +Automatically enabled if the basename of the shell invocation begins with +.Dq sh . +As a side effect, setting this flag turns off .Ic braceexpand -mode when turned on, which can be turned back on manually. +mode, which can be turned back on manually. .It Ic restricted The shell is a restricted shell. This option can only be used when the shell is invoked. @@ -5525,7 +5532,7 @@ and many other persons, and is currently maintained by .An Thorsten Glaser Aq tg@mirbsd.de . .Sh BUGS This document attempts to describe -.Nm mksh\ R35 +.Nm mksh\ R35c and up, compiled without any options impacting functionality, such as .Dv MKSH_SMALL , diff --git a/sh.h b/sh.h index 8788a3c..496a8b5 100644 --- a/sh.h +++ b/sh.h @@ -100,9 +100,9 @@ #define __SCCSID(x) __IDSTRING(sccsid,x) #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.231 2008/09/14 20:24:59 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.232 2008/09/17 19:31:30 tg Exp $"); #endif -#define MKSH_VERSION "R35 2008/09/14" +#define MKSH_VERSION "R35 2008/09/17" #ifndef MKSH_INCLUDES_ONLY