From 9788e3d94e7241f57b76257d410662d813dee9df Mon Sep 17 00:00:00 2001 From: grr Date: Tue, 5 Aug 1997 21:49:57 +0000 Subject: Fixes for a variety of pdksh problems: 1) pkksh in sh mode closed fd's other than [012] on exec'ing a command. this is a ksh'ism and POSIX sates that open files are part of the environment to be passed to the new process. 2) pdksh in sh mode interpets (( as meaning the start of arithmetic "quoting", which is incompatible with it's usage as a nested sub-shell invocation. The $(( form for arithmetic substitution is stil valid, however. PR user/59 millert@openbsd.org (Todd C. Miller) 3) pdksh sh.1 manpage isn't explicit about the range of input text that is subject to field splitting after a substitution. PR user/236 Mathieu.Herrb@mipnet.fr (Mathiew Herrb) --- bin/ksh/c_sh.c | 4 ++-- bin/ksh/lex.c | 12 +++++++----- bin/ksh/sh.1 | 26 ++++++++++++++++++++------ bin/ksh/sh.1tbl | 26 ++++++++++++++++++++------ bin/pdksh/c_sh.c | 4 ++-- bin/pdksh/lex.c | 12 +++++++----- bin/pdksh/sh.1tbl | 26 ++++++++++++++++++++------ 7 files changed, 78 insertions(+), 32 deletions(-) (limited to 'bin') diff --git a/bin/ksh/c_sh.c b/bin/ksh/c_sh.c index bd99341f86e..0691aa51af5 100644 --- a/bin/ksh/c_sh.c +++ b/bin/ksh/c_sh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_sh.c,v 1.5 1997/06/19 13:58:38 kstailey Exp $ */ +/* $OpenBSD: c_sh.c,v 1.6 1997/08/05 21:49:54 grr Exp $ */ /* * built-in Bourne commands @@ -728,7 +728,7 @@ c_exec(wp) if (e->savefd[i] > 0) close(e->savefd[i]); /* keep anything > 2 private */ - if (i > 2 && e->savefd[i]) + if (!Flag(FSH) && i > 2 && e->savefd[i]) fd_clexec(i); } e->savefd = NULL; diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c index 85f1582fadd..40469fdd3e3 100644 --- a/bin/ksh/lex.c +++ b/bin/ksh/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.7 1997/06/19 13:58:44 kstailey Exp $ */ +/* $OpenBSD: lex.c,v 1.8 1997/08/05 21:49:55 grr Exp $ */ /* * lexical analysis and source input @@ -587,10 +587,12 @@ Done: case '(': /*)*/ #ifdef KSH - if ((c2 = getsc()) == '(') /*)*/ - c = MDPAREN; - else - ungetsc(c2); + if (!Flag(FSH)) { + if ((c2 = getsc()) == '(') /*)*/ + c = MDPAREN; + else + ungetsc(c2); + } #endif /* KSH */ return c; /*(*/ diff --git a/bin/ksh/sh.1 b/bin/ksh/sh.1 index 03b86793338..cc6ef3b7eac 100644 --- a/bin/ksh/sh.1 +++ b/bin/ksh/sh.1 @@ -1,5 +1,5 @@ '\" t -.\" $OpenBSD: sh.1,v 1.2 1997/01/02 17:41:47 downsj Exp $ +.\" $OpenBSD: sh.1,v 1.3 1997/08/05 21:49:56 grr Exp $ .\"{{{}}} .\"{{{ Notes about man page .\" - use the pseudo-macros .sh( and .sh) to begin and end sh-specific @@ -421,12 +421,21 @@ zero or one non-IFS white space characters delimit a field. As a special case, leading and trailing IFS white space is stripped (\fIi.e.\fP, no leading or trailing empty field is created by it); leading or trailing non-IFS white space does create an empty field. -Example: if \fBIFS\fP is set to `:', the sequence of characters -`A:B::D' contains four fields: `A', `B', `' and `D'. +.PP +Example: if \fBIFS\fP is set to `:', and VAR is set to +`A:B::D', the substitution for $VAR results +in four fields: `A', `B', `' and `D'. Note that if the \fBIFS\fP parameter is set to the null string, no field splitting is done; if the parameter is unset, the default value of space, tab and newline is used. .PP +Also, note that the field splitting applies only to immediate result of +the substitution. Using the previous example, the substitution for $VAR:E +results in the fields: `A', `B', `' and `D:E', not `A', `B', `', `D' and `E'. +This behavior is POSIX compliant, but incompatible with some other shell +implementations which do field splitting on the word which contained the +substitution or use \fBIFS\fP\ as a general whitespace delimiter. +.PP The results of substitution are, unless otherwise specified, also subject to brace expansion and file name expansion (see the relevant sections below). @@ -1381,9 +1390,6 @@ The command is executed without forking, replacing the shell process. .sp If no arguments are given, any IO redirection is permanent and the shell is not replaced. -Any file descriptors greater than 2 which are opened or \fIdup\fP(2)-ed -in this way are not made available to other executed commands (\fIi.e.\fP, -commands that are not built-in to the shell). .\"}}} .\"{{{ exit [status] .IP "\fBexit\fP [\fIstatus\fP]" @@ -2313,6 +2319,14 @@ jobs are sent a \fBHUP\fP signal and the shell exits. .br /etc/suid_profile .\"}}} +.\"{{{ Notes +.SH NOTES +Sh is implemented as a runtime option of pdksh, with only those ksh features +whose syntax or semantics are incompatible with a traditional Bourne +shell disabled. Since this leaves some ksh extensions exposed, caution +should be used where backwards compatibility with traditional Bourne or +POSIX compliant shells is an issue. +.\"}}} .\"{{{ Bugs .SH BUGS Any bugs in pdksh should be reported to pdksh@cs.mun.ca. Please diff --git a/bin/ksh/sh.1tbl b/bin/ksh/sh.1tbl index 8c5febc4e4a..7d0eeacbc9e 100644 --- a/bin/ksh/sh.1tbl +++ b/bin/ksh/sh.1tbl @@ -1,5 +1,5 @@ '\" t -.\" $OpenBSD: sh.1tbl,v 1.2 1997/01/02 17:41:47 downsj Exp $ +.\" $OpenBSD: sh.1tbl,v 1.3 1997/08/05 21:49:56 grr Exp $ .\"{{{}}} .\"{{{ Notes about man page .\" - use the pseudo-macros .sh( and .sh) to begin and end sh-specific @@ -421,12 +421,21 @@ zero or one non-IFS white space characters delimit a field. As a special case, leading and trailing IFS white space is stripped (\fIi.e.\fP, no leading or trailing empty field is created by it); leading or trailing non-IFS white space does create an empty field. -Example: if \fBIFS\fP is set to `:', the sequence of characters -`A:B::D' contains four fields: `A', `B', `' and `D'. +.PP +Example: if \fBIFS\fP is set to `:', and VAR is set to +`A:B::D', the substitution for $VAR results +in four fields: `A', `B', `' and `D'. Note that if the \fBIFS\fP parameter is set to the null string, no field splitting is done; if the parameter is unset, the default value of space, tab and newline is used. .PP +Also, note that the field splitting applies only to immediate result of +the substitution. Using the previous example, the substitution for $VAR:E +results in the fields: `A', `B', `' and `D:E', not `A', `B', `', `D' and `E'. +This behavior is POSIX compliant, but incompatible with some other shell +implementations which do field splitting on the word which contained the +substitution or use \fBIFS\fP\ as a general whitespace delimiter. +.PP The results of substitution are, unless otherwise specified, also subject to brace expansion and file name expansion (see the relevant sections below). @@ -1381,9 +1390,6 @@ The command is executed without forking, replacing the shell process. .sp If no arguments are given, any IO redirection is permanent and the shell is not replaced. -Any file descriptors greater than 2 which are opened or \fIdup\fP(2)-ed -in this way are not made available to other executed commands (\fIi.e.\fP, -commands that are not built-in to the shell). .\"}}} .\"{{{ exit [status] .IP "\fBexit\fP [\fIstatus\fP]" @@ -2313,6 +2319,14 @@ jobs are sent a \fBHUP\fP signal and the shell exits. .br /etc/suid_profile .\"}}} +.\"{{{ Notes +.SH NOTES +Sh is implemented as a runtime option of pdksh, with only those ksh features +whose syntax or semantics are incompatible with a traditional Bourne +shell disabled. Since this leaves some ksh extensions exposed, caution +should be used where backwards compatibility with traditional Bourne or +POSIX compliant shells is an issue. +.\"}}} .\"{{{ Bugs .SH BUGS Any bugs in pdksh should be reported to pdksh@cs.mun.ca. Please diff --git a/bin/pdksh/c_sh.c b/bin/pdksh/c_sh.c index bd99341f86e..0691aa51af5 100644 --- a/bin/pdksh/c_sh.c +++ b/bin/pdksh/c_sh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_sh.c,v 1.5 1997/06/19 13:58:38 kstailey Exp $ */ +/* $OpenBSD: c_sh.c,v 1.6 1997/08/05 21:49:54 grr Exp $ */ /* * built-in Bourne commands @@ -728,7 +728,7 @@ c_exec(wp) if (e->savefd[i] > 0) close(e->savefd[i]); /* keep anything > 2 private */ - if (i > 2 && e->savefd[i]) + if (!Flag(FSH) && i > 2 && e->savefd[i]) fd_clexec(i); } e->savefd = NULL; diff --git a/bin/pdksh/lex.c b/bin/pdksh/lex.c index 85f1582fadd..40469fdd3e3 100644 --- a/bin/pdksh/lex.c +++ b/bin/pdksh/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.7 1997/06/19 13:58:44 kstailey Exp $ */ +/* $OpenBSD: lex.c,v 1.8 1997/08/05 21:49:55 grr Exp $ */ /* * lexical analysis and source input @@ -587,10 +587,12 @@ Done: case '(': /*)*/ #ifdef KSH - if ((c2 = getsc()) == '(') /*)*/ - c = MDPAREN; - else - ungetsc(c2); + if (!Flag(FSH)) { + if ((c2 = getsc()) == '(') /*)*/ + c = MDPAREN; + else + ungetsc(c2); + } #endif /* KSH */ return c; /*(*/ diff --git a/bin/pdksh/sh.1tbl b/bin/pdksh/sh.1tbl index 8c5febc4e4a..7d0eeacbc9e 100644 --- a/bin/pdksh/sh.1tbl +++ b/bin/pdksh/sh.1tbl @@ -1,5 +1,5 @@ '\" t -.\" $OpenBSD: sh.1tbl,v 1.2 1997/01/02 17:41:47 downsj Exp $ +.\" $OpenBSD: sh.1tbl,v 1.3 1997/08/05 21:49:56 grr Exp $ .\"{{{}}} .\"{{{ Notes about man page .\" - use the pseudo-macros .sh( and .sh) to begin and end sh-specific @@ -421,12 +421,21 @@ zero or one non-IFS white space characters delimit a field. As a special case, leading and trailing IFS white space is stripped (\fIi.e.\fP, no leading or trailing empty field is created by it); leading or trailing non-IFS white space does create an empty field. -Example: if \fBIFS\fP is set to `:', the sequence of characters -`A:B::D' contains four fields: `A', `B', `' and `D'. +.PP +Example: if \fBIFS\fP is set to `:', and VAR is set to +`A:B::D', the substitution for $VAR results +in four fields: `A', `B', `' and `D'. Note that if the \fBIFS\fP parameter is set to the null string, no field splitting is done; if the parameter is unset, the default value of space, tab and newline is used. .PP +Also, note that the field splitting applies only to immediate result of +the substitution. Using the previous example, the substitution for $VAR:E +results in the fields: `A', `B', `' and `D:E', not `A', `B', `', `D' and `E'. +This behavior is POSIX compliant, but incompatible with some other shell +implementations which do field splitting on the word which contained the +substitution or use \fBIFS\fP\ as a general whitespace delimiter. +.PP The results of substitution are, unless otherwise specified, also subject to brace expansion and file name expansion (see the relevant sections below). @@ -1381,9 +1390,6 @@ The command is executed without forking, replacing the shell process. .sp If no arguments are given, any IO redirection is permanent and the shell is not replaced. -Any file descriptors greater than 2 which are opened or \fIdup\fP(2)-ed -in this way are not made available to other executed commands (\fIi.e.\fP, -commands that are not built-in to the shell). .\"}}} .\"{{{ exit [status] .IP "\fBexit\fP [\fIstatus\fP]" @@ -2313,6 +2319,14 @@ jobs are sent a \fBHUP\fP signal and the shell exits. .br /etc/suid_profile .\"}}} +.\"{{{ Notes +.SH NOTES +Sh is implemented as a runtime option of pdksh, with only those ksh features +whose syntax or semantics are incompatible with a traditional Bourne +shell disabled. Since this leaves some ksh extensions exposed, caution +should be used where backwards compatibility with traditional Bourne or +POSIX compliant shells is an issue. +.\"}}} .\"{{{ Bugs .SH BUGS Any bugs in pdksh should be reported to pdksh@cs.mun.ca. Please -- cgit v1.2.3