Commit Graph

1129 Commits

Author SHA1 Message Date
bdrewery
8b002dd3b0 Allow overriding VTABSIZE at compile-time.
Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D14339
2018-02-13 16:48:57 +00:00
arichardson
20f24e68c5 Don't hardcode /usr/bin as the path for mktemp in build tools
It won't work e.g. when crossbuilding from Ubuntu Linux as mktemp is in
/bin there.

Reviewed By:	bdrewery
Approved By:	jhb (mentor)
Differential Revision: https://reviews.freebsd.org/D13937
2018-02-06 15:41:35 +00:00
jilles
12b427ef2f sh: Refactor job status printing, preparing for -o pipefail and similar
No functional change is intended.
2018-02-02 22:53:58 +00:00
jilles
af8bf1e796 sh: Move various structs from jobs.h to jobs.c
These implementation details of jobs.c need not be exposed.
2018-01-01 22:31:52 +00:00
eadler
48140559e0 Fix a few speelling errors
- man pages
- bin/sh

Reviewed by:		jilles
2017-12-28 08:22:26 +00:00
jilles
6f728e58bf sh: Don't leak wait* implementation details from jobs.c 2017-12-26 16:23:18 +00:00
jilles
e5bdf08b02 sh(1): Markup and spelling fixes 2017-12-23 22:58:19 +00:00
bjk
782597315d Fix mandoc -Tlint warnings in bin/
Many style-level issues are still reported.

Submitted by:	Yuri Pankov <yuripv@gmx.com>
Reviewed by:	jilles (previous revision)
Differential Revision:	https://reviews.freebsd.org/D13334
2017-12-07 01:57:27 +00:00
pfg
872b698bd4 General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
bdrewery
a598c4b809 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
bdrewery
a4164f0dcd DIRDEPS_BUILD: Connect new directories.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:04:07 +00:00
ngie
18951eee49 Add supporting changes for Add limited sandbox capability to "make check"
Non-tests/... changes:
- Add HAS_TESTS= to Makefiles with libraries and programs to enable iteration
  and propagate the appropriate environment down to *.test.mk.

tests/... changes:
- Add appropriate support Makefile.inc's to set HAS_TESTS in a minimal manner,
  since tests/... is a special subdirectory tree compared to the others.

MFC after:	2 months
MFC with:	r322511
Reviewed by:	arch (silence), testing (silence)
Differential Revision:	D12014
2017-08-14 19:21:37 +00:00
jilles
a80e2edd75 sh: Add test for sh -c with missing command string.
This already works correctly.
2017-08-13 14:36:10 +00:00
jilles
ef8ca7bad4 sh: Add tests for sh -c that already pass.
PR:		220587
Submitted by:	Ryan Moeller
2017-08-12 19:17:48 +00:00
ngie
734d081ed1 MFhead@r321912 2017-08-02 08:38:36 +00:00
ngie
d810089ddf Convert traditional ${MK_TESTS} conditional idiom for including test
directories to SUBDIR.${MK_TESTS} idiom

This is being done to pave the way for future work (and homogenity) in
^/projects/make-check-sandbox .

No functional change intended.

MFC after:	1 weeks
2017-08-02 08:35:51 +00:00
ngie
a871f00559 Add HAS_TESTS to all Makefiles that use the SUBDIR.${MK_TESTS}+= tests idiom 2017-08-02 08:14:06 +00:00
jilles
80a48cd3a3 sh: Remove broken #ifdef NOHACK code (related to sh -c).
Apart from the fact that subtle syntactic changes make a poor compile-time
option, the NOHACK case has been obviously broken since it was added,
because it uses q uninitialized if (*p != '\0').

No functional change is intended.
2017-07-18 19:00:15 +00:00
jilles
515d466527 sh: Ignore error when cd writes the directory actually switched to.
If CDPATH is used non-trivially or the operand is "-", cd writes the
directory actually switched to. (We currently do this only in interactive
shells, but POSIX requires this in non-interactive shells as well.)

As mentioned in Austin group bug #1045, cd shall not return an error while
leaving the current directory changed. Therefore, ignore any write error.
2017-06-25 21:53:08 +00:00
jilles
75a08b42cd sh: Enable interrupts before executing EXIT trap and doing final flush. 2017-06-11 16:54:04 +00:00
jilles
2659ecef3c sh: Call fc -e editor with interrupts enabled.
Starting the fc -e editor can execute arbitrary script, and executing
arbitrary script with INTOFF in effect may cause unexpected results.

This change (together with other changes) serves mainly to allow asserting
that INTOFF is not in effect when starting the evaluation of a node.
2017-06-06 21:08:05 +00:00
jilles
f04929ccc2 sh: Make sure to process SIGINT if SETINTON re-enables processing.
If INTON re-enables interrupts, it processes any interrupt that occurred
while interrupts were disabled. Make SETINTON do the same.
2017-06-04 21:58:02 +00:00
bdrewery
3d82bdb18a Allow defining nofork builtins from builtins.def and move always-safe ones there.
The generated code remains the same.

Reviewed by:	jilles
Differential Revision:	https://reviews.freebsd.org/D11042
2017-06-04 21:02:48 +00:00
jilles
6f57e08e8d sh: Fix INTOFF leak when a redirection on a compound command fails.
Reported by:	bdrewery
2017-06-04 20:52:55 +00:00
jilles
e222a7286a sh: Keep output buffer across builtins.
Allocating and deallocating repeatedly the 1024-byte buffer for stdout from
builtins costs CPU time for little or no benefit.

