summaryrefslogtreecommitdiffstats
path: root/bin/sh
Commit message (Collapse)AuthorAgeFilesLines
* sh: Make return return from the closest function or dot script.jilles2013-09-044-15/+10
| | | | | | | | | | | | | Formerly, return always returned from a function if it was called from a function, even if there was a closer dot script. This was for compatibility with the Bourne shell which only allowed returning from functions. Other modern shells and POSIX return from the function or the dot script, whichever is closest. Git 1.8.4's rebase --continue depends on the POSIX behaviour. Reported by: Christoph Mallon, avg
* sh: Fix race condition with signals and wait or set -T.jilles2013-09-024-31/+20
| | | | | | | | | | The change in r238888 was incomplete. It was still possible for a trapped signal to arrive before the shell went to sleep (sigsuspend()) because a check was missing or because the signal arrived before in_waitcmd was set. On SMP, this bug sometimes caused the builtins/wait4.0 test to take 1 second to execute; it then might or might not fail. On UP, the test almost always failed.
* sh: Simplify list() in the parser.jilles2013-08-301-21/+22
| | | | | | The erflag argument was only used by old-style (``) command substitutions. We can remove it and handle the special case in the command substitution code.
* sh: Separate out nbinary allocation into a function.jilles2013-08-301-21/+22
|
* sh: Use makename() where possible.jilles2013-08-301-22/+5
|
* sh: Add a function for the case where one token is required in the parse.jilles2013-08-301-31/+23
|
* sh: Recognize "--" as end of options in type builtin.jilles2013-08-301-0/+2
| | | | | This implementation makes minimal changes: command names starting with "-" (other than "--") can still be queried normally.
* sh: Cast -1 to pointer rather than pointer to variable of wrong type.jilles2013-08-302-5/+3
| | | | | | | | | | NEOF needs to be a non-null pointer distinct from valid union node pointers. It is not dereferenced. The new NEOF is much like SIG_ERR except that it is an object pointer instead of a function pointer. The variable tokpushback can now be static.
* sh: Recognize "--" as end of options in alias builtin.jilles2013-08-251-3/+5
| | | | | Aliases starting with "-" (which are non-POSIX) will need to be preceded by an alias not starting with "-" or the newly added "--".
* sh: Disallow empty simple commands.jilles2013-08-251-8/+4
| | | | | | | | | | As per POSIX, a simple command must have at least one redirection, assignment word or command word. These occured in rare cases such as eval "f()" . The extension of allowing no commands inside { }, if, while, for, etc. remains.
* sh: Reject ++ and -- in arithmetic.jilles2013-08-241-0/+4
| | | | | | | | | | POSIX does not require ++ and -- in arithmetic. It is probably more useful to reject them than to treat ++x and --x as x silently. Note that the behaviour of increment and decrement can be obtained via (x+=1), ((x+=1)-1), (x-=1) and ((x-=1)+1). PR: bin/176444
* sh: Do not prematurely discard stopped jobs in a wait builtin.jilles2013-08-241-5/+1
| | | | | | | | | | | | | If a job is specified to 'wait', wait for it to complete. Formerly, in interactive mode, the job was deleted if it stopped. If no jobs are specified in interactive mode, 'wait' still waits for all jobs to complete or stop. In non-interactive mode, WUNTRACED is not passed to wait3() so stopped jobs are not detected. PR: bin/181435
* sh: Remove unnecessary reset functions.jilles2013-08-166-25/+1
| | | | These are already handled by exception handlers.
* sh: Recognize "--" as end of options in bg/fg/jobid builtins.jilles2013-08-161-6/+9
|
* sh: Recognize "--" as end of options in local builtin.jilles2013-08-141-0/+1
|
* sh: Allow a lone redirection before '|', ';;' or ';&'.jilles2013-08-141-0/+3
| | | | | | | Example: </dev/null | : PR: 181240 MFC after: 1 week
* sh: Remove an incorrect comment.jilles2013-07-251-1/+1
|
* sh: Remove #define MKINIT.jilles2013-07-257-11/+9
| | | | MKINIT only served for the removed mkinit. Many variables can be static now.
* sh: Remove mkinit.jilles2013-07-2514-576/+32
| | | | | | | | | | | | | | Replace the RESET blocks with regular functions and a reset() function that calls them all. This code generation tool is unusual and does not appear to provide much benefit. I do not think isolating the knowledge about which modules need to be reset is worth an almost 500-line build tool and wider scope for variables used by the reset functions. Also, relying on reset functions is often wrong: the cleanup should be done in exception handlers so that no stale state remains after 'command eval' and the like.
* sh: Remove output.c's reset() handler.jilles2013-07-251-19/+0
| | | | | These cleanup operations are not needed because they are already performed after an optimized command substitution (whether there was an error or not).
* sh: Do not read from stdin if an error occurs during -i -c cmd.jilles2013-07-121-1/+1
| | | | | | | | | | | | Although using -i with -c does not seem very useful, it seems inappropriate to read commands from the terminal in this case. Side effect: if the -s -c extension is used and the -s option is turned off using 'set +s' during the interactive part, the shell now exits after an error or interrupt. Note that POSIX only specifies -s as option to sh, not to set. See also Austin Group issue #718.
* sh: Do not close(-1) if pipe() fails.jilles2013-06-281-1/+2
|
* sh(1): A subshell environment has its own rlimits (ulimit).jilles2013-06-141-1/+4
| | | | | | This has always been the case and is intended (just like cd). This matches Austin group issue #706.
* sh(1): Document new features in wait builtin.jilles2013-06-051-4/+9
| | | | PR: 176916
* sh: Return status 127 for unknown jobs in wait builtin.jilles2013-06-051-5/+19
| | | | | | | | | | This is required by POSIX, at least for pids that are not known child processes. Other problems with job specifications still cause wait to abort with exit status 2. PR: 176916
* sh: Allow multiple operands in wait builtin.jilles2013-06-051-6/+18
| | | | | | | | This is only part of the PR; the behaviour for unknown/invalid pids/jobs remains unchanged (aborts the builtin with status 2). PR: 176916 Submitted by: Vadim Goncharov
* 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
OpenPOWER on IntegriCloud