summaryrefslogtreecommitdiffstats
path: root/bin/sh
Commit message (Collapse)AuthorAgeFilesLines
* sh: Remove an unused variable.jilles2012-11-142-2/+0
|
* sh: Forward-declare struct alias instead of giving up type safety via void *jilles2012-11-112-4/+5
|
* sh: Fix two issues when an alias is redefined:jilles2012-11-081-0/+11
| | | | | | | | | | | | | * The last character is not displayed. * If the alias ends with itself (as a word), an infinite memory-eating loop occurs. If an alias is defined initially, a space is appended to avoid recursion but this did not happen when an alias was later modified. PR: bin/173418 Submitted by: Daniel F. MFC after: 1 week
* sh: Change cmdtype in tblentry from short to signed char.jilles2012-11-051-1/+1
| | | | | If this is a smaller type than int anyway, we can make it the smallest possible.
* sh: Use C99 flexible array instead of accessing array beyond bounds.jilles2012-11-031-3/+2
| | | | | | | | Although sufficient memory is available for a longer string in cmdname, this is undefined behaviour anyway. Side effect: for alignment reasons, an additional byte of memory is allocated per hashed command.
* mdoc: don't nest displays. The markup here isn't adding anything anyway.joel2012-10-141-2/+2
| | | | | | Fixes a mandoc lint warning. Discussed with: brueffer, Jason McIntyre <jmc@kerhand.co.uk>
* sh: Prefer internal nextopt() to libc getopt().jilles2012-09-155-83/+37
| | | | | | | | | This reduces code duplication and code size. /usr/bin/printf is not affected. Side effect: different error messages when certain builtins are passed invalid options.
* sh: Reduce code duplication: use setinputfile instead of open/setinputfdjilles2012-09-141-8/+1
| | | | | | combination. MFC after: 2 weeks
* Minor mdoc fix.joel2012-09-111-1/+2
|
* sh: Remove XXX comment about removing nextopt().jilles2012-09-081-4/+0
| | | | | Using nextopt() avoids depending on the BSD-specific optreset feature in getopt() and reduces code size (both source and binary).
* sh: Fix EINTR race condition in "wait" and "set -T" using sigsuspend().jilles2012-07-293-4/+49
| | | | | | | | | | | | | | | | | When waiting for child processes using "wait" or if "set -T" is in effect, a signal interrupts the wait. Make sure there is no window where the signal handler may be invoked (setting a flag) just before going to sleep. There is a similar race condition in the shell language, but scripts can avoid it by exiting from the trap handler or enforcing synchronization using a fifo. If SIGCHLD is not trapped, a signal handler must be installed for it. Only install this handler for the duration of the wait to avoid triggering unexpected [EINTR] errors elsewhere. Note that for some reason only SIGINT and SIGQUIT interrupt a "wait" command. This remains the case.
* sh: Do not ask for stopped/continued processes if we do not need themjilles2012-07-281-6/+5
| | | | rather than retrying wait3 if they happen.
* sh: Inline waitproc() into its only caller.jilles2012-07-281-22/+9
|
* sh: Track continued jobs (even if not continued by bg or fg).jilles2012-07-281-3/+8
| | | | | | | This uses wait3's WCONTINUED flag. There is no message for this. The change is visible in "jobs" or if the job stops again.
* sh: Reset pendingsigs before checking pending traps, not after.jilles2012-07-151-1/+1
| | | | | Otherwise, a signal arriving at exactly the right moment might not be processed until another signal arrived.
* sh: Remove unused variable in_dowait.jilles2012-07-152-4/+0
|
* sh: Expand assignment-like words specially for export/readonly/local.jilles2012-07-154-4/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | Examples: export x=~ now expands the tilde local y=$1 is now safe, even if $1 contains IFS characters or metacharacters. For a word to "look like an assignment", it must start with a name followed by an equals sign, none of which may be quoted. The special treatment applies when the first word (potentially after "command") is "export", "readonly" or "local". There may be quoting characters but no expansions. If "local" is overridden with a function there is no special treatment ("export" and "readonly" cannot be overridden with a function). If things like local arr=(1 2 3) are ever allowed in the future, they cannot call a "local" function. This would either be a run-time error or it would call the builtin. This matches Austin Group bug #351, planned for the next issue of POSIX.1. PR: bin/166771
* Merge libedit adjustment from NetBSD.pfg2012-07-111-1/+1
| | | | | | | | | | | | | On recent versions of NetBSD's libedit, el_gets now sets el_len to -1 on error so we can distinguish between a NULL string and an error. This fixes sh from exiting with newer versions of libedit now allowing EINTR to return. Obtained from: NetBSD Reviewed by: jilles MFC after: 3 weeks
* Work better with how make/bmake works:marcel2012-05-242-9/+9
| | | | | | | | | | | | 1. Avoid a cd back into ${.CURDIR} to run mkbuiltins when we know make will first cd into ${.OBJDIR}. Keep the cwd to what make sets it to. 2. Don't tell mkbuiltins where to write to (= ${.OBJDIR}), but where to get sources from (= ${.CURDIR}). This to compensate for point 1. This fixes a problem with bmake's mk files that optimize ${.OBJDIR} to expand to "." after changing cwd, not taking into account that the target is pretty much undoing that and not getting the full path to the object tree anymore.
* sh: Remove an unused header.jilles2012-05-151-1/+0
| | | | The read builtin no longer does things with termios.
* Minor mdoc nits.joel2012-05-131-2/+2
|
* mdoc: fix column names, indentation, column separation within each row, andjoel2012-04-071-1/+1
| | | | | | | quotation. Also make sure we have the same amount of columns in each row as the number of columns we specify in the head arguments. Reviewed by: brueffer
* sh: Fix build with -DDEBUG=2.jilles2012-04-021-2/+2
| | | | | Reported by: Kristof Provost MFC after: 1 week
* Remove trailing whitespace per mdoc lint warningeadler2012-03-291-1/+1
| | | | | | | Disussed with: gavin No objection from: doc Approved by: joel MFC after: 3 days
* Remove superfluous paragraph macro.joel2012-03-251-1/+0
|
* sh: Make 'hash' return 1 if at least one utility is not found.jilles2012-02-111-8/+12
| | | | Reported by: lme
* sh: Fix swapped INTON/INTOFF.jilles2012-02-041-2/+2
| | | | | | | A possible consequence of this bug was a memory leak if SIGINT arrived during a 'set' command (listing variables). MFC after: 1 week
* sh: Use vfork in a few common cases.jilles2012-02-045-0/+64
| | | | | | | | | | | | | | | | | This uses vfork() for simple commands and command substitutions containing a single simple command, invoking an external program under certain conditions (no redirections or variable assignments, non-interactive shell, no job control). These restrictions limit the amount of code executed in a vforked child. There is a large speedup (for example 35%) in microbenchmarks. The difference in buildkernel is smaller (for example 0.5%) but still statistically significant. See http://lists.freebsd.org/pipermail/freebsd-hackers/2012-January/037581.html for some numbers. The use of vfork() can be disabled by setting a variable named SH_DISABLE_VFORK.
* Add prototypes, ANSIfy functions definitions to reduce WARNS=6 output.charnier2012-01-255-5/+6
|
* sh: Fix $? in the first command of a 'for'.jilles2012-01-221-1/+4
| | | | | | In the first command of a 'for', $? should be the exit status of the last pipeline (command substitution in the word list or command before 'for'), not always 0.
* sh: Remove "kill" example function, which is superseded by the kill builtinjilles2012-01-211-49/+0
| | | | MFC after: 1 week
* sh: Fix execution of multiple statements in a trap when evalskip is setdumbbell2012-01-163-2/+34
| | | | | | | | | | | Before this fix, only the first statement of the trap was executed if evalskip was set. This is for example the case when: o "-e" is set for this shell o a trap is set on EXIT o a function returns 1 and causes the script to abort Reviewed by: jilles MFC after: 2 weeks
* sh: Fix some bugs with exit status from case containing ;&.jilles2012-01-151-9/+24
| | | | | | | | | | | | | Also, rework evalcase() to not evaluate any tree. Instead, return the NCLISTFALLTHRU node and handle it in evaltree(). Fixed bugs: * If a ;& list with non-zero exit status is followed by an empty ;; or final list, the exit status of the case command should be equal to the exit status of the ;& list, not 0. * An empty ;& case should not reset $?.
* sh: Fix two bugs with case and exit status:jilles2012-01-151-1/+3
| | | | | | | * If no pattern is matched, POSIX says the exit status shall be 0 (even if there are command substitutions). * If a pattern is matched and there are no command substitutions, the first command should see the $? from before the case command, not always 0.
* sh: Change input buffer size from 1023 to 1024.jilles2012-01-141-6/+6
| | | | PR: bin/161756
* sh: Fix out of bounds array access when trap is used with an invalid signal.jilles2012-01-141-2/+2
| | | | MFC after: 1 week
* sh: Properly show "Not a directory" error in cd builtin.jilles2012-01-131-1/+6
| | | | | | | | The errno message display added in r222292 did not take attempting to cd to a non-directory or something that cannot be stat()ed into account. PR: bin/164070 MFC after: 10 days
* sh: Make various functions static.jilles2012-01-0110-12/+12
|
* sh: Remove unused function scopyn().jilles2012-01-012-20/+0
|
* sh: Make patmatch() non-recursive.jilles2012-01-011-37/+58
|
* sh: Allow quoting ^ and ] in bracket expressions.jilles2011-12-281-4/+4
|
* sh: Use dirent.d_type in pathname generation.jilles2011-12-281-0/+4
| | | | | | This improves performance for globs where a slash or another component follows a component with metacharacters by eliminating unnecessary attempts to open directories that are not.
* sh: Cache de->d_namlen in a local variable.jilles2011-12-281-6/+8
|
* sh: Do not force special builtins non-special in optimized command subst.jilles2011-12-281-2/+1
| | | | | | | | | This is not necessary: errors are already caught in evalbackcmd() and forcelocal handles changes to variables. Note that this depends on r223024. MFC after: 4 weeks
* sh: Remove impossible evalskip check in 'for'.jilles2011-11-271-3/+0
|
* sh: Reduce one level of evaltree() recursion when executing 'case'.jilles2011-11-261-11/+9
| | | | | | | Free expanded case text before executing commands. Remove impossible evalskip checks (expanding an argument cannot set evalskip anymore since $(break) and the like are properly executed in a subshell environment).
* sh: Allow unsetting OPTIND.jilles2011-11-201-2/+3
| | | | Note that only assigning the decimal value 1 resets getopts, as before.
* sh: Remove undefined behaviour due to overflow in +/-/* in arithmetic.jilles2011-11-081-3/+3
| | | | With i386 base gcc and i386 base clang, arith_yacc.o remains unchanged.
* sh(1): Improve documentation of field splitting.jilles2011-11-051-11/+55
|
* sh(1): Extend documentation about subshells.jilles2011-07-101-8/+46
| | | | | | | | | | | Because sh executes commands in subshell environments without forking in more and more cases (particularly from 8.0 on), it makes sense to describe subshell environments more precisely using ideas from POSIX, together with some FreeBSD-specific items. In particular, the hash and times builtins may not behave as if their state is copied for a subshell environment while leaving the parent shell environment unchanged.
OpenPOWER on IntegriCloud