aboutsummaryrefslogtreecommitdiff
path: root/bin
Commit message (Collapse)AuthorAgeFilesLines
* Add proper width calculation for time fields (time, cputime and usertime).Edward Tomasz Napierala2011-03-243-5/+52
| | | | | | | This fixes the ugly overflow in "ps aux" output for "[idle]". Notes: svn path=/head/; revision=219972
* Make "LOGIN" and "CLASS" columns width scale properly instead of wasting space.Edward Tomasz Napierala2011-03-243-5/+34
| | | | Notes: svn path=/head/; revision=219967
* sh(1): Describe subshell environment, command substitution more correctly.Jilles Tjoelker2011-03-201-7/+19
| | | | | | | | | | | | | | POSIX does not require the shell to fork for a subshell environment, and we use that possibility in various ways (command substitutions with a single command and most subshells that are the final command of a shell process). Therefore do not tie subshells to forking in the man page. Command substitutions with expansions are a bit strange, causing a fork for $(...$(($x))...) because $x might expand to y=2; they will probably be changed later but this is how they work now. Notes: svn path=/head/; revision=219806
* Implement the usertime and systime keywords for ps, printing theKonstantin Belousov2011-03-174-21/+63
| | | | | | | | | | corresponding times reported by getrusage(). Submitted by: Dan Nelson <dnelson allantgroup com> MFC after: 1 week Notes: svn path=/head/; revision=219713
* bin: Prefer strrchr() to rindex().Jilles Tjoelker2011-03-153-3/+3
| | | | | | | This removes the last index/rindex usage from /bin. Notes: svn path=/head/; revision=219680
* sh: Fix some parameter expansion variants ${#...}.Jilles Tjoelker2011-03-131-19/+30
| | | | | | | | | | | | These already worked: $# ${#} ${##} ${#-} ${#?} These now work as well: ${#+word} ${#-word} ${##word} ${#%word} There is an ambiguity in the standard with ${#?}: it could be the length of $? or it could be $# giving an error in the (impossible) case that it is not set. We continue to use the former interpretation as it seems more useful. Notes: svn path=/head/; revision=219623
* Remove unnecessary cast.Stefan Farfeleder2011-03-071-1/+1
| | | | | | | Reviewed by: jilles Notes: svn path=/head/; revision=219363
* sh(1): Reduce excessive semicolon-separated sentences.Jilles Tjoelker2011-03-061-4/+4
| | | | | | | Reported by: Benjamin Kaduk Notes: svn path=/head/; revision=219350
* Export login class information via kinfo and make it possible to viewEdward Tomasz Napierala2011-03-054-1/+28
| | | | | | | it using "ps -o class". Notes: svn path=/head/; revision=219307
* sh: Fix some warnings in code for arithmetic expressions.Jilles Tjoelker2011-03-052-3/+5
| | | | | | | Submitted by: eadler Notes: svn path=/head/; revision=219306
* kill: Note that this is used both as a normal program and a shell builtin.Jilles Tjoelker2011-03-011-0/+4
| | | | Notes: svn path=/head/; revision=219154
* Accept == as an alias of = which is a popular GNU extension.Xin LI2011-02-271-0/+1
| | | | | | | | | | This is intentionally undocumented for now since it's not part of any standard. MFC after: 1 month Notes: svn path=/head/; revision=219084
* When WITH_ICONV is set, use our in-tree iconv.Hajimu UMEMOTO2011-02-262-13/+23
| | | | Notes: svn path=/head/; revision=219061
* mdoc(7) markup.Sergey Kandaurov2011-02-211-1/+1
| | | | | | | | Approved by: avg (mentor), kib (mentor) MFC after: 3 days Notes: svn path=/head/; revision=218917
* Fix typos - remove duplicate "the".Rebecca Cran2011-02-212-2/+2
| | | | | | | | | PR: bin/154928 Submitted by: Eitan Adler <lists at eitanadler.com> MFC after: 3 days Notes: svn path=/head/; revision=218909
* test: Note that this is used both as a normal program and a shell builtin.Jilles Tjoelker2011-02-151-0/+4
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=218724
* sh: Detect dividing the smallest integer by -1.Jilles Tjoelker2011-02-122-0/+4
| | | | | | | | This overflows and on some architectures such as amd64 it generates SIGFPE. Generate an error on all architectures. Notes: svn path=/head/; revision=218626
* Fix typos.Rebecca Cran2011-02-121-2/+2
| | | | | | | | | PR: docs/131625 Submitted by: Andrew Wright <andrew at qemg.org> MFC after: 1 month Notes: svn path=/head/; revision=218619
* sh(1): Update description of arithmetic.Jilles Tjoelker2011-02-081-8/+3
| | | | Notes: svn path=/head/; revision=218467
* sh: Import arithmetic expression code from dash.Jilles Tjoelker2011-02-087-516/+716
| | | | | | | | | | | | | | | | | | | New features: * proper lazy evaluation of || and && * ?: ternary operator * executable is considerably smaller (8K on i386) because lex and yacc are no longer used Differences from dash: * arith_t instead of intmax_t * imaxdiv() not used * unset or null variables default to 0 * let/exp builtin (undocumented, will probably be removed later) Obtained from: dash Notes: svn path=/head/; revision=218466
* sh: Fix two things about {(...)} <redir:Jilles Tjoelker2011-02-051-1/+4
| | | | | | | | | | | * In {(...) <redir1;} <redir2, do not drop redir1. * Maintain the difference between (...) <redir and {(...)} <redir: In (...) <redir, the redirection is performed in the child, while in {(...)} <redir it should be performed in the parent (like {(...); :;} <redir) Notes: svn path=/head/; revision=218325
* sh: Remove clearcmdentry()'s now unused argument.Jilles Tjoelker2011-02-053-11/+10
| | | | Notes: svn path=/head/; revision=218324
* sh: Forget all cached command locations on any PATH change.Jilles Tjoelker2011-02-051-24/+1
| | | | | | | | | | | | POSIX requires this and it is simpler than the previous code that remembered command locations when appending directories to PATH. In particular, PATH=$PATH is no longer a no-op but discards all cached command locations. Notes: svn path=/head/; revision=218323
* sh: Do not try to execute binary files as scripts.Jilles Tjoelker2011-02-052-1/+16
| | | | | | | | | | | | | If execve() returns an [ENOEXEC] error, check if the file is binary before trying to execute it using sh. A file is considered binary if at least one of the first 256 bytes is '\0'. In particular, trying to execute ELF binaries for the wrong architecture now fails with an "Exec format error" message instead of syntax errors and potentially strange results. Notes: svn path=/head/; revision=218320
* sh: Remove special code for shell scripts without magic number.Jilles Tjoelker2011-02-0417-224/+27
| | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=218306
* Make sys_signame upper case.Jilles Tjoelker2011-02-043-5/+5
| | | | | | | | | | | | | | | This matches the constants from <signal.h> with 'SIG' removed, which POSIX requires kill and trap to accept and 'kill -l' to write. 'kill -l', 'trap', 'trap -l' output is now upper case. In Turkish locales, signal names with an upper case 'I' are now accepted, while signal names with a lower case 'i' are no longer accepted, and the output of 'killall -l' now contains proper capital 'I' without dot instead of a dotted capital 'I'. Notes: svn path=/head/; revision=218285
* sh: Return only 126 or 127 for execve() failures.Jilles Tjoelker2011-02-031-12/+5
| | | | | | | Do not return 2 for errors other than [EACCES] or [ENOENT]. Notes: svn path=/head/; revision=218242
* sh: Remove comment mentioning herefd, which is gone.Jilles Tjoelker2011-02-021-2/+1
| | | | Notes: svn path=/head/; revision=218203
* sh: Send messages about signals to stderr.Jilles Tjoelker2011-01-301-5/+5
| | | | | | | | | This is required by POSIX and seems to make more sense. See also r217557. Notes: svn path=/head/; revision=218105
* sh: Clean up some old comments:Jilles Tjoelker2011-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 Notes: svn path=/head/; revision=217847
* Document P_FOLLOWFORK.Konstantin Belousov2011-01-251-0/+1
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=217821
* sh: Fix signal messages being sent to the wrong file sometimes.Jilles Tjoelker2011-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 Notes: svn path=/head/; revision=217557
* sh(1): Document changes to 'exit' from traps.Jilles Tjoelker2011-01-161-2/+7
| | | | Notes: svn path=/head/; revision=217473
* sh: If exit is used without args from a trap action, exit on the signal.Jilles Tjoelker2011-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. Notes: svn path=/head/; revision=217472
* sh: Fix some things about -- in trap:Jilles Tjoelker2011-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. Notes: svn path=/head/; revision=217461
* sh: Make 'trap -l' look like 'kill -l'.Jilles Tjoelker2011-01-141-1/+1
| | | | Notes: svn path=/head/; revision=217425
* sh: Follow-up to r216743, grabstackblock() can be replaced with stalloc().Jilles Tjoelker2011-01-092-11/+1
| | | | | | | | grabstackblock() was used only once (but it is a very often executed piece of code). Notes: svn path=/head/; revision=217209
* sh: Remove special %builtin PATH entry.Jilles Tjoelker2011-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 Notes: svn path=/head/; revision=217206
* Move repeated MAXSLP definition from machine/vmparam.h to sys/vmmeter.h.Konstantin Belousov2011-01-091-0/+1
| | | | | | | | | | Update the outdated comments describing MAXSLP and the process selection algorithm for swap out. Comments wording and reviewed by: alc Notes: svn path=/head/; revision=217192
* sh: Make exit without parameters from EXIT trap POSIX-compliant.Jilles Tjoelker2011-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 $?'. Notes: svn path=/head/; revision=217175
* sh: Do not call exitshell() from evalcommand() unless evalcommand() forkedJilles Tjoelker2011-01-051-4/+5
| | | | | | | | | itself. This ensures that certain traps caused by builtins are executed. Notes: svn path=/head/; revision=217035
* Increase carried_error if we skip a file due to an error. This ensuresJaakko Heinonen2011-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 Notes: svn path=/head/; revision=216922
* sh: Check readonly status for assignments on regular builtins.Jilles Tjoelker2011-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 Notes: svn path=/head/; revision=216870
* sh: Check if dup2 for redirection from/to a file succeeds.Jilles Tjoelker2010-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<. Notes: svn path=/head/; revision=216851
* sh: Avoid side effects from builtins in optimized command substitution.Jilles Tjoelker2010-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. Notes: svn path=/head/; revision=216826
* sh: Properly restore exception handler in fc.Jilles Tjoelker2010-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 Notes: svn path=/head/; revision=216806
* sh: Don't do optimized command substitution if expansions have side effects.Jilles Tjoelker2010-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. Notes: svn path=/head/; revision=216778
* sh: Make expansion errors in optimized command substitution non-fatal.Jilles Tjoelker2010-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). Notes: svn path=/head/; revision=216761
* sh: Simplify "stack string" code slightly.Jilles Tjoelker2010-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. Notes: svn path=/head/; revision=216743
* sh: Fix integer overflow check, it checked an uninitialized variable.Jilles Tjoelker2010-12-261-1/+1
| | | | Notes: svn path=/head/; revision=216707