A simple loop containing builtins that write to a file descriptor, such as
  i=0; while [ "$i" -lt 1000000 ]; do printf .; i=$((i+1)); done >/dev/null
is over 10% faster in a simple benchmark on an amd64 virtual machine.
2017-05-18 22:10:04 +00:00
jilles
d6bd261071 sh: Ensure memout.bufsize matches allocated buffer, if it exists. 2017-05-18 21:44:14 +00:00
jilles
911d1cf0ac sh: Simplify output buffering.
Similarly to how STPUTC was changed, change struct output to store the
pointer just past the end of the available space instead of the size of the
available space, so after writing a character it is only necessary to
increment a pointer and not to decrement a counter.
2017-05-16 21:54:51 +00:00
jilles
a1b7b6531d sh: Fix '-' from quoted arithmetic in case/glob pattern range.
It does not make much sense to generate the '-' in a pattern bracket
expression using arithmetic expansion, but it does not make sense to forbid
it either.

Try to avoid reprocessing the string if it is unnecessary.
2017-05-14 13:14:19 +00:00
jilles
19a05788e4 sh: Add test for arithmetic expansion in [x-y] pattern range.
It does not make much sense to generate the '-' in a pattern bracket
expression using arithmetic expansion, but it does not make sense to forbid
it either.

This test already passes.
2017-05-13 20:28:32 +00:00
jilles
6c39df7f25 sh: Fix INTOFF leak after a builtin with different locale settings.
After executing a builtin with different locale settings such as
  LC_ALL=C true
SIGINT handling was left disabled indefinitely.

MFC after:	1 week
2017-05-07 19:49:46 +00:00
jilles
52d5b5df35 sh: Update TOUR and comments for some code changes, some of them old.
Also, improve some terminology in TOUR and comments.
2017-05-06 13:28:42 +00:00
jilles
64540667eb sh: Simplify handling of newlines in command substitution.
Unless we need to split on newlines, just append them as normal and remove
them at the end.
2017-04-28 16:16:22 +00:00
jilles
3205088b6f sh: Add some tests for command substitution final newline stripping. 2017-04-27 18:52:18 +00:00
jilles
ee31ad7631 sh: Add tests for NUL byte in command substitution output. 2017-04-23 21:58:17 +00:00
jilles
6f50e44dc0 sh: Simplify setinteractive().
setsignal() does nothing if the signal disposition is already set correctly.
2017-04-22 21:31:37 +00:00
jilles
21aa21c870 sh: Fix use after free when resetting an in-use alias.
The special case of modifying an existing alias does not work correctly if
the alias is currently in use. Instead, handle this case by unaliasing the
old alias (if any) and then creating a new alias.
2017-04-16 22:10:02 +00:00
jilles
715acb0045 sh: Link the new test to the build. 2017-04-16 21:57:25 +00:00
jilles
e005ca713c sh: Fix unalias -a while an alias is currently in use.
It is a rare situation to modify aliases while an alias is currently in use,
but this is handled for plain unalias. Handle it for unalias -a as well.
2017-04-16 21:42:43 +00:00
jilles
35ba17bacb sh: Reduce size of limits table. 2017-04-12 21:15:55 +00:00
jilles
ac0377de0b sh: Add test for unaliasing an alias that is currently in use.
This already works correctly.
2017-04-08 21:57:59 +00:00
jilles
bc32630dda sh: Remove an XXX comment: it is normal for builtins to use argptr. 2017-04-02 15:53:11 +00:00
jilles
5712a75a56 sh: Remove global state from collate_range_cmp().
The global state is not used across invocations of collate_range_cmp().
2017-04-02 14:02:10 +00:00
jilles
540b3bf7f6 sh: Don't scan word twice in ${param=word}. 2017-04-02 13:43:45 +00:00
jilles
79577b9fe5 sh: Don't scan word twice in ${param#%##%%word}.
If word is expanded, use the found end instead of iterating over the data
again.
2017-04-02 13:29:27 +00:00
jilles
460c4455d3 sh: Don't scan word twice in ${param+-word}.
There is no longer a case where argbackq has already been advanced but the
string pointer needs to be advanced.
2017-04-02 12:37:43 +00:00
jilles
363cf591af sh: Fix build with -DDEBUG=2.
With the new expansion code (word splitting during instead of after other
expansion processing), tracing the result of command substitution is no
longer possible, so stop trying.
2017-03-19 21:18:53 +00:00
jilles
a7b8e0f9c6 sh: Remove unused function declaration for arith_lex_reset().
Reported by:	Robert Elz
2017-03-18 20:41:07 +00:00
jilles
1f5642d40d sh: Remove unused return value of subevalvar_misc(). 2017-03-18 16:09:30 +00:00
jilles
3bc5005a4c sh: Get rid of global variable argbackq. 2017-03-16 21:53:55 +00:00
jilles
eab9784db4 sh: Fix executing wrong command with ${unsetvar#$(cmdsubst)}$(cmdsubst).
The parsed internal representation of words consists of a byte string with a
list of nodes (commands in command substitution). Each unescaped CTLBACKQ or
CTLBACKQ | CTLQUOTE byte corresponds to an entry in the list.

If param in ${param#%##%%word} is not set, the word is not expanded (in a
deviation of POSIX shared with other ash variants and ksh93). Erroneously,
the pointer in the list of commands (argbackq) was not advanced. This caused
the wrong command to be executed later if the outer word contained another
command substitution.

Example:
  echo "${unsetvar#$(echo a)}$(echo b)"
wrote "a" but should write "b".

MFC after:	1 week
2017-03-10 16:04:00 +00:00