History log of /openbsd-current/bin/ksh/exec.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.77 21-Jun-2023 millert

ksh: escape control chars when displaying file name completions.
If there are multiple matches when using autocomplete, the list of
matching file names was output as-is. However, for a single match,
control characters are escaped before the file name is displayed.
This makes the behavior more consistent by escaping control chars
in the list of matches too. Discussed with deraadt@, OK op@


Revision tags: OPENBSD_7_3_BASE
# 1.76 10-Oct-2022 kn

Trigger ERR trap on permanent I/O redirection failure

The following three cases behave identical in bash(1), but our ksh
(ksh93 also) fails to run the trap in the last case:

(non-zero exit code is trigger, no redirection)
$ ksh -c 'trap "echo ERR" ERR ; false'
ERR

(failed redirection is trigger, 'echo' was not executed)
$ ksh -c 'trap "echo ERR" ERR ; echo >/'
ksh: cannot create /: Is a directory
ERR

(failed redirection, no execution, trap was NOT triggered)
$ ksh -c 'trap "echo ERR" ERR ; exec >/'
ksh: cannot create /: Is a directory


bash(1) prints "ERR" in all three cases, as expected.
ksh93 behaves like our ksh(1).

In ksh `exec' is a builtin (CSHELL), but also special (SPEC_BI):
$ type alias
alias is a shell builtin
$ type exec
exec is a special shell builtin

Without command and redirection alone, `exec' permanently redirects I/O for
the shell itself, not executing anything; it is the only (special) builtin
with such a special use-case, implemented as c_sh.c:c_exec().

This corner-case is overlooked in exec.c:execute() which handles iosetup()
failure for all commands, incl. builtins.

Exclude c_exec() from the rest of special builtins to ensure it runs the
ERR trap as expected:

$ ./obj/ksh -c 'trap "echo ERR" ERR ; exec >/'
ksh: cannot create /: Is a directory
ERR

Also add three new regress cases covering this; rest keep passing.

OK millert


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.75 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.74 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 15-Mar-2018 anton

Favor usage of __func__ in warning/error messages. Some of them referred to the
wrong function and fix the rest for consistency.
Diff from Michael W. Bombardieri with some cosmetic cleanup applied.

ok benno@ tb@


# 1.72 16-Jan-2018 jca

Introduce internal_warningf() and mark internal_errorf() as noreturn

This helps tools like scan-build, and follows the example of warningf()
and errorf(). ok anton@


# 1.71 15-Jan-2018 jca

Stop pretending we support building ksh without EDIT/HISTORY support

ok anton@


# 1.70 27-Dec-2017 millert

Add -Wshadow to Makefile and fix the resulting warnings. Many of
the warnings are due to the use of globals with generic names,
specifically "options" and "path". I've renamed "options" to
"sh_options" since it holds the shell options and "path" to
"search_path". OK jca@ tb@


# 1.69 18-Dec-2017 anton

Get rid of a todo by stop declaring variable texec as static and instead zeroing
it out prior to continuing down the recursive call chain.

Initial diff from Michael W. Bombardieri, later tweaked; ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.68 11-Dec-2016 millert

I missed a bit of the indentation fix from Kartik Agaram.


# 1.67 11-Dec-2016 millert

When ERREXIT (set -e) is in effect, don't disable it after a
short-circuited `&&` or `||` chain in later iterations of `for`
loops. It should be disabled after a short-circuited `&&` or `||`
chain only in the *final* iteration of loops (as well as in
conditionals, which was already working). From Kartik Agaram.


# 1.66 11-Dec-2016 millert

In execute() we assign xerrorok to a dummy value if it is NULL
so there is no need to check xerrorok for NULL after that.
From Kartik Agaram.


# 1.65 11-Dec-2016 millert

Fix for() loop indentation for TCASE in execute() and add some
braces for improved readability. Based on a diff from Kartik Agaram.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.64 30-Dec-2015 tedu

rename global "e" to genv to avoid accidental shadowing and aliasing.
ok millert nicm tb


# 1.63 14-Dec-2015 tb

Move system headers from sh.h to those files that actually need them.

ok mmcc@ a while ago


# 1.62 01-Nov-2015 mmcc

Add uses of areallocarray(). mksh and Bitrig ksh already have similar
functions. With help from Theo Buehler.

ok nicm@


# 1.61 19-Oct-2015 mmcc

Move string.h include from sh.h to the files that use it.

ok nicm@


# 1.60 19-Oct-2015 mmcc

Apply style(9) to header includes.

ok nicm@


# 1.59 17-Oct-2015 mmcc

Drop two useless defines.

ok nicm@


# 1.58 17-Oct-2015 mmcc

Move a system header include from the global header (sh.h) into the
files that need it. No binary change.

"This looks fine" -nicm@


# 1.57 22-Sep-2015 millert

Make errorf() and bi_errorf() handle a NULL argument.
From Michael McConville; OK nicm@


# 1.56 18-Sep-2015 nicm

Last of the (thing *)0 -> NULL, from Michael McConville. No binary
change.


# 1.55 17-Sep-2015 nicm

Remove unnecessary casts, from Michael McConville. No binary change.


# 1.54 15-Sep-2015 tedu

correct spelling of NULL from (char *)0. from Michael McConville.
ok md5


# 1.53 14-Sep-2015 nicm

Replace Tflag typedef with just int; ok tedu


# 1.52 10-Sep-2015 nicm

Replace newline and space defines by "\n" and " " directly, from Michael
McConville. ok millert


Revision tags: OPENBSD_5_8_BASE
# 1.51 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.50 10-Jun-2013 millert

POSIX specifies that for an AND/OR list, only the last command's
exit status matters for "set -e". Revert the part of revision 1.49
that always sets xerrok for AND/OR. This makes sh/ksh pass the
updated regress tests. OK espie@ jca@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.49 29-Jan-2009 jaredy

pass "xerrok" status across the execution call stack to more closely
match what both POSIX and ksh.1 already describe in regards to set
-e/errexit's behavior in determining when to exit from nonzero return
values.

