summaryrefslogtreecommitdiffstats
path: root/bin/sh/redir.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r272575: sh: Eliminate some gotos.jilles2015-09-131-15/+14
| | | | This MFC is to avoid conflicts in the MFC of r287148.
* MFC r263777: sh: Fix possible memory leaks and double frees with unexpectedjilles2014-04-141-10/+11
| | | | SIGINT.
* MFC r263195: sh: Add some consts.jilles2014-04-051-2/+2
|
* Sync sh(1) in stable/10 to head.jmmv2014-03-091-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* 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