History log of /freebsd-9.3-release/bin/sh/main.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 241030 28-Sep-2012 jilles

MFC r240505: sh: Reduce code duplication: use setinputfile instead of
open/setinputfd combination.


# 231790 15-Feb-2012 jilles

MFC r229220: sh: Make various functions static.


# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 223060 13-Jun-2011 jilles

sh: Fix duplicate prototypes for builtins.

Have mkbuiltins write the prototypes for the *cmd functions to builtins.h
instead of builtins.c and include builtins.h in more .c files instead of
duplicating prototypes for *cmd functions in other headers.


# 223005 12-Jun-2011 jilles

sh: Read .profile from the home directory (or / if HOME is not set).

In most cases, login shells are started from the home directory, but not in
all, such as xterm -ls.

This commit depends on r222957 for read_profile() performing parameter
expansion.

PR: bin/50569


# 222957 10-Jun-2011 jilles

sh: Do parameter expansion on ENV before using it.

This is required by POSIX, and allows things like ENV=\$HOME/.shrc.

Note that tilde expansion is explicitly not performed.


# 222684 04-Jun-2011 jilles

sh: Reduce more needless differences between error messages.


# 222173 22-May-2011 jilles

sh: Fix bss-based buffer overflow in . builtin.

If the length of a directory in PATH together with the given filename
exceeded FILENAME_MAX (which may happen even for pathnames that work), a
static buffer was overflown.

The static buffer is unnecessary, we can use the stalloc() stack.

Obtained from: NetBSD
MFC after: 1 week


# 221669 08-May-2011 jilles

sh: Add \u/\U support (in $'...') for UTF-8.

Because we have no iconv in base, support for other charsets is not
possible.

Note that \u/\U are processed using the locale that was active when the
shell started. This is necessary to avoid behaviour that depends on the
parse/execute split (for example when placing braces around an entire
script). Therefore, UTF-8 encoding is implemented manually.


# 221559 06-May-2011 jilles

sh: Track if the current locale's charset is UTF-8 or not.


# 220978 23-Apr-2011 jilles

sh: Allow EV_EXIT through function calls, make {...} <redir more consistent.

If EV_EXIT causes an exit, use the exception mechanism to unwind
redirections and local variables. This way, if the final command is a
redirected command, an EXIT trap now executes without the redirections.

Because of these changes, EV_EXIT can now be inherited by the body of a
function, so do so. This means that a function no longer prevents a fork
before an exec being skipped, such as in
f() { head -1 /etc/passwd; }; echo $(f)

Wrapping a single builtin in a function may still cause an otherwise
unnecessary fork with command substitution, however.

An exit command or -e failure still invokes the EXIT trap with the
original redirections and local variables in place.

Note: this depends on SHELLPROC being gone. A SHELLPROC depended on
keeping the redirections and local variables and only cleaning up the
state to restore them.


# 218306 04-Feb-2011 jilles

sh: Remove special code for shell scripts without magic number.

These are called "shell procedures" in the source.

