summaryrefslogtreecommitdiffstats
path: root/bin
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* sh: Add binary buffered output for use by the printf builtin.jilles2010-11-143-10/+16
|
* sh: Update the suspend example for the change of the job control flagjilles2010-11-131-1/+1
| | | | | | from -j to -m, many years ago. Due to r215266, this function now actually works.
* sh: Do the additional actions if 'local -' restore changes -i/-m/-E/-V.jilles2010-11-131-0/+1
| | | | | | | Example: f() { local -; set +m; }; f caused failure to execute external programs because the job control tty fd was not opened.
* echo(1): Clarify portability and mention literal "--" handling.jilles2010-11-121-9/+22
| | | | MFC after: 1 week
* sh(1): Document r214304 (special builtin is illegal function name).jilles2010-11-121-0/+1
|
* sh(1): Update for r214492. "${v+"hi}there"}".jilles2010-11-121-5/+8
| | | | | The part hi}there is not a quoted string but nevertheless the closing brace does not terminate the expansion.
* sh: Remove unused man page for echo builtin.jilles2010-11-121-114/+0
| | | | | | | | | | | | | The information in sh(1) about the echo builtin is equivalent, though less extensive. The echo(1) man page (bin/echo/echo.1) is different. Unfortunately, sh's echo builtin and /bin/echo have gone out of sync and this probably cannot be fixed any more. Reported by: uqs (list of untouched files) MFC after: 1 week
* sh(1): Modernize the introduction a bit.jilles2010-11-121-12/+5
| | | | | | In particular, remove the text about ksh-like features, which are usually taken for granted nowadays. The original Bourne shell is fading away and for most users our /bin/sh is one of the most minimalistic they know.
* test: Move tests to tools/regression/bin/test.jilles2010-11-083-353/+0
| | | | | | | | | Convert the tests to the perl prove format. Remove obsolete TEST.README (results of an old TEST.sh for some old Unices) and TEST.csh (old tests without correct values, far less complete than TEST.sh). MFC after: 1 week
* sh: Fix some issues with aliases and case, by importing dash checkkwd code.jilles2010-11-021-50/+49
| | | | | | | | | | | This moves the function of the noaliases variable into the checkkwd variable. This way it is properly reset on errors and aliases can be used normally in the commands for each case (the case labels recognize the keyword esac but no aliases). The new code is clearer as well. Obtained from: dash
* Add a new libc function: cfmakesane(3).ed2010-11-021-5/+6
| | | | | | | | | | | I've noticed various terminal emulators that need to obtain a sane default termios structure use very complex `hacks'. Even though POSIX doesn't provide any functionality for this, extend our termios API with cfmakesane(3), which is similar to the commonly supported cfmakeraw(3), except that it fills the termios structure with sane defaults. Change all code in our base system to use this function, instead of depending on <sys/ttydefaults.h> to provide TTYDEF_*.
* sh(1): Correct synopsis and make precise how $0 is set.jilles2010-10-311-4/+24
| | | | | | In particular, the extra argument to set $0 with -c was not documented. MFC after: 1 week
* Fix typo and grammar nituqs2010-10-311-2/+2
| | | | | Submitted by: arundel MFC after: 7 days (or when the bikeshed has abated)
* sh: Reindent evaltree().jilles2010-10-311-76/+76
|
* sh: Use iteration instead of recursion to evaluate semicolon lists.jilles2010-10-312-15/+27
| | | | | This reduces CPU and memory usage when executing long lists (such as long functions).
* Elaborate some more on the non-security implications of using -Puqs2010-10-311-6/+15
| | | | | Submitted by: delphij Discussion at: svn-src-all
* sh: Tweak some string constants to reduce code size.jilles2010-10-294-5/+5
| | | | | * Reduce some needless differences. * Shorten some error messages that should not happen.
* sh: Reject function names ending in one of !%*+-=?@}~jilles2010-10-291-1/+5
| | | | | | | | | These do something else in ksh: name=(...) is an array or compound variable assignment and the others are extended patterns. This is the last patch of the ones tested in the exp run. Exp-run done by: pav (with some other sh(1) changes)
* sh: Detect various additional errors in the parser.jilles2010-10-291-3/+3
| | | | | | | | | | | | | Apart from detecting breakage earlier or at all, this also fixes a segfault in the testsuite. The "handling" of the breakage left an invalid internal representation in some cases. Examples: echo a; do echo b echo `) echo a` echo `date; do do do` Exp-run done by: pav (with some other sh(1) changes)
OpenPOWER on IntegriCloud