specifically, the truth values tested as operands to `&&' and `||', as
well as the resulting compound expression itself, along with the truth
value resulting from a negated command (i.e. a pipeline prefixed `!'),
should not make the shell exit when -e is in effect.

issue reported by matthieu.
testing matthieu, naddy.
ok miod (earlier version), otto.
man page ok jmc.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.48 05-Sep-2007 otto

Call ERR trap _before_ doing exit handling. Otherwise it's too late
and the ERR trap won't get called at all. ok millert@


Revision tags: OPENBSD_4_2_BASE
# 1.47 02-Aug-2007 fgsch

another memory leak fix found by coverity. from netbsd but modified.
millert@ ok.


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.46 10-Apr-2006 jaredy

fix lint comments, no functional changes; ok ray


# 1.45 17-Mar-2006 millert

Simplify savefd() by removing the "noclose" flag and make noclose
behavior the default. Almost all uses of savefd() are followed
by an implicit or explicit close. OK otto@


Revision tags: OPENBSD_3_9_BASE
# 1.44 11-Dec-2005 otto

fix a few name clashes with libc; found by lint. ok deraadt@


# 1.43 11-Dec-2005 deraadt

remove unused variables and functions


# 1.42 11-Sep-2005 otto

Fix " handling in here documents. POSIX says they are not special, so
cat << EOF
\"
EOF
should print \"
Fixes PR 4472; testing jmc@ and Adam Montague. ok millert@


Revision tags: OPENBSD_3_8_BASE
# 1.41 30-Mar-2005 deraadt

lots of indentation cleanup, now ksh is readable like our other code.
double checked to make sure no binaries change, and eyed by niallo


# 1.40 28-Mar-2005 deraadt

spacing


Revision tags: OPENBSD_3_7_BASE
# 1.39 22-Dec-2004 otto

Fix a use-after-free, that causs core dumps if a shell is killed
running with strict malloc.conf options. Problem spotted by hshoexer@;
fix by me with some help from millert@.

ok millert@ hshoexer@ krw@ deraadt@


# 1.38 22-Dec-2004 millert

Use stdbool.h instead of rolling our own bools.


# 1.37 20-Dec-2004 otto

Ansification plus some minor knf. No binary change on i386 and
sparc64, binary change in lex.o on macppc due to introduction of
dopprompt() prototype. ok millert@


# 1.36 19-Dec-2004 deraadt

spacing


# 1.35 18-Dec-2004 millert

Replace fd_clexec() with calls to fcntl(fd, F_SETFD, FD_CLOEXEC)


# 1.34 18-Dec-2004 millert

deregister


# 1.33 18-Dec-2004 millert

Get rid of #ifdef KSH since we don't care about building a V7 style sh and
the #ifdef KSH code is required to make a POSIX sh. From Matthias Kilian


# 1.32 18-Dec-2004 millert

Remove unused OS dependent #ifdef blocks, #defines and macro abstraction.
First step in making the ksh code easier to read. From Matthias Kilian


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.31 15-Dec-2003 otto

Unbreak parameter assignment when calling bourne style functions;
resolves PR 2450.

ok deraadt@ millert@


# 1.30 10-Nov-2003 millert

If "from fd" == "to fd" don't call dup2() or close "from fd".


# 1.29 10-Nov-2003 millert

For the >& and <& operators, add a check for "dup from" == "dup to" and
just return success if they are the same. Fixes the "ls 2>&2" problem
miod@ found.


# 1.28 22-Oct-2003 jmc

typos from Jared Yanovich;
ok deraadt@


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE
# 1.27 28-Feb-2003 jmc

typos; from Brian Poole


Revision tags: OPENBSD_3_2_BASE
# 1.26 09-Jun-2002 todd

knf


Revision tags: OPENBSD_3_1_BASE
# 1.25 16-Jan-2002 millert

Use the volatile specifier to fix warnings about variables being
clobbered by longjmp / vfork instead of the gcc "(void)&foo;" hack.


Revision tags: OPENBSD_3_0_BASE
# 1.24 19-Jul-2001 millert

Back out last change, it caused problems with exit vals.


# 1.23 03-Jul-2001 millert

Merge in pdksh-5.2.14-patches.2 to fix some problems with propagated
return values in multi-command lines.


Revision tags: OPENBSD_2_9_BASE
# 1.22 19-Feb-2001 camield

bash-like 'double-tab' completion

- bind TAB (^I) to complete-list by default
- complete-list now lists 'ls style' not 'menu style'
- complete-list first completes; if that does not work, it lists
- fix a memleak in emacs.c, do_complete
- completion now works after '=' (dd), and ':' (ssh) and ` (backtick)
- a command can now start with a subdir from the current dir


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.21 15-Jul-1999 millert

silence -Wall


# 1.20 14-Jul-1999 millert

Official fix for workaround in 1.18


# 1.19 14-Jul-1999 millert

pdksh-5.2.14


# 1.18 23-Jun-1999 millert

When redirecting to a file with stdout closed, don't blithely reuse
fd 1 since that will cause future output on stdout to go to the file
that was redirected. There is probably a better fix for this.


# 1.17 15-Jun-1999 millert

patches from pdksh 5.2.13.11


Revision tags: OPENBSD_2_5_BASE
# 1.16 19-Jan-1999 millert

Updates from pdksh-unstable-5.2.13.7. Most notable change is:
trap: exit traps now executed in subshells (without explicit exit call).
See the Changelog for a full list of changes.


# 1.15 10-Jan-1999 millert

sync with pdksh-unstable-5.2.13.6


# 1.14 08-Jan-1999 millert

bug fixes from pdksh-unstable-5.2.13.5; some of which we already had.


# 1.13 29-Oct-1998 millert

Bug fixes from pdksh-unstable-5.2.13.4, including "official" versions of
some that we had already fixed locally.
o typeset -f FUNC doesn't print follows command (and expression) substitutions.
o when re-allocating memory, too much may be copied from old memory.
o set -o printed some options sans names.
o emacs mode: <esc>. in very fist command causes core dump.
o pdksh dumps core after a cd command.
o typeset -i reports on array elements that have no value
(at&t ksh reports on array base name - no index).
o ulimit -ctn unlimittttted kills shell (resource exceeded).
o ". /dev/null" says access denied.
o flag field in aliases incorrectly changed (all flags set instead of
clearing ISSET) in exec.c(flushcom).
o ${#array[*]} prints largest index instead of number of (set) elements
in an array (ksh88 does the former).
o sys_siglist[] doesn't always have NSIG non-null entries...


Revision tags: OPENBSD_2_4_BASE
# 1.12 27-Jun-1998 deraadt

new ksh code stupidly did not permit ". /dev/null"; enable that again


# 1.11 25-Jun-1998 millert

pdksh-5.2.13 + local changes


Revision tags: OPENBSD_2_3_BASE
# 1.10 12-Sep-1997 millert

Avoid longjmp/vfork clobbering.


# 1.9 19-Jun-1997 kstailey

back out


# 1.8 18-Jun-1997 kstailey

(foo *)0 -> NULL


# 1.7 02-Jan-1997 downsj

After discussing $_ with the maintainer, revert ksh behaviour and completely
eliminate it from sh.


# 1.6 02-Jan-1997 downsj

Add FSH (set -o sh), initialize it if we're /bin/sh, and add the first use:
don't set $_ if we're non-interactive.


# 1.5 21-Nov-1996 downsj

Update to 5.2.12.


# 1.4 01-Oct-1996 downsj

Integrate pdksh 5.2.9.


# 1.3 25-Aug-1996 downsj

Fix problems with compiling without KSH defined, add NOEDIT override.


# 1.2 19-Aug-1996 downsj

update to pdksh-5.2.8


# 1.1 14-Aug-1996 downsj

branches: 1.1.1;
Initial revision


# 1.76 10-Oct-2022 kn

Trigger ERR trap on permanent I/O redirection failure

The following three cases behave identical in bash(1), but our ksh
(ksh93 also) fails to run the trap in the last case:

(non-zero exit code is trigger, no redirection)
$ ksh -c 'trap "echo ERR" ERR ; false'
ERR

(failed redirection is trigger, 'echo' was not executed)
$ ksh -c 'trap "echo ERR" ERR ; echo >/'
ksh: cannot create /: Is a directory
ERR

(failed redirection, no execution, trap was NOT triggered)
$ ksh -c 'trap "echo ERR" ERR ; exec >/'
ksh: cannot create /: Is a directory


bash(1) prints "ERR" in all three cases, as expected.
ksh93 behaves like our ksh(1).

In ksh `exec' is a builtin (CSHELL), but also special (SPEC_BI):
$ type alias
alias is a shell builtin
$ type exec
exec is a special shell builtin

Without command and redirection alone, `exec' permanently redirects I/O for
the shell itself, not executing anything; it is the only (special) builtin
with such a special use-case, implemented as c_sh.c:c_exec().

This corner-case is overlooked in exec.c:execute() which handles iosetup()
failure for all commands, incl. builtins.

Exclude c_exec() from the rest of special builtins to ensure it runs the
ERR trap as expected:

$ ./obj/ksh -c 'trap "echo ERR" ERR ; exec >/'
ksh: cannot create /: Is a directory
ERR

Also add three new regress cases covering this; rest keep passing.

OK millert


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.75 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.74 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 15-Mar-2018 anton

Favor usage of __func__ in warning/error messages. Some of them referred to the
wrong function and fix the rest for consistency.
Diff from Michael W. Bombardieri with some cosmetic cleanup applied.

ok benno@ tb@


# 1.72 16-Jan-2018 jca

Introduce internal_warningf() and mark internal_errorf() as noreturn

This helps tools like scan-build, and follows the example of warningf()
and errorf(). ok anton@


# 1.71 15-Jan-2018 jca

Stop pretending we support building ksh without EDIT/HISTORY support

ok anton@


# 1.70 27-Dec-2017 millert

Add -Wshadow to Makefile and fix the resulting warnings. Many of
the warnings are due to the use of globals with generic names,
specifically "options" and "path". I've renamed "options" to
"sh_options" since it holds the shell options and "path" to
"search_path". OK jca@ tb@


# 1.69 18-Dec-2017 anton

Get rid of a todo by stop declaring variable texec as static and instead zeroing
it out prior to continuing down the recursive call chain.

Initial diff from Michael W. Bombardieri, later tweaked; ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.68 11-Dec-2016 millert

I missed a bit of the indentation fix from Kartik Agaram.


# 1.67 11-Dec-2016 millert

When ERREXIT (set -e) is in effect, don't disable it after a
short-circuited `&&` or `||` chain in later iterations of `for`
loops. It should be disabled after a short-circuited `&&` or `||`
chain only in the *final* iteration of loops (as well as in
conditionals, which was already working). From Kartik Agaram.


# 1.66 11-Dec-2016 millert

In execute() we assign xerrorok to a dummy value if it is NULL
so there is no need to check xerrorok for NULL after that.
From Kartik Agaram.


# 1.65 11-Dec-2016 millert

Fix for() loop indentation for TCASE in execute() and add some
braces for improved readability. Based on a diff from Kartik Agaram.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.64 30-Dec-2015 tedu

rename global "e" to genv to avoid accidental shadowing and aliasing.
ok millert nicm tb


# 1.63 14-Dec-2015 tb

Move system headers from sh.h to those files that actually need them.

ok mmcc@ a while ago


# 1.62 01-Nov-2015 mmcc

Add uses of areallocarray(). mksh and Bitrig ksh already have similar
functions. With help from Theo Buehler.

ok nicm@


# 1.61 19-Oct-2015 mmcc

Move string.h include from sh.h to the files that use it.

ok nicm@


# 1.60 19-Oct-2015 mmcc

Apply style(9) to header includes.

ok nicm@


# 1.59 17-Oct-2015 mmcc

Drop two useless defines.

ok nicm@


# 1.58 17-Oct-2015 mmcc

Move a system header include from the global header (sh.h) into the
files that need it. No binary change.

"This looks fine" -nicm@


# 1.57 22-Sep-2015 millert

Make errorf() and bi_errorf() handle a NULL argument.
From Michael McConville; OK nicm@


# 1.56 18-Sep-2015 nicm

Last of the (thing *)0 -> NULL, from Michael McConville. No binary
change.


# 1.55 17-Sep-2015 nicm

Remove unnecessary casts, from Michael McConville. No binary change.


# 1.54 15-Sep-2015 tedu

correct spelling of NULL from (char *)0. from Michael McConville.
ok md5


# 1.53 14-Sep-2015 nicm

Replace Tflag typedef with just int; ok tedu


# 1.52 10-Sep-2015 nicm

Replace newline and space defines by "\n" and " " directly, from Michael
McConville. ok millert


Revision tags: OPENBSD_5_8_BASE
# 1.51 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.50 10-Jun-2013 millert

POSIX specifies that for an AND/OR list, only the last command's
exit status matters for "set -e". Revert the part of revision 1.49
that always sets xerrok for AND/OR. This makes sh/ksh pass the
updated regress tests. OK espie@ jca@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.49 29-Jan-2009 jaredy

pass "xerrok" status across the execution call stack to more closely
match what both POSIX and ksh.1 already describe in regards to set
-e/errexit's behavior in determining when to exit from nonzero return
values.

specifically, the truth values tested as operands to `&&' and `||', as
well as the resulting compound expression itself, along with the truth
value resulting from a negated command (i.e. a pipeline prefixed `!'),
should not make the shell exit when -e is in effect.

issue reported by matthieu.
testing matthieu, naddy.
ok miod (earlier version), otto.
man page ok jmc.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.48 05-Sep-2007 otto

Call ERR trap _before_ doing exit handling. Otherwise it's too late
and the ERR trap won't get called at all. ok millert@


Revision tags: OPENBSD_4_2_BASE
# 1.47 02-Aug-2007 fgsch

another memory leak fix found by coverity. from netbsd but modified.
millert@ ok.


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.46 10-Apr-2006 jaredy

fix lint comments, no functional changes; ok ray


# 1.45 17-Mar-2006 millert

Simplify savefd() by removing the "noclose" flag and make noclose
behavior the default. Almost all uses of savefd() are followed
by an implicit or explicit close. OK otto@


Revision tags: OPENBSD_3_9_BASE
# 1.44 11-Dec-2005 otto

fix a few name clashes with libc; found by lint. ok deraadt@


# 1.43 11-Dec-2005 deraadt

remove unused variables and functions


# 1.42 11-Sep-2005 otto

Fix " handling in here documents. POSIX says they are not special, so
cat << EOF
\"
EOF
should print \"
Fixes PR 4472; testing jmc@ and Adam Montague. ok millert@


Revision tags: OPENBSD_3_8_BASE
# 1.41 30-Mar-2005 deraadt

lots of indentation cleanup, now ksh is readable like our other code.
double checked to make sure no binaries change, and eyed by niallo


# 1.40 28-Mar-2005 deraadt

spacing


Revision tags: OPENBSD_3_7_BASE
# 1.39 22-Dec-2004 otto

Fix a use-after-free, that causs core dumps if a shell is killed
running with strict malloc.conf options. Problem spotted by hshoexer@;
fix by me with some help from millert@.

ok millert@ hshoexer@ krw@ deraadt@


# 1.38 22-Dec-2004 millert

Use stdbool.h instead of rolling our own bools.


# 1.37 20-Dec-2004 otto

Ansification plus some minor knf. No binary change on i386 and
sparc64, binary change in lex.o on macppc due to introduction of
dopprompt() prototype. ok millert@


# 1.36 19-Dec-2004 deraadt

spacing


# 1.35 18-Dec-2004 millert

Replace fd_clexec() with calls to fcntl(fd, F_SETFD, FD_CLOEXEC)


# 1.34 18-Dec-2004 millert

deregister


# 1.33 18-Dec-2004 millert

Get rid of #ifdef KSH since we don't care about building a V7 style sh and
the #ifdef KSH code is required to make a POSIX sh. From Matthias Kilian


# 1.32 18-Dec-2004 millert

Remove unused OS dependent #ifdef blocks, #defines and macro abstraction.
First step in making the ksh code easier to read. From Matthias Kilian


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.31 15-Dec-2003 otto

Unbreak parameter assignment when calling bourne style functions;
resolves PR 2450.

ok deraadt@ millert@


# 1.30 10-Nov-2003 millert

If "from fd" == "to fd" don't call dup2() or close "from fd".


# 1.29 10-Nov-2003 millert

For the >& and <& operators, add a check for "dup from" == "dup to" and
just return success if they are the same. Fixes the "ls 2>&2" problem
miod@ found.


# 1.28 22-Oct-2003 jmc

typos from Jared Yanovich;
ok deraadt@


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE
# 1.27 28-Feb-2003 jmc

typos; from Brian Poole


Revision tags: OPENBSD_3_2_BASE
# 1.26 09-Jun-2002 todd

knf


Revision tags: OPENBSD_3_1_BASE
# 1.25 16-Jan-2002 millert

Use the volatile specifier to fix warnings about variables being
clobbered by longjmp / vfork instead of the gcc "(void)&foo;" hack.


Revision tags: OPENBSD_3_0_BASE
# 1.24 19-Jul-2001 millert

Back out last change, it caused problems with exit vals.


# 1.23 03-Jul-2001 millert

Merge in pdksh-5.2.14-patches.2 to fix some problems with propagated
return values in multi-command lines.


Revision tags: OPENBSD_2_9_BASE
# 1.22 19-Feb-2001 camield

bash-like 'double-tab' completion

- bind TAB (^I) to complete-list by default
- complete-list now lists 'ls style' not 'menu style'
- complete-list first completes; if that does not work, it lists
- fix a memleak in emacs.c, do_complete
- completion now works after '=' (dd), and ':' (ssh) and ` (backtick)
- a command can now start with a subdir from the current dir


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.21 15-Jul-1999 millert

silence -Wall


# 1.20 14-Jul-1999 millert

Official fix for workaround in 1.18


# 1.19 14-Jul-1999 millert

pdksh-5.2.14


# 1.18 23-Jun-1999 millert

When redirecting to a file with stdout closed, don't blithely reuse
fd 1 since that will cause future output on stdout to go to the file
that was redirected. There is probably a better fix for this.


# 1.17 15-Jun-1999 millert

patches from pdksh 5.2.13.11


Revision tags: OPENBSD_2_5_BASE
# 1.16 19-Jan-1999 millert

Updates from pdksh-unstable-5.2.13.7. Most notable change is:
trap: exit traps now executed in subshells (without explicit exit call).
See the Changelog for a full list of changes.


# 1.15 10-Jan-1999 millert

sync with pdksh-unstable-5.2.13.6


# 1.14 08-Jan-1999 millert

bug fixes from pdksh-unstable-5.2.13.5; some of which we already had.


# 1.13 29-Oct-1998 millert

Bug fixes from pdksh-unstable-5.2.13.4, including "official" versions of
some that we had already fixed locally.
o typeset -f FUNC doesn't print follows command (and expression) substitutions.
o when re-allocating memory, too much may be copied from old memory.
o set -o printed some options sans names.
o emacs mode: <esc>. in very fist command causes core dump.
o pdksh dumps core after a cd command.
o typeset -i reports on array elements that have no value
(at&t ksh reports on array base name - no index).
o ulimit -ctn unlimittttted kills shell (resource exceeded).
o ". /dev/null" says access denied.
o flag field in aliases incorrectly changed (all flags set instead of
clearing ISSET) in exec.c(flushcom).
o ${#array[*]} prints largest index instead of number of (set) elements
in an array (ksh88 does the former).
o sys_siglist[] doesn't always have NSIG non-null entries...


Revision tags: OPENBSD_2_4_BASE
# 1.12 27-Jun-1998 deraadt

new ksh code stupidly did not permit ". /dev/null"; enable that again


# 1.11 25-Jun-1998 millert

pdksh-5.2.13 + local changes


Revision tags: OPENBSD_2_3_BASE
# 1.10 12-Sep-1997 millert

Avoid longjmp/vfork clobbering.


# 1.9 19-Jun-1997 kstailey

back out


# 1.8 18-Jun-1997 kstailey

(foo *)0 -> NULL


# 1.7 02-Jan-1997 downsj

After discussing $_ with the maintainer, revert ksh behaviour and completely
eliminate it from sh.


# 1.6 02-Jan-1997 downsj

Add FSH (set -o sh), initialize it if we're /bin/sh, and add the first use:
don't set $_ if we're non-interactive.


# 1.5 21-Nov-1996 downsj

Update to 5.2.12.


# 1.4 01-Oct-1996 downsj

Integrate pdksh 5.2.9.


# 1.3 25-Aug-1996 downsj

Fix problems with compiling without KSH defined, add NOEDIT override.


# 1.2 19-Aug-1996 downsj

update to pdksh-5.2.8


# 1.1 14-Aug-1996 downsj

branches: 1.1.1;
Initial revision


# 1.75 24-Oct-2021 deraadt

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant. Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk. They could all be 0xdeafbeef.
ok millert


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.74 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 15-Mar-2018 anton

Favor usage of __func__ in warning/error messages. Some of them referred to the
wrong function and fix the rest for consistency.
Diff from Michael W. Bombardieri with some cosmetic cleanup applied.

ok benno@ tb@


# 1.72 16-Jan-2018 jca

Introduce internal_warningf() and mark internal_errorf() as noreturn

This helps tools like scan-build, and follows the example of warningf()
and errorf(). ok anton@


# 1.71 15-Jan-2018 jca

Stop pretending we support building ksh without EDIT/HISTORY support

ok anton@


# 1.70 27-Dec-2017 millert

Add -Wshadow to Makefile and fix the resulting warnings. Many of
the warnings are due to the use of globals with generic names,
specifically "options" and "path". I've renamed "options" to
"sh_options" since it holds the shell options and "path" to
"search_path". OK jca@ tb@


# 1.69 18-Dec-2017 anton

Get rid of a todo by stop declaring variable texec as static and instead zeroing
it out prior to continuing down the recursive call chain.

Initial diff from Michael W. Bombardieri, later tweaked; ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.68 11-Dec-2016 millert

I missed a bit of the indentation fix from Kartik Agaram.


# 1.67 11-Dec-2016 millert

When ERREXIT (set -e) is in effect, don't disable it after a
short-circuited `&&` or `||` chain in later iterations of `for`
loops. It should be disabled after a short-circuited `&&` or `||`
chain only in the *final* iteration of loops (as well as in
conditionals, which was already working). From Kartik Agaram.


# 1.66 11-Dec-2016 millert

In execute() we assign xerrorok to a dummy value if it is NULL
so there is no need to check xerrorok for NULL after that.
From Kartik Agaram.


# 1.65 11-Dec-2016 millert

Fix for() loop indentation for TCASE in execute() and add some
braces for improved readability. Based on a diff from Kartik Agaram.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.64 30-Dec-2015 tedu

rename global "e" to genv to avoid accidental shadowing and aliasing.
ok millert nicm tb


# 1.63 14-Dec-2015 tb

Move system headers from sh.h to those files that actually need them.

ok mmcc@ a while ago


# 1.62 01-Nov-2015 mmcc

Add uses of areallocarray(). mksh and Bitrig ksh already have similar
functions. With help from Theo Buehler.

ok nicm@


# 1.61 19-Oct-2015 mmcc

Move string.h include from sh.h to the files that use it.

ok nicm@


# 1.60 19-Oct-2015 mmcc

Apply style(9) to header includes.

ok nicm@


# 1.59 17-Oct-2015 mmcc

Drop two useless defines.

ok nicm@


# 1.58 17-Oct-2015 mmcc

Move a system header include from the global header (sh.h) into the
files that need it. No binary change.

"This looks fine" -nicm@


# 1.57 22-Sep-2015 millert

Make errorf() and bi_errorf() handle a NULL argument.
From Michael McConville; OK nicm@


# 1.56 18-Sep-2015 nicm

Last of the (thing *)0 -> NULL, from Michael McConville. No binary
change.


# 1.55 17-Sep-2015 nicm

Remove unnecessary casts, from Michael McConville. No binary change.


# 1.54 15-Sep-2015 tedu

correct spelling of NULL from (char *)0. from Michael McConville.
ok md5


# 1.53 14-Sep-2015 nicm

Replace Tflag typedef with just int; ok tedu


# 1.52 10-Sep-2015 nicm

Replace newline and space defines by "\n" and " " directly, from Michael
McConville. ok millert


Revision tags: OPENBSD_5_8_BASE
# 1.51 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.50 10-Jun-2013 millert

POSIX specifies that for an AND/OR list, only the last command's
exit status matters for "set -e". Revert the part of revision 1.49
that always sets xerrok for AND/OR. This makes sh/ksh pass the
updated regress tests. OK espie@ jca@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.49 29-Jan-2009 jaredy

pass "xerrok" status across the execution call stack to more closely
match what both POSIX and ksh.1 already describe in regards to set
-e/errexit's behavior in determining when to exit from nonzero return
values.

specifically, the truth values tested as operands to `&&' and `||', as
well as the resulting compound expression itself, along with the truth
value resulting from a negated command (i.e. a pipeline prefixed `!'),
should not make the shell exit when -e is in effect.

issue reported by matthieu.
testing matthieu, naddy.
ok miod (earlier version), otto.
man page ok jmc.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.48 05-Sep-2007 otto

Call ERR trap _before_ doing exit handling. Otherwise it's too late
and the ERR trap won't get called at all. ok millert@


Revision tags: OPENBSD_4_2_BASE
# 1.47 02-Aug-2007 fgsch

another memory leak fix found by coverity. from netbsd but modified.
millert@ ok.


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.46 10-Apr-2006 jaredy

fix lint comments, no functional changes; ok ray


# 1.45 17-Mar-2006 millert

Simplify savefd() by removing the "noclose" flag and make noclose
behavior the default. Almost all uses of savefd() are followed
by an implicit or explicit close. OK otto@


Revision tags: OPENBSD_3_9_BASE
# 1.44 11-Dec-2005 otto

fix a few name clashes with libc; found by lint. ok deraadt@


# 1.43 11-Dec-2005 deraadt

remove unused variables and functions


# 1.42 11-Sep-2005 otto

Fix " handling in here documents. POSIX says they are not special, so
cat << EOF
\"
EOF
should print \"
Fixes PR 4472; testing jmc@ and Adam Montague. ok millert@


Revision tags: OPENBSD_3_8_BASE
# 1.41 30-Mar-2005 deraadt

lots of indentation cleanup, now ksh is readable like our other code.
double checked to make sure no binaries change, and eyed by niallo


# 1.40 28-Mar-2005 deraadt

spacing


Revision tags: OPENBSD_3_7_BASE
# 1.39 22-Dec-2004 otto

Fix a use-after-free, that causs core dumps if a shell is killed
running with strict malloc.conf options. Problem spotted by hshoexer@;
fix by me with some help from millert@.

ok millert@ hshoexer@ krw@ deraadt@


# 1.38 22-Dec-2004 millert

Use stdbool.h instead of rolling our own bools.


# 1.37 20-Dec-2004 otto

Ansification plus some minor knf. No binary change on i386 and
sparc64, binary change in lex.o on macppc due to introduction of
dopprompt() prototype. ok millert@


# 1.36 19-Dec-2004 deraadt

spacing


# 1.35 18-Dec-2004 millert

Replace fd_clexec() with calls to fcntl(fd, F_SETFD, FD_CLOEXEC)


# 1.34 18-Dec-2004 millert

deregister


# 1.33 18-Dec-2004 millert

Get rid of #ifdef KSH since we don't care about building a V7 style sh and
the #ifdef KSH code is required to make a POSIX sh. From Matthias Kilian


# 1.32 18-Dec-2004 millert

Remove unused OS dependent #ifdef blocks, #defines and macro abstraction.
First step in making the ksh code easier to read. From Matthias Kilian


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.31 15-Dec-2003 otto

Unbreak parameter assignment when calling bourne style functions;
resolves PR 2450.

ok deraadt@ millert@


# 1.30 10-Nov-2003 millert

If "from fd" == "to fd" don't call dup2() or close "from fd".


# 1.29 10-Nov-2003 millert

For the >& and <& operators, add a check for "dup from" == "dup to" and
just return success if they are the same. Fixes the "ls 2>&2" problem
miod@ found.


# 1.28 22-Oct-2003 jmc

typos from Jared Yanovich;
ok deraadt@


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE
# 1.27 28-Feb-2003 jmc

typos; from Brian Poole


Revision tags: OPENBSD_3_2_BASE
# 1.26 09-Jun-2002 todd

knf


Revision tags: OPENBSD_3_1_BASE
# 1.25 16-Jan-2002 millert

Use the volatile specifier to fix warnings about variables being
clobbered by longjmp / vfork instead of the gcc "(void)&foo;" hack.


Revision tags: OPENBSD_3_0_BASE
# 1.24 19-Jul-2001 millert

Back out last change, it caused problems with exit vals.


# 1.23 03-Jul-2001 millert

Merge in pdksh-5.2.14-patches.2 to fix some problems with propagated
return values in multi-command lines.


Revision tags: OPENBSD_2_9_BASE
# 1.22 19-Feb-2001 camield

bash-like 'double-tab' completion

- bind TAB (^I) to complete-list by default
- complete-list now lists 'ls style' not 'menu style'
- complete-list first completes; if that does not work, it lists
- fix a memleak in emacs.c, do_complete
- completion now works after '=' (dd), and ':' (ssh) and ` (backtick)
- a command can now start with a subdir from the current dir


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.21 15-Jul-1999 millert

silence -Wall


# 1.20 14-Jul-1999 millert

Official fix for workaround in 1.18


# 1.19 14-Jul-1999 millert

pdksh-5.2.14


# 1.18 23-Jun-1999 millert

When redirecting to a file with stdout closed, don't blithely reuse
fd 1 since that will cause future output on stdout to go to the file
that was redirected. There is probably a better fix for this.


# 1.17 15-Jun-1999 millert

patches from pdksh 5.2.13.11


Revision tags: OPENBSD_2_5_BASE
# 1.16 19-Jan-1999 millert

Updates from pdksh-unstable-5.2.13.7. Most notable change is:
trap: exit traps now executed in subshells (without explicit exit call).
See the Changelog for a full list of changes.


# 1.15 10-Jan-1999 millert

sync with pdksh-unstable-5.2.13.6


# 1.14 08-Jan-1999 millert

bug fixes from pdksh-unstable-5.2.13.5; some of which we already had.


# 1.13 29-Oct-1998 millert

Bug fixes from pdksh-unstable-5.2.13.4, including "official" versions of
some that we had already fixed locally.
o typeset -f FUNC doesn't print follows command (and expression) substitutions.
o when re-allocating memory, too much may be copied from old memory.
o set -o printed some options sans names.
o emacs mode: <esc>. in very fist command causes core dump.
o pdksh dumps core after a cd command.
o typeset -i reports on array elements that have no value
(at&t ksh reports on array base name - no index).
o ulimit -ctn unlimittttted kills shell (resource exceeded).
o ". /dev/null" says access denied.
o flag field in aliases incorrectly changed (all flags set instead of
clearing ISSET) in exec.c(flushcom).
o ${#array[*]} prints largest index instead of number of (set) elements
in an array (ksh88 does the former).
o sys_siglist[] doesn't always have NSIG non-null entries...


Revision tags: OPENBSD_2_4_BASE
# 1.12 27-Jun-1998 deraadt

new ksh code stupidly did not permit ". /dev/null"; enable that again


# 1.11 25-Jun-1998 millert

pdksh-5.2.13 + local changes


Revision tags: OPENBSD_2_3_BASE
# 1.10 12-Sep-1997 millert

Avoid longjmp/vfork clobbering.


# 1.9 19-Jun-1997 kstailey

back out


# 1.8 18-Jun-1997 kstailey

(foo *)0 -> NULL


# 1.7 02-Jan-1997 downsj

After discussing $_ with the maintainer, revert ksh behaviour and completely
eliminate it from sh.


# 1.6 02-Jan-1997 downsj

Add FSH (set -o sh), initialize it if we're /bin/sh, and add the first use:
don't set $_ if we're non-interactive.


# 1.5 21-Nov-1996 downsj

Update to 5.2.12.


# 1.4 01-Oct-1996 downsj

Integrate pdksh 5.2.9.


# 1.3 25-Aug-1996 downsj

Fix problems with compiling without KSH defined, add NOEDIT override.


# 1.2 19-Aug-1996 downsj

update to pdksh-5.2.8


# 1.1 14-Aug-1996 downsj

branches: 1.1.1;
Initial revision


# 1.74 28-Jun-2019 deraadt

When system calls indicate an error they return -1, not some arbitrary
value < 0. errno is only updated in this case. Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.73 15-Mar-2018 anton

Favor usage of __func__ in warning/error messages. Some of them referred to the
wrong function and fix the rest for consistency.
Diff from Michael W. Bombardieri with some cosmetic cleanup applied.

ok benno@ tb@


# 1.72 16-Jan-2018 jca

Introduce internal_warningf() and mark internal_errorf() as noreturn

This helps tools like scan-build, and follows the example of warningf()
and errorf(). ok anton@


# 1.71 15-Jan-2018 jca

Stop pretending we support building ksh without EDIT/HISTORY support

ok anton@


# 1.70 27-Dec-2017 millert

Add -Wshadow to Makefile and fix the resulting warnings. Many of
the warnings are due to the use of globals with generic names,
specifically "options" and "path". I've renamed "options" to
"sh_options" since it holds the shell options and "path" to
"search_path". OK jca@ tb@


# 1.69 18-Dec-2017 anton

Get rid of a todo by stop declaring variable texec as static and instead zeroing
it out prior to continuing down the recursive call chain.

Initial diff from Michael W. Bombardieri, later tweaked; ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.68 11-Dec-2016 millert

I missed a bit of the indentation fix from Kartik Agaram.


# 1.67 11-Dec-2016 millert

When ERREXIT (set -e) is in effect, don't disable it after a
short-circuited `&&` or `||` chain in later iterations of `for`
loops. It should be disabled after a short-circuited `&&` or `||`
chain only in the *final* iteration of loops (as well as in
conditionals, which was already working). From Kartik Agaram.


# 1.66 11-Dec-2016 millert

In execute() we assign xerrorok to a dummy value if it is NULL
so there is no need to check xerrorok for NULL after that.
From Kartik Agaram.


# 1.65 11-Dec-2016 millert

Fix for() loop indentation for TCASE in execute() and add some
braces for improved readability. Based on a diff from Kartik Agaram.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.64 30-Dec-2015 tedu

rename global "e" to genv to avoid accidental shadowing and aliasing.
ok millert nicm tb


# 1.63 14-Dec-2015 tb

Move system headers from sh.h to those files that actually need them.

ok mmcc@ a while ago


# 1.62 01-Nov-2015 mmcc

Add uses of areallocarray(). mksh and Bitrig ksh already have similar
functions. With help from Theo Buehler.

ok nicm@


# 1.61 19-Oct-2015 mmcc

Move string.h include from sh.h to the files that use it.

ok nicm@


# 1.60 19-Oct-2015 mmcc

Apply style(9) to header includes.

ok nicm@


# 1.59 17-Oct-2015 mmcc

Drop two useless defines.

ok nicm@


# 1.58 17-Oct-2015 mmcc

Move a system header include from the global header (sh.h) into the
files that need it. No binary change.

"This looks fine" -nicm@


# 1.57 22-Sep-2015 millert

Make errorf() and bi_errorf() handle a NULL argument.
From Michael McConville; OK nicm@


# 1.56 18-Sep-2015 nicm

Last of the (thing *)0 -> NULL, from Michael McConville. No binary
change.


# 1.55 17-Sep-2015 nicm

Remove unnecessary casts, from Michael McConville. No binary change.


# 1.54 15-Sep-2015 tedu

correct spelling of NULL from (char *)0. from Michael McConville.
ok md5


# 1.53 14-Sep-2015 nicm

Replace Tflag typedef with just int; ok tedu


# 1.52 10-Sep-2015 nicm

Replace newline and space defines by "\n" and " " directly, from Michael
McConville. ok millert


Revision tags: OPENBSD_5_8_BASE
# 1.51 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.50 10-Jun-2013 millert

POSIX specifies that for an AND/OR list, only the last command's
exit status matters for "set -e". Revert the part of revision 1.49
that always sets xerrok for AND/OR. This makes sh/ksh pass the
updated regress tests. OK espie@ jca@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.49 29-Jan-2009 jaredy

pass "xerrok" status across the execution call stack to more closely
match what both POSIX and ksh.1 already describe in regards to set
-e/errexit's behavior in determining when to exit from nonzero return
values.

specifically, the truth values tested as operands to `&&' and `||', as
well as the resulting compound expression itself, along with the truth
value resulting from a negated command (i.e. a pipeline prefixed `!'),
should not make the shell exit when -e is in effect.

issue reported by matthieu.
testing matthieu, naddy.
ok miod (earlier version), otto.
man page ok jmc.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.48 05-Sep-2007 otto

Call ERR trap _before_ doing exit handling. Otherwise it's too late
and the ERR trap won't get called at all. ok millert@


Revision tags: OPENBSD_4_2_BASE
# 1.47 02-Aug-2007 fgsch

another memory leak fix found by coverity. from netbsd but modified.
millert@ ok.


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.46 10-Apr-2006 jaredy

fix lint comments, no functional changes; ok ray


# 1.45 17-Mar-2006 millert

Simplify savefd() by removing the "noclose" flag and make noclose
behavior the default. Almost all uses of savefd() are followed
by an implicit or explicit close. OK otto@


Revision tags: OPENBSD_3_9_BASE
# 1.44 11-Dec-2005 otto

fix a few name clashes with libc; found by lint. ok deraadt@


# 1.43 11-Dec-2005 deraadt

remove unused variables and functions


# 1.42 11-Sep-2005 otto

Fix " handling in here documents. POSIX says they are not special, so
cat << EOF
\"
EOF
should print \"
Fixes PR 4472; testing jmc@ and Adam Montague. ok millert@


Revision tags: OPENBSD_3_8_BASE
# 1.41 30-Mar-2005 deraadt

lots of indentation cleanup, now ksh is readable like our other code.
double checked to make sure no binaries change, and eyed by niallo


# 1.40 28-Mar-2005 deraadt

spacing


Revision tags: OPENBSD_3_7_BASE
# 1.39 22-Dec-2004 otto

Fix a use-after-free, that causs core dumps if a shell is killed
running with strict malloc.conf options. Problem spotted by hshoexer@;
fix by me with some help from millert@.

ok millert@ hshoexer@ krw@ deraadt@


# 1.38 22-Dec-2004 millert

Use stdbool.h instead of rolling our own bools.


# 1.37 20-Dec-2004 otto

Ansification plus some minor knf. No binary change on i386 and
sparc64, binary change in lex.o on macppc due to introduction of
dopprompt() prototype. ok millert@


# 1.36 19-Dec-2004 deraadt

spacing


# 1.35 18-Dec-2004 millert

Replace fd_clexec() with calls to fcntl(fd, F_SETFD, FD_CLOEXEC)


# 1.34 18-Dec-2004 millert

deregister


# 1.33 18-Dec-2004 millert

Get rid of #ifdef KSH since we don't care about building a V7 style sh and
the #ifdef KSH code is required to make a POSIX sh. From Matthias Kilian


# 1.32 18-Dec-2004 millert

Remove unused OS dependent #ifdef blocks, #defines and macro abstraction.
First step in making the ksh code easier to read. From Matthias Kilian


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.31 15-Dec-2003 otto

Unbreak parameter assignment when calling bourne style functions;
resolves PR 2450.

ok deraadt@ millert@


# 1.30 10-Nov-2003 millert

If "from fd" == "to fd" don't call dup2() or close "from fd".


# 1.29 10-Nov-2003 millert

For the >& and <& operators, add a check for "dup from" == "dup to" and
just return success if they are the same. Fixes the "ls 2>&2" problem
miod@ found.


# 1.28 22-Oct-2003 jmc

typos from Jared Yanovich;
ok deraadt@


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE
# 1.27 28-Feb-2003 jmc

typos; from Brian Poole


Revision tags: OPENBSD_3_2_BASE
# 1.26 09-Jun-2002 todd

knf


Revision tags: OPENBSD_3_1_BASE
# 1.25 16-Jan-2002 millert

Use the volatile specifier to fix warnings about variables being
clobbered by longjmp / vfork instead of the gcc "(void)&foo;" hack.


Revision tags: OPENBSD_3_0_BASE
# 1.24 19-Jul-2001 millert

Back out last change, it caused problems with exit vals.


# 1.23 03-Jul-2001 millert

Merge in pdksh-5.2.14-patches.2 to fix some problems with propagated
return values in multi-command lines.


Revision tags: OPENBSD_2_9_BASE
# 1.22 19-Feb-2001 camield

bash-like 'double-tab' completion

- bind TAB (^I) to complete-list by default
- complete-list now lists 'ls style' not 'menu style'
- complete-list first completes; if that does not work, it lists
- fix a memleak in emacs.c, do_complete
- completion now works after '=' (dd), and ':' (ssh) and ` (backtick)
- a command can now start with a subdir from the current dir


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.21 15-Jul-1999 millert

silence -Wall


# 1.20 14-Jul-1999 millert

Official fix for workaround in 1.18


# 1.19 14-Jul-1999 millert

pdksh-5.2.14


# 1.18 23-Jun-1999 millert

When redirecting to a file with stdout closed, don't blithely reuse
fd 1 since that will cause future output on stdout to go to the file
that was redirected. There is probably a better fix for this.


# 1.17 15-Jun-1999 millert

patches from pdksh 5.2.13.11


Revision tags: OPENBSD_2_5_BASE
# 1.16 19-Jan-1999 millert

Updates from pdksh-unstable-5.2.13.7. Most notable change is:
trap: exit traps now executed in subshells (without explicit exit call).
See the Changelog for a full list of changes.


# 1.15 10-Jan-1999 millert

sync with pdksh-unstable-5.2.13.6


# 1.14 08-Jan-1999 millert

bug fixes from pdksh-unstable-5.2.13.5; some of which we already had.


# 1.13 29-Oct-1998 millert

Bug fixes from pdksh-unstable-5.2.13.4, including "official" versions of
some that we had already fixed locally.
o typeset -f FUNC doesn't print follows command (and expression) substitutions.
o when re-allocating memory, too much may be copied from old memory.
o set -o printed some options sans names.
o emacs mode: <esc>. in very fist command causes core dump.
o pdksh dumps core after a cd command.
o typeset -i reports on array elements that have no value
(at&t ksh reports on array base name - no index).
o ulimit -ctn unlimittttted kills shell (resource exceeded).
o ". /dev/null" says access denied.
o flag field in aliases incorrectly changed (all flags set instead of
clearing ISSET) in exec.c(flushcom).
o ${#array[*]} prints largest index instead of number of (set) elements
in an array (ksh88 does the former).
o sys_siglist[] doesn't always have NSIG non-null entries...


Revision tags: OPENBSD_2_4_BASE
# 1.12 27-Jun-1998 deraadt

new ksh code stupidly did not permit ". /dev/null"; enable that again


# 1.11 25-Jun-1998 millert

pdksh-5.2.13 + local changes


Revision tags: OPENBSD_2_3_BASE
# 1.10 12-Sep-1997 millert

Avoid longjmp/vfork clobbering.


# 1.9 19-Jun-1997 kstailey

back out


# 1.8 18-Jun-1997 kstailey

(foo *)0 -> NULL


# 1.7 02-Jan-1997 downsj

After discussing $_ with the maintainer, revert ksh behaviour and completely
eliminate it from sh.


# 1.6 02-Jan-1997 downsj

Add FSH (set -o sh), initialize it if we're /bin/sh, and add the first use:
don't set $_ if we're non-interactive.


# 1.5 21-Nov-1996 downsj

Update to 5.2.12.


# 1.4 01-Oct-1996 downsj

Integrate pdksh 5.2.9.


# 1.3 25-Aug-1996 downsj

Fix problems with compiling without KSH defined, add NOEDIT override.


# 1.2 19-Aug-1996 downsj

update to pdksh-5.2.8


# 1.1 14-Aug-1996 downsj

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_3_BASE
# 1.73 15-Mar-2018 anton

Favor usage of __func__ in warning/error messages. Some of them referred to the
wrong function and fix the rest for consistency.
Diff from Michael W. Bombardieri with some cosmetic cleanup applied.

ok benno@ tb@


# 1.72 16-Jan-2018 jca

Introduce internal_warningf() and mark internal_errorf() as noreturn

This helps tools like scan-build, and follows the example of warningf()
and errorf(). ok anton@


# 1.71 15-Jan-2018 jca

Stop pretending we support building ksh without EDIT/HISTORY support

ok anton@


# 1.70 27-Dec-2017 millert

Add -Wshadow to Makefile and fix the resulting warnings. Many of
the warnings are due to the use of globals with generic names,
specifically "options" and "path". I've renamed "options" to
"sh_options" since it holds the shell options and "path" to
"search_path". OK jca@ tb@


# 1.69 18-Dec-2017 anton

Get rid of a todo by stop declaring variable texec as static and instead zeroing
it out prior to continuing down the recursive call chain.

Initial diff from Michael W. Bombardieri, later tweaked; ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.68 11-Dec-2016 millert

I missed a bit of the indentation fix from Kartik Agaram.


# 1.67 11-Dec-2016 millert

When ERREXIT (set -e) is in effect, don't disable it after a
short-circuited `&&` or `||` chain in later iterations of `for`
loops. It should be disabled after a short-circuited `&&` or `||`
chain only in the *final* iteration of loops (as well as in
conditionals, which was already working). From Kartik Agaram.


# 1.66 11-Dec-2016 millert

In execute() we assign xerrorok to a dummy value if it is NULL
so there is no need to check xerrorok for NULL after that.
From Kartik Agaram.


# 1.65 11-Dec-2016 millert

Fix for() loop indentation for TCASE in execute() and add some
braces for improved readability. Based on a diff from Kartik Agaram.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.64 30-Dec-2015 tedu

rename global "e" to genv to avoid accidental shadowing and aliasing.
ok millert nicm tb


# 1.63 14-Dec-2015 tb

Move system headers from sh.h to those files that actually need them.

ok mmcc@ a while ago


# 1.62 01-Nov-2015 mmcc

Add uses of areallocarray(). mksh and Bitrig ksh already have similar
functions. With help from Theo Buehler.

ok nicm@


# 1.61 19-Oct-2015 mmcc

Move string.h include from sh.h to the files that use it.

ok nicm@


# 1.60 19-Oct-2015 mmcc

Apply style(9) to header includes.

ok nicm@


# 1.59 17-Oct-2015 mmcc

Drop two useless defines.

ok nicm@


# 1.58 17-Oct-2015 mmcc

Move a system header include from the global header (sh.h) into the
files that need it. No binary change.

"This looks fine" -nicm@


# 1.57 22-Sep-2015 millert

Make errorf() and bi_errorf() handle a NULL argument.
From Michael McConville; OK nicm@


# 1.56 18-Sep-2015 nicm

Last of the (thing *)0 -> NULL, from Michael McConville. No binary
change.


# 1.55 17-Sep-2015 nicm

Remove unnecessary casts, from Michael McConville. No binary change.


# 1.54 15-Sep-2015 tedu

correct spelling of NULL from (char *)0. from Michael McConville.
ok md5


# 1.53 14-Sep-2015 nicm

Replace Tflag typedef with just int; ok tedu


# 1.52 10-Sep-2015 nicm

Replace newline and space defines by "\n" and " " directly, from Michael
McConville. ok millert


Revision tags: OPENBSD_5_8_BASE
# 1.51 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.50 10-Jun-2013 millert

POSIX specifies that for an AND/OR list, only the last command's
exit status matters for "set -e". Revert the part of revision 1.49
that always sets xerrok for AND/OR. This makes sh/ksh pass the
updated regress tests. OK espie@ jca@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.49 29-Jan-2009 jaredy

pass "xerrok" status across the execution call stack to more closely
match what both POSIX and ksh.1 already describe in regards to set
-e/errexit's behavior in determining when to exit from nonzero return
values.

specifically, the truth values tested as operands to `&&' and `||', as
well as the resulting compound expression itself, along with the truth
value resulting from a negated command (i.e. a pipeline prefixed `!'),
should not make the shell exit when -e is in effect.

issue reported by matthieu.
testing matthieu, naddy.
ok miod (earlier version), otto.
man page ok jmc.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.48 05-Sep-2007 otto

Call ERR trap _before_ doing exit handling. Otherwise it's too late
and the ERR trap won't get called at all. ok millert@


Revision tags: OPENBSD_4_2_BASE
# 1.47 02-Aug-2007 fgsch

another memory leak fix found by coverity. from netbsd but modified.
millert@ ok.


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.46 10-Apr-2006 jaredy

fix lint comments, no functional changes; ok ray


# 1.45 17-Mar-2006 millert

Simplify savefd() by removing the "noclose" flag and make noclose
behavior the default. Almost all uses of savefd() are followed
by an implicit or explicit close. OK otto@


Revision tags: OPENBSD_3_9_BASE
# 1.44 11-Dec-2005 otto

fix a few name clashes with libc; found by lint. ok deraadt@


# 1.43 11-Dec-2005 deraadt

remove unused variables and functions


# 1.42 11-Sep-2005 otto

Fix " handling in here documents. POSIX says they are not special, so
cat << EOF
\"
EOF
should print \"
Fixes PR 4472; testing jmc@ and Adam Montague. ok millert@


Revision tags: OPENBSD_3_8_BASE
# 1.41 30-Mar-2005 deraadt

lots of indentation cleanup, now ksh is readable like our other code.
double checked to make sure no binaries change, and eyed by niallo


# 1.40 28-Mar-2005 deraadt

spacing


Revision tags: OPENBSD_3_7_BASE
# 1.39 22-Dec-2004 otto

Fix a use-after-free, that causs core dumps if a shell is killed
running with strict malloc.conf options. Problem spotted by hshoexer@;
fix by me with some help from millert@.

ok millert@ hshoexer@ krw@ deraadt@


# 1.38 22-Dec-2004 millert

Use stdbool.h instead of rolling our own bools.


# 1.37 20-Dec-2004 otto

Ansification plus some minor knf. No binary change on i386 and
sparc64, binary change in lex.o on macppc due to introduction of
dopprompt() prototype. ok millert@


# 1.36 19-Dec-2004 deraadt

spacing


# 1.35 18-Dec-2004 millert

Replace fd_clexec() with calls to fcntl(fd, F_SETFD, FD_CLOEXEC)


# 1.34 18-Dec-2004 millert

deregister


# 1.33 18-Dec-2004 millert

Get rid of #ifdef KSH since we don't care about building a V7 style sh and
the #ifdef KSH code is required to make a POSIX sh. From Matthias Kilian


# 1.32 18-Dec-2004 millert

Remove unused OS dependent #ifdef blocks, #defines and macro abstraction.
First step in making the ksh code easier to read. From Matthias Kilian


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.31 15-Dec-2003 otto

Unbreak parameter assignment when calling bourne style functions;
resolves PR 2450.

ok deraadt@ millert@


# 1.30 10-Nov-2003 millert

If "from fd" == "to fd" don't call dup2() or close "from fd".


# 1.29 10-Nov-2003 millert

For the >& and <& operators, add a check for "dup from" == "dup to" and
just return success if they are the same. Fixes the "ls 2>&2" problem
miod@ found.


# 1.28 22-Oct-2003 jmc

typos from Jared Yanovich;
ok deraadt@


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE
# 1.27 28-Feb-2003 jmc

typos; from Brian Poole


Revision tags: OPENBSD_3_2_BASE
# 1.26 09-Jun-2002 todd

knf


Revision tags: OPENBSD_3_1_BASE
# 1.25 16-Jan-2002 millert

Use the volatile specifier to fix warnings about variables being
clobbered by longjmp / vfork instead of the gcc "(void)&foo;" hack.


Revision tags: OPENBSD_3_0_BASE
# 1.24 19-Jul-2001 millert

Back out last change, it caused problems with exit vals.


# 1.23 03-Jul-2001 millert

Merge in pdksh-5.2.14-patches.2 to fix some problems with propagated
return values in multi-command lines.


Revision tags: OPENBSD_2_9_BASE
# 1.22 19-Feb-2001 camield

bash-like 'double-tab' completion

- bind TAB (^I) to complete-list by default
- complete-list now lists 'ls style' not 'menu style'
- complete-list first completes; if that does not work, it lists
- fix a memleak in emacs.c, do_complete
- completion now works after '=' (dd), and ':' (ssh) and ` (backtick)
- a command can now start with a subdir from the current dir


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.21 15-Jul-1999 millert

silence -Wall


# 1.20 14-Jul-1999 millert

Official fix for workaround in 1.18


# 1.19 14-Jul-1999 millert

pdksh-5.2.14


# 1.18 23-Jun-1999 millert

When redirecting to a file with stdout closed, don't blithely reuse
fd 1 since that will cause future output on stdout to go to the file
that was redirected. There is probably a better fix for this.


# 1.17 15-Jun-1999 millert

patches from pdksh 5.2.13.11


Revision tags: OPENBSD_2_5_BASE
# 1.16 19-Jan-1999 millert

Updates from pdksh-unstable-5.2.13.7. Most notable change is:
trap: exit traps now executed in subshells (without explicit exit call).
See the Changelog for a full list of changes.


# 1.15 10-Jan-1999 millert

sync with pdksh-unstable-5.2.13.6


# 1.14 08-Jan-1999 millert

bug fixes from pdksh-unstable-5.2.13.5; some of which we already had.


# 1.13 29-Oct-1998 millert

Bug fixes from pdksh-unstable-5.2.13.4, including "official" versions of
some that we had already fixed locally.
o typeset -f FUNC doesn't print follows command (and expression) substitutions.
o when re-allocating memory, too much may be copied from old memory.
o set -o printed some options sans names.
o emacs mode: <esc>. in very fist command causes core dump.
o pdksh dumps core after a cd command.
o typeset -i reports on array elements that have no value
(at&t ksh reports on array base name - no index).
o ulimit -ctn unlimittttted kills shell (resource exceeded).
o ". /dev/null" says access denied.
o flag field in aliases incorrectly changed (all flags set instead of
clearing ISSET) in exec.c(flushcom).
o ${#array[*]} prints largest index instead of number of (set) elements
in an array (ksh88 does the former).
o sys_siglist[] doesn't always have NSIG non-null entries...


Revision tags: OPENBSD_2_4_BASE
# 1.12 27-Jun-1998 deraadt

new ksh code stupidly did not permit ". /dev/null"; enable that again


# 1.11 25-Jun-1998 millert

pdksh-5.2.13 + local changes


Revision tags: OPENBSD_2_3_BASE
# 1.10 12-Sep-1997 millert

Avoid longjmp/vfork clobbering.


# 1.9 19-Jun-1997 kstailey

back out


# 1.8 18-Jun-1997 kstailey

(foo *)0 -> NULL


# 1.7 02-Jan-1997 downsj

After discussing $_ with the maintainer, revert ksh behaviour and completely
eliminate it from sh.


# 1.6 02-Jan-1997 downsj

Add FSH (set -o sh), initialize it if we're /bin/sh, and add the first use:
don't set $_ if we're non-interactive.


# 1.5 21-Nov-1996 downsj

Update to 5.2.12.


# 1.4 01-Oct-1996 downsj

Integrate pdksh 5.2.9.


# 1.3 25-Aug-1996 downsj

Fix problems with compiling without KSH defined, add NOEDIT override.


# 1.2 19-Aug-1996 downsj

update to pdksh-5.2.8


# 1.1 14-Aug-1996 downsj

branches: 1.1.1;
Initial revision


# 1.72 16-Jan-2018 jca

Introduce internal_warningf() and mark internal_errorf() as noreturn

This helps tools like scan-build, and follows the example of warningf()
and errorf(). ok anton@


# 1.71 15-Jan-2018 jca

Stop pretending we support building ksh without EDIT/HISTORY support

ok anton@


# 1.70 27-Dec-2017 millert

Add -Wshadow to Makefile and fix the resulting warnings. Many of
the warnings are due to the use of globals with generic names,
specifically "options" and "path". I've renamed "options" to
"sh_options" since it holds the shell options and "path" to
"search_path". OK jca@ tb@


# 1.69 18-Dec-2017 anton

Get rid of a todo by stop declaring variable texec as static and instead zeroing
it out prior to continuing down the recursive call chain.

Initial diff from Michael W. Bombardieri, later tweaked; ok tb@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.68 11-Dec-2016 millert

I missed a bit of the indentation fix from Kartik Agaram.


# 1.67 11-Dec-2016 millert

When ERREXIT (set -e) is in effect, don't disable it after a
short-circuited `&&` or `||` chain in later iterations of `for`
loops. It should be disabled after a short-circuited `&&` or `||`
chain only in the *final* iteration of loops (as well as in
conditionals, which was already working). From Kartik Agaram.


# 1.66 11-Dec-2016 millert

In execute() we assign xerrorok to a dummy value if it is NULL
so there is no need to check xerrorok for NULL after that.
From Kartik Agaram.


# 1.65 11-Dec-2016 millert

Fix for() loop indentation for TCASE in execute() and add some
braces for improved readability. Based on a diff from Kartik Agaram.


Revision tags: OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.64 30-Dec-2015 tedu

rename global "e" to genv to avoid accidental shadowing and aliasing.
ok millert nicm tb


# 1.63 14-Dec-2015 tb

Move system headers from sh.h to those files that actually need them.

ok mmcc@ a while ago


# 1.62 01-Nov-2015 mmcc

Add uses of areallocarray(). mksh and Bitrig ksh already have similar
functions. With help from Theo Buehler.

ok nicm@


# 1.61 19-Oct-2015 mmcc

Move string.h include from sh.h to the files that use it.

ok nicm@


# 1.60 19-Oct-2015 mmcc

Apply style(9) to header includes.

ok nicm@


# 1.59 17-Oct-2015 mmcc

Drop two useless defines.

ok nicm@


# 1.58 17-Oct-2015 mmcc

Move a system header include from the global header (sh.h) into the
files that need it. No binary change.

"This looks fine" -nicm@


# 1.57 22-Sep-2015 millert

Make errorf() and bi_errorf() handle a NULL argument.
From Michael McConville; OK nicm@


# 1.56 18-Sep-2015 nicm

Last of the (thing *)0 -> NULL, from Michael McConville. No binary
change.


# 1.55 17-Sep-2015 nicm

Remove unnecessary casts, from Michael McConville. No binary change.


# 1.54 15-Sep-2015 tedu

correct spelling of NULL from (char *)0. from Michael McConville.
ok md5


# 1.53 14-Sep-2015 nicm

Replace Tflag typedef with just int; ok tedu


# 1.52 10-Sep-2015 nicm

Replace newline and space defines by "\n" and " " directly, from Michael
McConville. ok millert


Revision tags: OPENBSD_5_8_BASE
# 1.51 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.50 10-Jun-2013 millert

POSIX specifies that for an AND/OR list, only the last command's
exit status matters for "set -e". Revert the part of revision 1.49
that always sets xerrok for AND/OR. This makes sh/ksh pass the
updated regress tests. OK espie@ jca@


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.49 29-Jan-2009 jaredy

pass "xerrok" status across the execution call stack to more closely
match what both POSIX and ksh.1 already describe in regards to set
-e/errexit's behavior in determining when to exit from nonzero return
values.

specifically, the truth values tested as operands to `&&' and `||', as
well as the resulting compound expression itself, along with the truth
value resulting from a negated command (i.e. a pipeline prefixed `!'),
should not make the shell exit when -e is in effect.

issue reported by matthieu.
testing matthieu, naddy.
ok miod (earlier version), otto.
man page ok jmc.


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.48 05-Sep-2007 otto

Call ERR trap _before_ doing exit handling. Otherwise it's too late
and the ERR trap won't get called at all. ok millert@


Revision tags: OPENBSD_4_2_BASE
# 1.47 02-Aug-2007 fgsch

another memory leak fix found by coverity. from netbsd but modified.
millert@ ok.


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.46 10-Apr-2006 jaredy

fix lint comments, no functional changes; ok ray


# 1.45 17-Mar-2006 millert

Simplify savefd() by removing the "noclose" flag and make noclose
behavior the default. Almost all uses of savefd() are followed
by an implicit or explicit close. OK otto@


Revision tags: OPENBSD_3_9_BASE
# 1.44 11-Dec-2005 otto

fix a few name clashes with libc; found by lint. ok deraadt@


# 1.43 11-Dec-2005 deraadt

remove unused variables and functions


# 1.42 11-Sep-2005 otto

Fix " handling in here documents. POSIX says they are not special, so
cat << EOF
\"
EOF
should print \"
Fixes PR 4472; testing jmc@ and Adam Montague. ok millert@


Revision tags: OPENBSD_3_8_BASE
# 1.41 30-Mar-2005 deraadt

lots of indentation cleanup, now ksh is readable like our other code.
double checked to make sure no binaries change, and eyed by niallo


# 1.40 28-Mar-2005 deraadt

spacing


Revision tags: OPENBSD_3_7_BASE
# 1.39 22-Dec-2004 otto

Fix a use-after-free, that causs core dumps if a shell is killed
running with strict malloc.conf options. Problem spotted by hshoexer@;
fix by me with some help from millert@.

ok millert@ hshoexer@ krw@ deraadt@


# 1.38 22-Dec-2004 millert

Use stdbool.h instead of rolling our own bools.


# 1.37 20-Dec-2004 otto

Ansification plus some minor knf. No binary change on i386 and
sparc64, binary change in lex.o on macppc due to introduction of
dopprompt() prototype. ok millert@


# 1.36 19-Dec-2004 deraadt

spacing


# 1.35 18-Dec-2004 millert

Replace fd_clexec() with calls to fcntl(fd, F_SETFD, FD_CLOEXEC)


# 1.34 18-Dec-2004 millert

deregister


# 1.33 18-Dec-2004 millert

Get rid of #ifdef KSH since we don't care about building a V7 style sh and
the #ifdef KSH code is required to make a POSIX sh. From Matthias Kilian


# 1.32 18-Dec-2004 millert

Remove unused OS dependent #ifdef blocks, #defines and macro abstraction.
First step in making the ksh code easier to read. From Matthias Kilian


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.31 15-Dec-2003 otto

Unbreak parameter assignment when calling bourne style functions;
resolves PR 2450.

ok deraadt@ millert@


# 1.30 10-Nov-2003 millert

If "from fd" == "to fd" don't call dup2() or close "from fd".


# 1.29 10-Nov-2003 millert

For the >& and <& operators, add a check for "dup from" == "dup to" and
just return success if they are the same. Fixes the "ls 2>&2" problem
miod@ found.


# 1.28 22-Oct-2003 jmc

typos from Jared Yanovich;
ok deraadt@


Revision tags: OPENBSD_3_3_BASE OPENBSD_3_4_BASE
# 1.27 28-Feb-2003 jmc

typos; from Brian Poole


Revision tags: OPENBSD_3_2_BASE
# 1.26 09-Jun-2002 todd

knf


Revision tags: OPENBSD_3_1_BASE
# 1.25 16-Jan-2002 millert

Use the volatile specifier to fix warnings about variables being
clobbered by longjmp / vfork instead of the gcc "(void)&foo;" hack.


Revision tags: OPENBSD_3_0_BASE
# 1.24 19-Jul-2001 millert

Back out last change, it caused problems with exit vals.


# 1.23 03-Jul-2001 millert

Merge in pdksh-5.2.14-patches.2 to fix some problems with propagated
return values in multi-command lines.


Revision tags: OPENBSD_2_9_BASE
# 1.22 19-Feb-2001 camield

bash-like 'double-tab' completion

- bind TAB (^I) to complete-list by default
- complete-list now lists 'ls style' not 'menu style'
- complete-list first completes; if that does not work, it lists
- fix a memleak in emacs.c, do_complete
- completion now works after '=' (dd), and ':' (ssh) and ` (backtick)
- a command can now start with a subdir from the current dir


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.21 15-Jul-1999 millert

silence -Wall


# 1.20 14-Jul-1999 millert

Official fix for workaround in 1.18


# 1.19 14-Jul-1999 millert

pdksh-5.2.14


# 1.18 23-Jun-1999 millert

When redirecting to a file with stdout closed, don't blithely reuse
fd 1 since that will cause future output on stdout to go to the file
that was redirected. There is probably a better fix for this.


# 1.17 15-Jun-1999 millert

patches from pdksh 5.2.13.11


Revision tags: OPENBSD_2_5_BASE
# 1.16 19-Jan-1999 millert

Updates from pdksh-unstable-5.2.13.7. Most notable change is:
trap: exit traps now executed in subshells (without explicit exit call).
See the Changelog for a full list of changes.


# 1.15 10-Jan-1999 millert

sync with pdksh-unstable-5.2.13.6


# 1.14 08-Jan-1999 millert

bug fixes from pdksh-unstable-5.2.13.5; some of which we already had.


# 1.13 29-Oct-1998 millert

Bug fixes from pdksh-unstable-5.2.13.4, including "official" versions of
some that we had already fixed locally.
o typeset -f FUNC doesn't print follows command (and expression) substitutions.
o when re-allocating memory, too much may be copied from old memory.
o set -o printed some options sans names.
o emacs mode: <esc>. in very fist command causes core dump.
o pdksh dumps core after a cd command.
o typeset -i reports on array elements that have no value
(at&t ksh reports on array base name - no index).
o ulimit -ctn unlimittttted kills shell (resource exceeded).
o ". /dev/null" says access denied.
o flag field in aliases incorrectly changed (all flags set instead of
clearing ISSET) in exec.c(flushcom).
o ${#array[*]} prints largest index instead of number of (set) elements
in an array (ksh88 does the former).
o sys_siglist[] doesn't always have NSIG non-null entries...


Revision tags: OPENBSD_2_4_BASE
# 1.12 27-Jun-1998 deraadt

new ksh code stupidly did not permit ". /dev/null"; enable that again


# 1.11 25-Jun-1998 millert

pdksh-5.2.13 + local changes


Revision tags: OPENBSD_2_3_BASE
# 1.10 12-Sep-1997 millert

Avoid longjmp/vfork clobbering.


# 1.9 19-Jun-1997 kstailey

back out


# 1.8 18-Jun-1997 kstailey

(foo *)0 -> NULL


# 1.7 02-Jan-1997 downsj

After discussing $_ with the maintainer, revert ksh behaviour and completely
eliminate it from sh.


# 1.6 02-Jan-1997 downsj

Add FSH (set -o sh), initialize it if we're /bin/sh, and add the first use:
don't set $_ if we're non-interactive.


# 1.5 21-Nov-1996 downsj

Update to 5.2.12.


# 1.4 01-Oct-1996 downsj

Integrate pdksh 5.2.9.


# 1.3 25-Aug-1996 downsj

Fix problems with compiling without KSH defined, add NOEDIT override.


# 1.2 19-Aug-1996 downsj

update to pdksh-5.2.8


# 1.1 14-Aug-1996 downsj

branches: 1.1.1;
Initial revision