summaryrefslogtreecommitdiffstats
path: root/bin/sh/redir.c
Commit message (Collapse)AuthorAgeFilesLines
* sh: Don't allocate a redirtab if there are no redirections.jilles2016-01-301-7/+22
| | | | | | | | | | | | | | | | | Builtins (including variable assignments without command word), function calls and redirected compound commands need to restore file descriptors to their original state after execution. This is handled by allocating a redirtab structure. These mallocs and frees show up heavily in pmcstat. Only allocate a redirtab if there are actually redirections and maintain a count of how many levels of REDIR_PUSH there are without redirtabs. A simple loop without external programs like sh -c 'i=0; w=$(printf %0100d 7); while [ "$i" -lt 1000000 ]; do i=$((i+1)); done' is over 25% faster on an amd64 bhyve VM.
* sh: Eliminate some gotos.jilles2014-10-051-15/+14
|
* sh: Fix possible memory leaks and double frees with unexpected SIGINT.jilles2014-03-261-10/+11
|
* sh: Add some consts.jilles2014-03-141-2/+2
|
* sh: Make <&0 disable the </dev/null implicit in a background command.jilles2013-11-241-4/+5
| | | | | | Although <&0 does nothing, it is a redirection affecting standard input and should therefore disable the </dev/null redirection implicit in a background command.
* sh: Remove unnecessary reset functions.jilles2013-08-161-12/+0
| | | | These are already handled by exception handlers.
* sh: Remove #define MKINIT.jilles2013-07-251-2/+1
| | | | MKINIT only served for the removed mkinit. Many variables can be static now.
* sh: Remove mkinit.jilles2013-07-251-6/+3
| | | | | | | | | | | | | | 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.
* sh: Use O_CLOEXEC and F_DUPFD_CLOEXEC instead of separate fcntl() call.jilles2013-05-051-3/+2
|
* sh: Write as much into the heredoc pipe as possible, to avoid forking.jilles2013-04-021-5/+13
| | | | | | 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.
* sh: Expand here documents in the current process.jilles2013-02-031-10/+12
| | | | | | | | | | | | | | | | | 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.
* sh: Remove special code for shell scripts without magic number.jilles2011-02-041-4/+0
| | | | | | | | | | 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.
* sh: Check if dup2 for redirection from/to a file succeeds.jilles2010-12-311-1/+6
| | | | | | | | A failure (e.g. caused by ulimit -n being set very low) is a redirection error. Example: ulimit -n 9; exec 9<.
* sh: Check whether dup2 was successful for >&FD and <&FD.jilles2010-10-241-2/+5
| | | | | | A failure (usually caused by FD not being open) is a redirection error. Exp-run done by: pav (with some other sh(1) changes)
* In the spirit of r90111, depend on c89 and remove the "STATIC" macroobrien2010-10-131-4/+4
| | | | and its usage.
* Consistently use "STATIC" for all functions in order to be able to setobrien2010-10-131-1/+1
| | | | | | breakpoints with in a debugger. And use naked "static" for variables. Noticed by: bde
* Fix some cases where file descriptors from redirections leak to programs.jilles2009-11-291-15/+7
| | | | | | | | | | | | | | | | - 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.
* Fix various things about SIGINT handling:jilles2009-11-221-2/+5
| | | | | | | | | | | | | | | | | | * 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.
* Fix race condition in noclobber option.jilles2009-06-201-7/+19
| | | | | | | | | | 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)
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* Replace home-grown dup2() implementation with actual dup2() calls. Thisdes2004-01-211-32/+8
| | | | | | | 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
* Changes following CScout analysis:dds2003-07-051-1/+1
| | | | | | | | | | | - 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
* Remove dead code which supported systems without O_APPEND, O_CREAT or SIGTSTP.tjr2002-09-291-30/+0
|
* Convert the remaining callers of errmsg() to use strerror(), and removetjr2002-09-291-11/+11
| | | | errmsg() and its table of error messages.
* Don't assume file descriptors fit in a short, use an int instead.tjr2002-07-181-1/+1
|
* Close file descriptors when [n]>&- and [n]<&- redirections are used.tjr2002-07-091-1/+2
| | | | | | | This was broken by rev. 1.16. PR: 40334 MFC after: 1 week
* Consistently use FBSDIDobrien2002-06-301-2/+2
|
* Implement the -C (-o noclobber) option, which prevents existing regulartjr2002-05-191-0/+11
| | | | files from being overwritten by shell redirection.
* o __P has been reovedimp2002-02-021-19/+15
| | | | | | | | | | | | | | | | | | 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) { ...
* The fix for >/dev/stdout, including Tor Egge's fix for the bug in thebabkin2002-01-131-4/+4
| | | | | | | | 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
* backout rev 1.14, it's breaking things.alfred2001-12-241-1/+3
|
* Added ability to do ">/dev/stdout". The apsfilter people are anxiousbabkin2001-12-221-3/+1
| | | | | | to get it MFCed in time for release 4.5. MFC after: 2 weeks
* Implement the <> redirection operator.brian2000-10-031-0/+21
|
* Include strerror(errno) in error messages after failed system calls.cracauer1999-11-291-1/+1
| | | | Fix a warning.
* $Id$ -> $FreeBSD$peter1999-08-271-1/+1
|
* Add rcsid. Spelling.charnier1998-05-181-3/+5
|
* Fix redirection of unopened file descriptors and nuke registersteve1997-04-281-9/+27
| | | | | | keyword usage. Obtained from: NetBSD
* Revert $FreeBSD$ to $Id$peter1997-02-221-1/+1
|
* Make the long-awaited change from $Id$ to $FreeBSD$jkh1997-01-141-1/+1
| | | | | | | | 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.
* Merge in NetBSD mods and -Wall cleaning.steve1996-12-141-9/+11
| | | | Obtained from: NetBSD, me
* Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is apeter1996-09-011-18/+18
| | | | | | | | | | | | | | 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
* o rename ulimit -p into ulimit -u, so we are in agreement with bashjoerg1995-10-211-1/+6
| | | | | | | 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
* Remove trailing whitespace.rgrimes1995-05-301-3/+3
| | | | Reviewed by: phk
* Added $Id$dg1994-09-241-0/+2
|
* BSD 4.4 Lite bin Sourcesrgrimes1994-05-261-0/+343
OpenPOWER on IntegriCloud