summaryrefslogtreecommitdiffstats
path: root/bin/sh
Commit message (Collapse)AuthorAgeFilesLines
* sh: Remove linked list of stack marks.jilles2013-05-112-18/+3
| | | | | | | | | | | | | | | | The linked list of stack marks may cause problems if the allocation stack is used between an exception and a higher-level popstackmark(), as it may then touch a stack mark that is local to a function which has returned. Also, the adjustment compares to a pointer passed to realloc(), which is undefined behaviour. Instead of adjusting stack marks when reallocating stack blocks, ensure that such an adjustment is never necessary by fixing a small piece of memory in place at a stack mark. This also simplifies the code. To avoid the problems reported in bin/175922, it remains necessary to call setstackmark() after popstackmark() if the stack mark remains in use.
* Fix two typoseadler2013-05-091-2/+2
| | | | Reviewed by: jilles
* sh: Use O_CLOEXEC and F_DUPFD_CLOEXEC instead of separate fcntl() call.jilles2013-05-054-17/+11
|
* sh: Improve error handling in read builtin:jilles2013-05-032-5/+29
| | | | | | | | | | | | * If read -t times out, return status as if interrupted by SIGALRM (formerly 1). * If a trapped signal interrupts read, return status 128+sig (formerly 1). * If [EINTR] occurs but there is no trap, retry the read (for example because of a SIGWINCH in interactive mode). * If a read error occurs, write an error message and return status 2. As before, a variable assignment error returns 2 and discards the remaining data read.
* sh: Don't consider jobs -s/-p as reporting the status of jobs.jilles2013-04-271-7/+9
| | | | | This ensures that something like j=$(jobs -p) does not prevent any status from being written to the terminal.
* Document a few expansions for the $PS1 and $PS2 environmental variables.joel2013-04-211-1/+25
| | | | | | PR: 173410 Submitted by: Derek Wood <ddwood@outlook.com> Reviewed by: jilles
* sh: Don't modify exit status when break/continue/return passes !.jilles2013-04-121-0/+2
| | | | | | | | This matches what would happen if ! P were to be replaced with if P; then false; else true; fi. Example: f() { ! return 0; }; f
* sh: Add const to nodesavestr().jilles2013-04-071-3/+3
|
* 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: Fix various compiler warnings.jilles2013-04-0111-32/+36
| | | | | | | It now passes WARNS=7 with clang on i386. GCC 4.2.1 does not understand setjmp() properly so will always trigger -Wuninitialized. I will not add the volatile keywords to suppress this.
* Minor mdoc fix.joel2013-03-291-1/+1
|
* sh(1): Mention possible ambiguities with $(( and ((.jilles2013-03-241-1/+14
| | | | | | | | | In some other shells, things like $((a);(b)) are command substitutions. Also, there are shells that have an extension ((ARITH)) that evaluates an arithmetic expression and returns status 1 if the result is zero, 0 otherwise. This extension may lead to ambiguity with two subshells starting in sequence.
* sh: Recognize "--" and explicitly reject options in wait builtin.jilles2013-03-151-3/+4
| | | | | | If syntactically invalid job identifiers are to be taken as jobs that exited with status 127, this should not apply to options, so that we can add options later if need be.
* sh: When executing a trap, keep exit status along with evalskip.jilles2013-03-031-2/+3
| | | | | | | This ensures 'return' in a trap returns the correct status to the caller. If evalskip is not set or if it is overridden by a previous evalskip, keep the old behaviour of restoring the exit status from before the trap.
* sh: If a SIGINT or SIGQUIT interrupts "wait", return status 128+sig.jilles2013-02-235-20/+23
|
* sh: Fix a crash with the stackmark code.jilles2013-02-191-0/+2
| | | | | | | | | | | | | | | | If a stack mark is set while the current stack block is empty, the stack block may move later on (because of realloc()) and the stack mark needs to be updated. This updating does not happen after popstackmark() has been called; therefore, call setstackmark() again if the stack mark is still being used. For some reason, this only affects a few users. I cannot reproduce it. The situation seems quite rare as well because an empty stack block would usually be freed (by popstackmark()) before execution reaches a setstackmark() call. PR: 175922 Tested by: KT Sin
* sh: Simplify mksyntax and make it fit for cross-compiling.jilles2013-02-071-88/+66
| | | | | | | | | | | | | | | | | | | | Now it outputs fixed files, which use constants provided by the C standard library to determine appropriate values for the target machine. Before, mksyntax inspected the host machine which resulted in subtle breakage if e.g. char is signed on the host and unsigned on the target such as when cross-compiling on x86 for ARM. Tested using -funsigned-char on amd64. Compiling build-tools without it and sh itself with it causes various tests to fail without this change but not with this change. With consistent -funsigned-char, tests pass with or without this change. The mksyntax program could be removed and syntax.c and syntax.h committed to the repository. Submitted by: Christoph Mallon MFC after: 2 weeks
* sh: Fix a comment.jilles2013-02-071-1/+1
|
* Catch TRACE parameters up with r238888. This change is only needed whendelphij2013-02-071-1/+1
| | | | debugging is enabled.
* sh: Do not test for digit_contig in mksyntax.jilles2013-02-051-46/+2
| | | | | | | | | ISO/IEC 9899:1999 (E) 5.2.1p3 guarantees that the values of the characters 0123456789 are contiguous. The generated syntax.c and syntax.h remain the same. Submitted by: Christoph Mallon
* sh: Expand here documents in the current process.jilles2013-02-035-24/+48
| | | | | | | | | | | | | | | | | 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: Prefer our character classification functions to <ctype.h>.jilles2013-01-312-3/+2
|
* sh: Show negated commands (!) in jobs output.jilles2013-01-311-0/+4
|
* Add FILES section.joel2013-01-221-2/+14
| | | | Discussed with: jilles
* Change the $ENV example to use .shrc instead of .shinit. This is consistentjoel2013-01-201-3/+3
| | | | | | with what we use in /usr/share/skel/dot.profile. Discussed with: jilles
* sh: Move some stackmarks to fix high memory usage in some loops.jilles2013-01-201-11/+5
| | | | | | | | | | | | If a loop contained certain commands (such as redirected compound commands), the temporary memory for the redirection was not freed between iterations of the loop but only after the loop. Put a stackmark in evaltree(), freeing memory whenever a node has been evaluated. Some other stackmarks are then redundant; remove them. Example: while :; do { :; } </dev/null; done
* sh: Remove mkinit's initialization routine.jilles2013-01-205-35/+12
| | | | Instead, call the only init function left directly from main().
* sh: Replace an mkinit use with an initialization.jilles2013-01-191-10/+5
|
* sh: Simplify cd-hash interaction.jilles2013-01-142-40/+15
| | | | | | | | Instead of rechecking relative paths for all hashed utilities after a cd, track if any utility in cmdtable depends on a relative path in PATH. If there is such a utility, cd clears the entire table. As a result, the '*' in hash no longer happens.
* sh: Pass $? to command substitution containing compound/multiple commands.jilles2013-01-141-2/+1
| | | | | Example: false; echo $(echo $?; :)
* sh: Fix crash when parsing '{ } &'.jilles2013-01-131-2/+2
| | | | MFC after: 1 week
* sh: Don't lose $? when backquoted command ends with semicolon or newline.jilles2013-01-131-1/+2
| | | | | | | | | An empty simple command was added and overwrote the exit status with 0. This affects `...` but not $(...). Example: v=`false;`; echo $?
* sh: Prefer strsignal() to accessing sys_siglist directly.jilles2012-12-251-8/+13
| | | | | | | | Accessing sys_siglist directly requires rtld to copy it from libc to the sh executable's BSS. Also, strsignal() will put in the signal number for unknown signals (FreeBSD-specific) so we need not do that ourselves. Unfortunately, there is no function for sys_signame.
* sh: Detect and flag write errors on stdout in builtins.jilles2012-12-123-0/+22
| | | | | | | If there is a write error on stdout, a message will be printed (to stderr) and the exit status will be changed to 2 if it would have been 0 or 1. PR: bin/158206
* 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
|
OpenPOWER on IntegriCloud