summaryrefslogtreecommitdiffstats
path: root/bin
Commit message (Collapse)AuthorAgeFilesLines
* sh: Send messages about signals to stderr.jilles2011-01-301-5/+5
| | | | | | This is required by POSIX and seems to make more sense. See also r217557.
* sh: Clean up some old comments:jilles2011-01-251-6/+3
| | | | | | | | | * There is no plan for an alternative to the command "set". * Attempting to unset a readonly variable has not raised an error for quite a while, so the order of unsetting a variable and a function with the same name does not matter. MFC after: 1 week
* Document P_FOLLOWFORK.kib2011-01-251-0/+1
| | | | MFC after: 2 weeks
* sh: Fix signal messages being sent to the wrong file sometimes.jilles2011-01-181-0/+1
| | | | | | | | | | | | | When a foreground job exits on a signal, a message is printed to stdout about this. The buffer was not flushed after this which could result in the message being written to the wrong file if the next command was a builtin and had stdout redirected. Example: sh -c 'kill -9 $$'; : > foo; echo FOO:; cat foo Reported by: gcooper MFC after: 1 week
* sh(1): Document changes to 'exit' from traps.jilles2011-01-161-2/+7
|
* sh: If exit is used without args from a trap action, exit on the signal.jilles2011-01-161-4/+23
| | | | | | | | | | | | This is useful so that it is easier to exit on a signal than to reset the trap to default and resend the signal. It matches ksh93. POSIX says that 'exit' without args from a trap action uses the exit status from the last command before the trap, which is different from 'exit $?' and matches this if the previous command is assumed to have exited on the signal. If the signal is SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU, or if the default action for the signal is to ignore it, a normal _exit(2) is done with exit status 128+signal_number.
* sh: Fix some things about -- in trap:jilles2011-01-151-11/+14
| | | | | | | * Make 'trap --' do the same as 'trap' instead of nothing. * Make '--' stop option processing (note that '-' action is not an option). Side effect: The error message for an unknown option is different.
* sh: Make 'trap -l' look like 'kill -l'.jilles2011-01-141-1/+1
|
* sh: Follow-up to r216743, grabstackblock() can be replaced with stalloc().jilles2011-01-092-11/+1
| | | | | grabstackblock() was used only once (but it is a very often executed piece of code).
* sh: Remove special %builtin PATH entry.jilles2011-01-091-33/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | All builtins are now always found before a PATH search. Most ash derivatives have an undocumented feature where the presence of an entry "%builtin" in $PATH will cause builtins to be checked at that point of the PATH search, rather than before looking at any directories as documented in the man page (very old versions do document this feature). I am removing this feature from sh, as it complicates the code, may violate expectations (for example, /usr/bin/alias is very close to a forkbomb with PATH=/usr/bin:%builtin, only /usr/bin/builtin not being another link saves it) and appears to be unused (all the %builtin google code search finds is in some sort of ash source code). Note that aliases and functions took and take precedence above builtins. Because aliases work on a lexical level they can only ever be overridden on a lexical level (quoting or preceding 'builtin' or 'command'). Allowing override of functions via PATH does not really fit in the model of sh and it would work differently from %builtin if implemented. Note: POSIX says special builtins are found before functions. We comply to this because we do not allow functions with the same name as a special builtin. Silence from: freebsd-hackers@ (message sent 20101225) Discussed with: dougb
* Move repeated MAXSLP definition from machine/vmparam.h to sys/vmmeter.h.kib2011-01-091-0/+1
| | | | | | | Update the outdated comments describing MAXSLP and the process selection algorithm for swap out. Comments wording and reviewed by: alc
* sh: Make exit without parameters from EXIT trap POSIX-compliant.jilles2011-01-083-7/+19
| | | | | | | It should use the original exit status, just like falling off the end of the trap handler. Outside an EXIT trap, 'exit' is still equivalent to 'exit $?'.
* 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.
OpenPOWER on IntegriCloud