If execve() failed with [ENOEXEC], the shell would reinitialize itself
and execute the program as a script. This requires a fair amount of code
which is not frequently used (most scripts have a #! magic number).
Therefore just execute a new instance of sh (_PATH_BSHELL) to run the
script.


# 217175 08-Jan-2011 jilles

sh: Make exit without parameters from EXIT trap POSIX-compliant.

It should use the original exit status, just like falling off the
end of the trap handler.

Outside an EXIT trap, 'exit' is still equivalent to 'exit $?'.


# 215567 20-Nov-2010 jilles

sh: Code size optimizations to buffered output.

This is mainly less use of the outc macro.

No functional change is intended, but code size is about 2K less on i386.


# 213811 13-Oct-2010 obrien

In the spirit of r90111, depend on c89 and remove the "STATIC" macro
and its usage.


# 211349 15-Aug-2010 jilles

sh: Fix break/continue/return sometimes not skipping the rest of dot script.

In our implementation and most others, a break or continue in a dot script
can break or continue a loop outside the dot script. This should cause all
further commands in the dot script to be skipped. However, cmdloop() did not
know about this and continued to parse and execute commands from the dot
script.

As described in the man page, a return in a dot script in a function returns
from the function, not only from the dot script. There was a similar issue
as with break and continue. In various other shells, the return appears to
return from the dot script, but POSIX seems not very clear about this.


# 208630 28-May-2010 jilles

sh: Recognize "--" in . and exec.

Although "--" historically has not been required to be recognized for
certain special builtins that do not take options in POSIX, some other
implementations recognize options for them, requiring scripts to use "--" or
avoid operands starting with "-".

Operands starting with "-" can be avoided with eval by prepending a space,
and cannot occur with break, continue, exit, return and shift as they only
take numbers, nor with times as it does not take operands. With . and exec,
avoiding "-" is not so easy as it may require reimplementing the PATH
search; therefore the current proposal for POSIX is to require recognition
of "--" for them.

We continue to accept other strings starting with "-" as operands to . and
exec, and also "--" if it is alone to . (which would otherwise be invalid
anyway).


# 206759 17-Apr-2010 jilles

sh: On startup of the shell, use PWD from the environment if it is valid.
Unset PWD if it is incorrect and no value for it can be determined.
This preserves the logical current directory across shell invocations.

Example (assuming /home is a symlink):
$ cd
$ pwd
/home/foo
$ sh
$ pwd
/home/foo

Formerly the second pwd would show the physical path (symlinks resolved).


# 203576 06-Feb-2010 jilles

sh: Do not stat() $MAIL/$MAILPATH in non-interactive shells.

These may be NFS mounted, and we should not touch them unless we are going
to do something useful with the information.


# 201053 27-Dec-2009 jilles

sh: Various warning fixes (from WARNS=6 NO_WERROR=1):
- const
- initializations to silence -Wuninitialized (it was safe anyway)
- remove nested extern declarations
- rename "index" locals to "idx"


# 200998 25-Dec-2009 jilles

sh: Do not run callers' exception handlers in subshells.

Reset the exception handler in the child to main's.

This avoids inappropriate double cleanups or shell duplication when the
exception is caught, such as 'fc' and future 'command eval' and 'command .'.


# 200956 24-Dec-2009 jilles

sh: Constify various strings.

Most of this is adding const keywords, but setvar() in var.c had to be
changed somewhat more.


# 200943 24-Dec-2009 jilles

sh: Remove setting variables from dotcmd/exportcmd.

It is already done by evalcommand(), unless special-ness has been removed,
in which case variable assignments should not persist. (These are currently
always special builtins, but this will change later: command builtin,
command substitution.)

This also fixes a memory leak when calling . with variable assignments.

Example:
valgrind --leak-check=full sh -c 'x=1 . /dev/null; x=2'


# 199629 21-Nov-2009 jilles

sh: Some changes to stderr flushing:
* increase buffer size from 100 to 256 bytes
* remove implied flush from out2str(), in particular this avoids unnecessary
flushing in the middle of a -x tracing line
* rename dprintf() to out2fmt_flush(), make it flush out2 and use this
function in various places where flushing is desired after an error
message


# 194128 13-Jun-2009 jilles

Avoid leaving unnecessary waiting shells in many forms of sh -c COMMAND.

This change only affects strings passed to -c, when the -s
option is not used.

The approach is to check if there may be additional data
in the string after parsing each command. If there is none,
use the EV_EXIT flag so that a fork may be omitted in
specific cases.

If there are empty lines after the command, the check will
not see the end and forks will not be omitted. The same
thing seems to happen in bash.

Example:
sh -c 'ps lT'
No longer shows a shell process waiting for ps to finish.

PR: bin/113860
Reviewed by: stefanf
Approved by: ed (mentor)


# 193169 31-May-2009 stefanf

Fix the eval command in combination with set -e. Before this change the shell
would always terminate if eval returned with a non-zero exit status regardless
if the status was actually tested. Unfortunately a new file-scope variable
is needed, the alternative would only be to add a new parameter to all
built-ins.

PR: 134881


# 163085 07-Oct-2006 stefanf

Add the POSIX option -p to the jobs builtin command. It prints the PID of the
process leader for each job. Now the last specified option for the output
format (-l, -p or -s) wins, previously -s trumped -l.

PR: 99926
Submitted by: Ed Schouten and novel (patches modified by me)


# 157414 02-Apr-2006 stefanf

Issue an error when . (dot) is invoked without a filename. The synopsis
is just ". file" according to POSIX, however many other shells allow
arguments to be passed after the file. For compatibility (we even use that
feature in buildworld) additional arguments are not considered to be an
error, even though this shell does not do anything with the arguments at all.


# 155304 04-Feb-2006 schweikh

Initialize PWD early on (don't expect it to be inherited from the
environment or set it only when changing directories with cd).

PR: standards/92640


# 127958 06-Apr-2004 markm

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 104261 30-Sep-2002 tjr

Remove some kind of profiling support that required the 4.2BSD monitor()
function in libc.


# 104255 30-Sep-2002 tjr

Remove bits and pieces of support for atty, which was made obsolete by
adding history and vi/emacs-style line editing to the shell itself.
Atty was a user-mode terminal emulator (like screen and window) that did
line editing and history.


# 99110 30-Jun-2002 obrien

Consistently use FBSDID


# 97669 31-May-2002 tjr

Add -s (output PID's only) and -l (show PID's) options to the jobs(1)
builtin. Modify the output format to match what SUSv3 requires.


# 90111 02-Feb-2002 imp

o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
they already are.
o Change
int
foo() {
...
to
int
foo(void)
{
...


# 64702 16-Aug-2000 cracauer

From submitter:
growstackblock() sometimes relocates a stack_block considered empty
without properly relocating stack marks referencing that block.
The first call to popstackmark() with the unrelocated stack mark
as argument then causes sh to abort.

Relocating the relevant stack marks seems to solve this problem.

The patch changes the semantics of popstackmark() somewhat. It can
only be called once after a call to setstackmark(), thus cmdloop() in
main.c needs an extra call to setstackmark().

PR: bin/19983
Submitted by: Tor.Egge@fast.no
Reviewed by: Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>


# 59214 14-Apr-2000 imp

Use #include <errno.h> rather than extern int errno;.


# 53891 29-Nov-1999 cracauer

Include strerror(errno) in error messages after failed system calls.
Fix a warning.


# 50471 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 46684 08-May-1999 kris

Various spelling/formatting changes.

Submitted by: Philippe Charnier <charnier@xp11.frmug.org>


# 36150 18-May-1998 charnier

Add rcsid. Spelling.


# 25471 05-May-1997 steve

Don't source $ENV unless this is an interactive shell.


# 22988 22-Feb-1997 peter

Revert $FreeBSD$ to $Id$


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 20774 21-Dec-1996 steve

Make sh(1) a little braver in the face of adversity. sh(1)
now handles the getpwd() init problem the same way as bash
and ksh do. Also while I was in here, I cleaned up the format
a little, removed some unnnecessary #if SYMLINKS cruft, and
changed the pwd builtin to use getcwd(3) as Joerg suggested.


# 20425 14-Dec-1996 steve

Merge in NetBSD mods and -Wall cleaning.

Obtained from: NetBSD, me


# 19240 29-Oct-1996 steve

Add the -p (privileged) commandline switch
found in bash, zsh, and friends.

Reviewed by: joerg


# 18267 12-Sep-1996 adam

Mend 'exit' without breaking 'exit 1'
*blush* %-\

Pointed out by: bruce


# 18254 12-Sep-1996 bde

Backed out last change. It broke even `exit 1'.


# 18154 08-Sep-1996 adam

let the "exit" command return status when it is implicit


# 17987 01-Sep-1996 peter

Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is a
merge of parallel duplicate work by Steve Price and myself. :-]

There are some changes to the build that are my fault... mkinit.c was
trying (poorly) to duplicate some of the work that make(1) is designed to
do. The Makefile hackery is my fault too, the depend list was incomplete
because of some explicit OBJS+= entries, so mkdep wasn't picking up their
source file #includes.

This closes a pile of /bin/sh PR's, but not all of them..

Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter


# 17525 11-Aug-1996 ache

Localize it


# 8855 29-May-1995 rgrimes

Remove trailing whitespace.

Reviewed by: phk


# 3044 24-Sep-1994 dg

Added $Id$


# 1557 26-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1556,
which included commits to RCS files with non-trunk default branches.


# 1556 26-May-1994 rgrimes

BSD 4.4 Lite bin Sources