History log of /freebsd-9.3-release/bin/sh/redir.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

# 264629 17-Apr-2014 jilles

MFC r263777: sh: Fix possible memory leaks and double frees with unexpected
SIGINT.


# 225736 22-Sep-2011 kensmith

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

Approved by: re (implicit)


# 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.


# 216851 31-Dec-2010 jilles

sh: Check if dup2 for redirection from/to a file succeeds.

A failure (e.g. caused by ulimit -n being set very low) is a redirection
error.

Example:
ulimit -n 9; exec 9<.


# 214290 24-Oct-2010 jilles

sh: Check whether dup2 was successful for >&FD and <&FD.

A failure (usually caused by FD not being open) is a redirection error.

Exp-run done by: pav (with some other sh(1) changes)


# 213811 13-Oct-2010 obrien

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


# 213760 13-Oct-2010 obrien

Consistently use "STATIC" for all functions in order to be able to set
breakpoints with in a debugger. And use naked "static" for variables.

Noticed by: bde


# 199953 29-Nov-2009 jilles

Fix some cases where file descriptors from redirections leak to programs.

- Redirecting fds that were not open before kept two copies of the
redirected file.
sh -c '{ :; } 7>/dev/null; fstat -p $$; true'
(both fd 7 and 10 remained open)
- File descriptors used to restore things after redirection were not
set close-on-exec, instead they were explicitly closed before executing
a program normally and before executing a shell procedure. The latter
must remain but the former is replaced by close-on-exec.
sh -c 'exec 7</; { exec fstat -p $$; } 7>/dev/null; true'
(fd 10 remained open)

The examples above are simpler than the testsuite because I do not want to
use fstat or procstat in the testsuite.


# 199660 22-Nov-2009 jilles

Fix various things about SIGINT handling:
* exception handlers are now run with interrupts disabled, which avoids
many race conditions
* fix some cases where SIGINT only aborts one command and continues the
script, in particular if a SIGINT causes an EINTR error which trumped the
interrupt.

Example:
sh -c 'echo < /some/fifo; echo This should not be printed'
The fifo should not have writers. When pressing ctrl+c to abort the open,
the shell used to continue with the next command.

Example:
sh -c '/bin/echo < /some/fifo; echo This should not be printed'
Similar. Note, however, that this particular case did not and does not work
in interactive mode with job control enabled.


# 194560 20-Jun-2009 jilles

Fix race condition in noclobber option.

Formerly, it was possible for the file to be created between the check if it
existed and the open; the contents would then be lost.

Because this must use O_EXCL, noclobber > will not create a file through a
symlink anymore. This agrees with behaviour of other shells.

Approved by: ed (mentor) (implicit)


# 127958 06-Apr-2004 markm

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 124780 21-Jan-2004 des

Replace home-grown dup2() implementation with actual dup2() calls. This
should slightly reduce the number of system calls in critical portions of
the shell, and select a more efficient path through the fdalloc code.

Reviewed by: bde


# 117261 05-Jul-2003 dds

Changes following CScout analysis:

- Removed dead declarations
- Made objects that should have been declared as static, static.

The changes use STATIC instead of static, following the existing
convention in the rest of the code.

Approved by: schweikh (mentor)
MFC after: 2 weeks


# 104141 29-Sep-2002 tjr

Remove dead code which supported systems without O_APPEND, O_CREAT or SIGTSTP.


# 104132 29-Sep-2002 tjr

Convert the remaining callers of errmsg() to use strerror(), and remove
errmsg() and its table of error messages.


# 100315 18-Jul-2002 tjr

Don't assume file descriptors fit in a short, use an int instead.


# 99645 09-Jul-2002 tjr

Close file descriptors when [n]>&- and [n]<&- redirections are used.
This was broken by rev. 1.16.

PR: 40334
MFC after: 1 week


# 99110 30-Jun-2002 obrien

Consistently use FBSDID


# 96922 19-May-2002 tjr

Implement the -C (-o noclobber) option, which prevents existing regular
files from being overwritten by shell redirection.


# 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)
{
...


# 89312 13-Jan-2002 babkin

The fix for >/dev/stdout, including Tor Egge's fix for the bug in the
original attempt of the fix. And yes, this time I've tried to build
world with it and it succeeded.

Submitted by: Tor Egge
MFC after: 1 week


# 88463 24-Dec-2001 alfred

backout rev 1.14, it's breaking things.


# 88396 22-Dec-2001 babkin

Added ability to do ">/dev/stdout". The apsfilter people are anxious
to get it MFCed in time for release 4.5.

MFC after: 2 weeks


# 66612 03-Oct-2000 brian

Implement the <> redirection operator.


# 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$


# 36150 18-May-1998 charnier

Add rcsid. Spelling.


# 25231 28-Apr-1997 steve

Fix redirection of unopened file descriptors and nuke register
keyword usage.

Obtained from: NetBSD


# 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.


# 20425 14-Dec-1996 steve

Merge in NetBSD mods and -Wall cleaning.

Obtained from: NetBSD, me


# 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


# 11601 20-Oct-1995 joerg

o rename ulimit -p into ulimit -u, so we are in agreement with bash

o fix brokeness for 1>&5 redirection, where `5' was an invalid file
descriptor, but no error message has been generated

o fix brokeness for redirect to/from myself case


# 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