summaryrefslogtreecommitdiffstats
path: root/bin
Commit message (Collapse)AuthorAgeFilesLines
* sh: Do not call exitshell() from evalcommand() unless evalcommand() forkedjilles2011-01-051-4/+5
| | | | | | itself. This ensures that certain traps caused by builtins are executed.
* Increase carried_error if we skip a file due to an error. This ensuresjh2011-01-031-0/+4
| | | | | | | | | that setfacl(1) exits with proper exit status on failure. PR: bin/149780 Submitted by: Ævar Arnfjörð Bjarmason (original version) Reviewed by: trasz MFC after: 3 weeks
* sh: Check readonly status for assignments on regular builtins.jilles2011-01-013-5/+9
| | | | | | | | | | An error message is written, the builtin is not executed, nonzero exit status is returned but the shell does not abort. This was already checked for special builtins and external commands, with the same consequences except that the shell aborts for special builtins. Obtained from: NetBSD
* 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: Avoid side effects from builtins in optimized command substitution.jilles2010-12-301-5/+27
| | | | | | | | | | | | | | | | | | Change the criterion for builtins to be safe to execute in the same process in optimized command substitution from a blacklist of only cd, . and eval to a whitelist. This avoids clobbering the main shell environment such as by $(exit 4) and $(set -x). The builtins jobid, jobs, times and trap can still show information not available in a child process; this is deliberately permitted. (Changing traps is not.) For some builtins, whether they are safe depends on the arguments passed to them. Some of these are always considered unsafe to keep things simple; this only harms efficiency a little in the rare case they are used alone in a command substitution.
* sh: Properly restore exception handler in fc.jilles2010-12-291-1/+2
| | | | | | | | | | | If SIGINT arrived at exactly the right moment (unlikely), an exception handler in a no longer active stack frame would be called. Because the old handler was not used in the normal path, clang thought it was a dead value and if an exception happened it would longjmp() to garbage. This caused builtins/fc1.0 to fail if histedit.c was compiled with clang. MFC after: 1 week
* sh: Don't do optimized command substitution if expansions have side effects.jilles2010-12-283-1/+88
| | | | | | | | | | | | | | | | | | | | | | | | | Before considering to execute a command substitution in the same process, check if any of the expansions may have a side effect; if so, execute it in a new process just like happens if it is not a single simple command. Although the check happens at run time, it is a static check that does not depend on current state. It is triggered by: - expanding $! (which may cause the job to be remembered) - ${var=value} default value assignment - assignment operators in arithmetic - parameter substitutions in arithmetic except ${#param}, $$, $# and $? - command substitutions in arithmetic This means that $((v+1)) does not prevent optimized command substitution, whereas $(($v+1)) does, because $v might expand to something containing assignment operators. Scripts should not depend on these exact details for correctness. It is also imaginable to have the shell fork if and when a side effect is encountered or to create a new temporary namespace for variables. Due to the $! change, the construct $(jobs $!) no longer works. The value of $! should be stored in a variable outside command substitution first.
* sh: Make expansion errors in optimized command substitution non-fatal.jilles2010-12-281-1/+15
| | | | | | Command substitutions consisting of a single simple command are executed in the main shell process but this should be invisible apart from performance and very few exceptions such as $(trap).
* sh: Simplify "stack string" code slightly.jilles2010-12-272-26/+17
| | | | | | | Maintain a pointer to the end of the stack string area instead of how much space is left. This simplifies the macros in memalloc.h. The places where the new variable must be updated are only where the memory area is created, destroyed or resized.
* sh: Fix integer overflow check, it checked an uninitialized variable.jilles2010-12-261-1/+1
|
* sh: Allow arbitrary large numbers in CHECKSTRSPACE.jilles2010-12-265-25/+30
| | | | | | Reduce "stack string" API somewhat and simplify code. Add a check for integer overflow of the "stack string" length (probably incomplete).
* sh(1): Explain why it is a bad idea to use aliases in scripts.jilles2010-12-211-3/+4
|
* sh: Add kill builtin.jilles2010-12-217-13/+55
| | | | | | | | | | | | | | | | | This allows specifying a %job (which is equivalent to the corresponding process group). Additionally, it improves reliability of kill from sh in high-load situations and ensures "kill" finds the correct utility regardless of PATH, as required by POSIX (unless the undocumented %builtin mechanism is used). Side effect: fatal errors (any error other than kill(2) failure) now return exit status 2 instead of 1. (This is consistent with other sh builtins, but not in NetBSD.) Code size increases about 1K on i386. Obtained from: NetBSD
* sh: Add a function to print warnings (with command name and newline).jilles2010-12-216-14/+27
| | | | | | This is like error() but without raising an exception. It is particularly useful as a replacement for the warnx macro in bltin/bltin.h.
* sh: Make warnings in the printf builtin non-fatal, like in the program.jilles2010-12-201-15/+6
| | | | | | | | The #define for warnx now behaves much like the libc function (except that it uses sh command name and output). Also, it now uses C99 __VA_ARGS__ so there is no need for three different macros for 0, 1 or 2 parameters.
* sh: arith: Disallow decimal constants starting with 0 (containing 8 or 9).jilles2010-12-181-2/+2
| | | | | | | | | Constants in arithmetic starting with 0 should be octal only. This avoids the following highly puzzling result: $ echo $((018-017)) 3 by making it an error instead.
* Remove dead code.uqs2010-12-181-2/+0
| | | | | | | | c is assigned 0 and *loc is pointing to NULL, so c!=0 cannot be true, and dereferencing loc would be a bad idea anyway. Coverity Prevent: CID 5113 Reviewed by: jilles
* sh: Fix corruption of command substitutions with special chars after newlinejilles2010-12-161-2/+2
| | | | | | | | The CTLESC byte to protect a special character was output before instead of after a newline directly preceding the special character. The special handling of newlines is because command substitutions discard all trailing newlines.
* Remove duplicate check, turning dead code into live code.uqs2010-12-131-2/+0
| | | | | Coverity CID: 5114 Reviewed by: jilles
* sh: Various simplifications to jobs.c:jilles2010-12-121-11/+5
| | | | | | | | * Prefer kill(-X) to killpg(X). * Remove some dead code. * No additional SIGINT is needed if int_pending() is already true. No functional change is intended.
* sh: Remove the herefd hack.jilles2010-12-123-15/+0
| | | | | | | | | | | | | | | | | | The herefd hack wrote out partial here documents while expanding them. It seems unnecessary complication given that other expansions just allocate memory. It causes bugs because the stack is also used for intermediate results such as arithmetic expressions. Such places should disable herefd for the duration but not all of them do, and I prefer removing the need for disabling herefd to disabling it everywhere needed. Here documents larger than 1024 bytes will use a bit more CPU time and memory. Additionally this allows a later change to expand here documents in the current shell environment. (This is faster for small here documents but also changes behaviour.) Obtained from: dash
* sh: Replace some macros and repeated code in expand.c with functions.jilles2010-12-111-31/+32
| | | | | No functional change is intended, but the binary is about 1K smaller on i386.
* sh: Use vsnprintf() rather than crafting our own in fmtstr().jilles2010-12-111-18/+5
| | | | | Add INTOFF/INTON as longjmp out of vsnprintf may cause memory leaks or undefined behaviour.
* sh: Improve internal-representation-to-text code to avoid binary output.jilles2010-12-061-3/+36
| | | | | | | | | | | The code to translate the internal representation to text did not know about various additions to the internal representation since the original ash and therefore wrote binary stuff to the terminal. The code is used in the jobs command and similar output. Note that the output is far from complete and mostly serves for recognition purposes.
* sh: POSIX says there should not be a space between Done and (exitstatus).jilles2010-12-051-1/+1
| | | | (On the other hand, (core dumped) does need a space and so does [1] +.)
* sh: Improve jobs output of pipelines.jilles2010-12-051-66/+83
| | | | | | | | | | | | | | If describing the status of a pipeline, write all elements of the pipeline and show the status of the last process (which would also end up in $?). Only write one report per job, not one for every process that exits. To keep some earlier behaviour, if any process started by the shell in a foreground job terminates because of a signal, write a message about the signal (at most one message per job, however). Also, do not write messages about signals in the wait builtin in non-interactive shells. Only true foreground jobs now write such messages (for example, "Terminated").
* sh: Avoid marking a job as done before it is fully created.jilles2010-12-051-2/+2
| | | | | | | | | In r208489, I added code to reap zombies when forking new processes, to limit the amount of zombies. However, this can lead to marking a job as done or stopped if it consists of multiple processes and the first process ends very quickly. Fix this by only checking for zombies before forking the first process of a job and not marking any jobs without processes as done or stopped.
* sh: jobs -p: Do not ask the kernel for the pgid.jilles2010-12-051-4/+1
| | | | | | | | The getpgid() call will fail if the first process in the job has already terminated, resulting in output of "-1". The pgid of a job is always the pid of the first process in the job and other code already relies on this.
* Move most of the remaining USD/PSD/SMM papers into share/docuqs2010-12-047-4985/+0
|
* sh(1): Clean up documentation of built-in commands.jilles2010-12-031-11/+14
| | | | | | | Make sure all built-in commands are in the subsection named such, except exp, let and wordexp which are deliberately undocumented. The text said only built-ins that really need to be a built-in were documented there but in fact almost all of them were already documented.
* sh(1): Document that command's -p option also works with -v/-V.jilles2010-12-011-2/+3
| | | | This was implemented in r201343.
* sh: Code size optimizations to "stack string" memory allocation:jilles2010-11-238-33/+47
| | | | | | | | * Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC. * Add STPUTS macro (based on function) and use it instead of loops that add nul-terminated strings to the stack string. No functional change is intended, but code size is about 1K less on i386.
* sh: Pass multiple bytes at a time to lex.jilles2010-11-231-1/+9
| | | | This speeds up the expansion/arith6.0 test considerably.
* sh: Fix confusing behaviour if chdir succeeded but getcwd failed in cd -P.jilles2010-11-221-2/+5
| | | | | | If getcwd fails, do not treat this as an error, but print a warning and unset PWD. This is similar to the behaviour when starting the shell in a directory whose name cannot be determined.
* Fix some more warnings found by clang.brucec2010-11-221-0/+1
|
* sh: Remove the check that alpha/name/in_name chars are not CTL* bytes.jilles2010-11-201-3/+3
| | | | | | | | Since is_alpha/is_name/is_in_name were made ASCII-only, this can no longer happen. Additionally, the check was wrong because it did not include the new CTLQUOTEEND.
* sh: Code size optimizations to buffered output.jilles2010-11-207-34/+39
| | | | | | This is mainly less use of the outc macro. No functional change is intended, but code size is about 2K less on i386.
* sh: Add printf builtin.jilles2010-11-193-4/+9
| | | | | | | | | | | | | | | | | This was removed in 2001 but I think it is appropriate to add it back: * I do not want to encourage people to write fragile and non-portable echo commands by making printf much slower than echo. * Recent versions of Autoconf use it a lot. * Almost no software still wants to support systems that do not have printf(1) at all. * In many other shells printf is already a builtin. Side effect: printf is now always the builtin version (which behaves identically to /usr/bin/printf) and cannot be overridden via PATH (except via the undocumented %builtin mechanism). Code size increases about 5K on i386. Embedded folks might want to replace /usr/bin/printf with a hard link to /usr/bin/alias.
* sh: Add binary buffered output for use by the printf builtin.jilles2010-11-143-10/+16
|
* sh: Update the suspend example for the change of the job control flagjilles2010-11-131-1/+1
| | | | | | from -j to -m, many years ago. Due to r215266, this function now actually works.
* sh: Do the additional actions if 'local -' restore changes -i/-m/-E/-V.jilles2010-11-131-0/+1
| | | | | | | Example: f() { local -; set +m; }; f caused failure to execute external programs because the job control tty fd was not opened.
* echo(1): Clarify portability and mention literal "--" handling.jilles2010-11-121-9/+22
| | | | MFC after: 1 week
* sh(1): Document r214304 (special builtin is illegal function name).jilles2010-11-121-0/+1
|
* sh(1): Update for r214492. "${v+"hi}there"}".jilles2010-11-121-5/+8
| | | | | The part hi}there is not a quoted string but nevertheless the closing brace does not terminate the expansion.
* sh: Remove unused man page for echo builtin.jilles2010-11-121-114/+0
| | | | | | | | | | | | | The information in sh(1) about the echo builtin is equivalent, though less extensive. The echo(1) man page (bin/echo/echo.1) is different. Unfortunately, sh's echo builtin and /bin/echo have gone out of sync and this probably cannot be fixed any more. Reported by: uqs (list of untouched files) MFC after: 1 week
* sh(1): Modernize the introduction a bit.jilles2010-11-121-12/+5
| | | | | | In particular, remove the text about ksh-like features, which are usually taken for granted nowadays. The original Bourne shell is fading away and for most users our /bin/sh is one of the most minimalistic they know.
* test: Move tests to tools/regression/bin/test.jilles2010-11-083-353/+0
| | | | | | | | | Convert the tests to the perl prove format. Remove obsolete TEST.README (results of an old TEST.sh for some old Unices) and TEST.csh (old tests without correct values, far less complete than TEST.sh). MFC after: 1 week
* sh: Fix some issues with aliases and case, by importing dash checkkwd code.jilles2010-11-021-50/+49
| | | | | | | | | | | This moves the function of the noaliases variable into the checkkwd variable. This way it is properly reset on errors and aliases can be used normally in the commands for each case (the case labels recognize the keyword esac but no aliases). The new code is clearer as well. Obtained from: dash
* Add a new libc function: cfmakesane(3).ed2010-11-021-5/+6
| | | | | | | | | | | I've noticed various terminal emulators that need to obtain a sane default termios structure use very complex `hacks'. Even though POSIX doesn't provide any functionality for this, extend our termios API with cfmakesane(3), which is similar to the commonly supported cfmakeraw(3), except that it fills the termios structure with sane defaults. Change all code in our base system to use this function, instead of depending on <sys/ttydefaults.h> to provide TTYDEF_*.
* sh(1): Correct synopsis and make precise how $0 is set.jilles2010-10-311-4/+24
| | | | | | In particular, the extra argument to set $0 with -c was not documented. MFC after: 1 week
OpenPOWER on IntegriCloud