History log of /freebsd-10.1-release/bin/sh/redir.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 272461 02-Oct-2014 gjb

Copy stable/10@r272459 to releng/10.1 as part of
the 10.1-RELEASE process.

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

# 264478 14-Apr-2014 jilles

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


# 264168 05-Apr-2014 jilles

MFC r263195: sh: Add some consts.


# 262951 09-Mar-2014 jmmv

Sync sh(1) in stable/10 to head.

This is a MFC of all the commits listed below.

My original goal of this change was to only merge the move of the tests
from tools/regression/bin/ into the new layout (which include tests for
sh(1) and other tools as well). However, doing so is tricky due to the
ongoing work in sh(1) and, especially, the many changes to its tests
since stable/10 was first branched.

Merging everything is the simplest way to achieve this goal and, as a
bonus point, we get various fixes and miscellaneous improvements into
the branch.

Per jilles' suggestion, I'm avoiding the merge of a couple of changes
(r256850 and r257506) that required depending kernel changes. I'm also
avoiding very recent changes that have not had a long enough time to be
validated in current.

This is "make tinderbox" clean.

r256735 sh: Remove one syscall when waiting for a foreground job.
r257399 sh: Allow trapping SIGINT/SIGQUIT after ignore because of '&'.
r257504 sh: Reorder union node to reduce its size on 64-bit platforms.
r257920 sh: Add a test case for would-be assignments that are not due to quoting.
r257929 sh: Properly quote alias output from command -v.
r258489 sh: Add tests for the </dev/null implicit in a background command.
r258533 sh: Add more tests for the </dev/null implicit in a background command.
r258535 sh: Make <&0 disable the </dev/null implicit in a background command.
r258776 sh: Prefer memcpy() to strcpy() in most cases. Remove the scopy macro.
r259047 sh: Split set -x output into a separate function.
r259210 Migrate tools/regression/bin/ tests to the new layout.
r259844 sh: Remove an unused variable.
r259846 sh: Initialize OPTIND=1 even if it came from the environment.
r259874 sh: Simplify code related to PPID variable.
r259946 sh: Don't check input for non-whitespace if history is disabled.
r260246 sh(1): Discourage use of -e.
r260506 Run the sh(1) and test(1) tests as unprivileged.
r260586 Mark the bin/pax tests as requiring perl.
r260634 Use TAP_TESTS_PERL to register the legacy_test in bin/pax.
r260635 Replace hand-crafted Kyuafiles with automatic generation.
r260654 sh: Remove SIGWINCH handler and just check for resize before every read.
r261121 sh: Add test for nested alias.
r261125 sh: Solve the alias recursion problem in a less hackish way.
r261141 sh: Do not depend on parse/execute split in new alias test.
r261160 sh: Add tests for alias names after another alias.
r261192 sh: Allow aliases to force alias substitution on the following word.
r262533 sh: Make expari() static.
r262565 sh: Do not corrupt internal representation if LINENO inner expansion fails.
r262697 sh: Simplify expari().

Reviewed by: jilles


# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

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


# 254426 16-Aug-2013 jilles

sh: Remove unnecessary reset functions.

These are already handled by exception handlers.


# 253658 25-Jul-2013 jilles

sh: Remove #define MKINIT.

MKINIT only served for the removed mkinit. Many variables can be static now.


# 253650 25-Jul-2013 jilles

sh: Remove mkinit.

Replace the RESET blocks with regular functions and a reset() function that
calls them all.

This code generation tool is unusual and does not appear to provide much
benefit. I do not think isolating the knowledge about which modules need to
be reset is worth an almost 500-line build tool and wider scope for
variables used by the reset functions.

Also, relying on reset functions is often wrong: the cleanup should be done
in exception handlers so that no stale state remains after 'command eval'
and the like.


# 250267 05-May-2013 jilles

sh: Use O_CLOEXEC and F_DUPFD_CLOEXEC instead of separate fcntl() call.


# 249034 02-Apr-2013 jilles

sh: Write as much into the heredoc pipe as possible, to avoid forking.

Use non-blocking I/O to write as much as the pipe will accept (often 64K,
but it can be as little as 4K), avoiding the need for the ugly PIPESIZE
constant. If PIPESIZE was set too high, a deadlock would occur.


# 246288 03-Feb-2013 jilles

sh: Expand here documents in the current process.

Expand here documents at the same point other redirections are expanded but
use a non-fork subshell environment (like simple command substitutions) for
compatibility. Substitition errors result in an empty here document like
before.

As a result, a fork is avoided for short (<4K) expanded here documents.

Unexpanded here documents (with quoted end marker after <<) are not affected
by this change. They already only forked when >4K.

Side effects:
* Order of expansion is slightly different.
* Slow expansions are not executed in parallel with the redirected command.
* A non-fork subshell environment is subtly different from a forked process.


# 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