summaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
| * ash: expand: Use HOME in tilde expansion when it is emptyDenys Vlasenko2020-02-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Sun, 27 May 2018 17:31:57 +0800 expand: Use HOME in tilde expansion when it is empty Currently if HOME is set to empty tilde expansion will fail, i.e., it will remain as a literal tilde. This patch changes it to return the empty string as required by POSIX. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: builtin: Mark more regular built-insDenys Vlasenko2020-02-161-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Sat, 19 May 2018 02:39:49 +0800 builtin: Mark more regular built-ins This patch marks the following built-ins as regular, meaning that they cannot be overriden using PATH search: hash pwd type ulimit Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: jobs: Replace some uses of fmtstr with stpcpy/stpncpyDenys Vlasenko2020-02-161-8/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Sat, 19 May 2018 02:39:45 +0800 jobs: Replace some uses of fmtstr with stpcpy/stpncpy Some uses of fmtstr, particularly the ones without a format string, can be replaced with stpcpy or stpncpy. This patch does that so we don't have to introduce unnecessary format strings in order to silence compiler warnings. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: output: Fix fmtstr return valueDenys Vlasenko2020-02-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Sat, 19 May 2018 02:39:44 +0800 output: Fix fmtstr return value The function fmtstr is meant to return the actual length of output produced, rather than the untruncated length. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: main: Only set savestatus in exitcmdDenys Vlasenko2020-02-161-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Sat, 19 May 2018 02:39:38 +0800 main: Only set savestatus in exitcmd Currently exitcmd sets exitstatus and then savestatus if the latter was previously set. In fact, as exitcmd always raises an exception and will either end up in the setjmp call in main() or exitshell(), where exitstatus is always replaced by savestatus if set, we only need to set savestatus. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: [BUILTIN] Exit without arguments in a trap should use status outside trapsDenys Vlasenko2020-02-163-13/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Mon Oct 6 10:39:47 2014 +0800 [BUILTIN] Exit without arguments in a trap should use status outside traps POSIX now requires that exit without arguments in a trap should return the last command status prior to executing traps. This patch implements this behaviour. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: parser: Fix incorrect eating of backslash newlinesDenys Vlasenko2020-02-161-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Keeping up with upstream (in our case, 'before patch' code is not buggy). Upstream commit: Date: Fri, 11 May 2018 23:41:25 +0800 parser: Fix incorrect eating of backslash newlines With the introduction of synstack->syntax, a number of references to the syntax variable was missed during the conversion. This causes backslash newlines to be incorrectly removed in single quote context. This patch also combines these calls into a new helper function pgetc_top. Fixes: ab1cecb40478 ("parser: Add syntax stack for recursive...") Reported-by: Leah Neukirchen <leah@vuxu.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: use pgetc_eatbnl() in more places, take 2Denys Vlasenko2020-02-161-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adding previously skipped "readtoken1(pgetc_eatbnl(), DQSYNTAX..." changes from upstream commit: Date: Thu Mar 8 08:37:11 2018 +0100 Author: Harald van Dijk <harald@gigawatt.nl> parser: use pgetc_eatbnl() in more places dash has a pgetc_eatbnl function in parser.c which skips any backslash-newline combinations. It's not used everywhere it could be. There is also some duplicated backslash-newline handling elsewhere in parser.c. Replace most of the calls to pgetc() with calls to pgetc_eatbnl() and remove the duplicated backslash-newline handling. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2020-02-152-21/+56
|\|
| * ash,hush: allow builtins to be tab-completed, closes 7532Ron Yorston2020-01-292-1/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta complete_cmd_dir_file 678 830 +152 get_builtin_name - 35 +35 optschanged 125 132 +7 hush_main 1069 1076 +7 save_command_ps_at_cur_history 76 78 +2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/0 up/down: 203/0) Total: 203 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: improve expandstr()Ron Yorston2020-01-291-20/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The dash maintainer recently posted a fix for issues with expanding PS1. These had already been fixed differently in BusyBox ash. Borrow a couple of improvements: - Use a single call to setjmp() to trap errors in both readtoken1() and expandarg(). - In case of error set the prompt to the literal value of PS1 rather than the half-digested nonsense in stackblock() which might include ugly control characters. function old new delta expandstr 353 300 -53 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: code shrinkRon Yorston2020-02-141-4/+12
| | | | | | | | | | | | Commit 575581082 (ash: move code from setup_environment()) replaced calls to xsetenv_if_unset() with explicit tests. I don't know why because using xsetenv_if_unset() saves 48 bytes.
* | ash: code shrinkRon Yorston2020-02-111-3/+15
| | | | | | | | | | | | | | Since we don't support execution of signal traps or the 'trap hack' there's no need for the may_have_traps variable or trap_ptr. Saves 64 bytes.
* | ash: fixes to trapRon Yorston2020-02-101-3/+4
| | | | | | | | | | | | | | If a trap is set for SIGINT don't call raise(SIGINT) in preadfd(), otherwise the shell exits because the signal isn't being caught. In forkshell_init() change the initialisation of trap and trap_ptr.
* | ash: don't compile dotrap()Ron Yorston2020-02-081-0/+6
| | | | | | | | | | | | | | | | Since signal handling isn't functional for WIN32 there's no need to compile dotrap(). Some elements of the globals_misc structure can also be excluded. Saves 144 bytes.
* | ash: fixes to handling of ctrl-C in read builtinRon Yorston2020-02-082-2/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this script: while read -r; do echo $REPLY; done echo hello There are currently two problems with this when the read is interrupted by ctrl-C: - The error return code is 0 when it should be 130; - The echo command is executed. Fix these issues by propagating the control event to the process that would have caught it if the read builtin hadn't grabbed keyboard input.
* | ash: catch EOF in read builtinRon Yorston2020-02-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The read builtin didn't detect EOF so it wasn't possible to cleanly terminate a loop like: while read -r; do echo $REPLY; done Consider how Linux handles EOF (represented as ^D, though this isn't echoed): $ awk '{print}' | xxd abc^D123 ^D 00000000: 6162 6331 3233 0a abc123. Contrast with busybox-w32 on Windows (where the ^Z is echoed): $ awk '{print}' | xxd abc^Z123 ^Z 00000000: 6162 631a 3132 330a abc.123. In both cases EOF is only detected at the start of a line. On Linux EOF within a line is dropped; on Windows it's output as a literal ctrl-Z. Implement similar behaviour for the read builtin.
* | ash: process backspace in read builtinRon Yorston2020-02-071-0/+10
| | | | | | | | | | | | | | | | | | | | | | Previously the 'read' builtin had no special treatment for backspace characters entered in interactive mode: they were simply added to the string being read. Change this so that backspace deletes the previous character from the buffer and updates the display to match. It still doesn't handle tabs in the input or lines that are larger than the console width.
* | ash: remove obsolete commentRon Yorston2020-02-041-4/+1
| |
* | ash: tidy up history_copy()Ron Yorston2020-01-211-6/+6
| | | | | | | | No change in functionality or executable size.
* | ash: fix out of bounds read in tblentry_copy()Ron Yorston2020-01-191-1/+1
| | | | | | | | | | | | Commit 2ffcb860e (ash: minor fixes to forkshell handling) ensured that tblentry structures were properly aligned but also resulted in reads beyond the end of the allocated structure.
* | ash: reduce size of forkshell relocation mapRon Yorston2020-01-181-70/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The functions to calculate the size of the forkshell data block returned the total size of funcblock and funcstring. The relocation map only needs to cover the size of the forkshell structure plus funcblock, not funcstring. Revise the *_size() functions to distinguish between funcblock and funcstring. Avoid complicating the calculation of node sizes (calcsize() and related functions). This slightly overestimates the size of funcblock by including strings stored in node structures. This change increases the binary by 96 bytes but can save several thousand bytes at runtime.
* | ash: simplify MARK_PTR macroRon Yorston2020-01-181-9/+16
| | | | | | | | | | | | | | The MARK_PTR macro was unnecessarily complex. Since the relocation map is a fixed offset from the start of the forkshell structure we can obtain a pointer to the flag corresponding to a given destination pointer knowing just the pointer and the offset. Saves 324 bytes.
* | ash: reorder SAVE_PTR macrosRon Yorston2020-01-181-10/+8
| | | | | | | | | | | | Group together the code to mark pointers in the relocation map and that to store annotations. This allows some optimisations when forkshell debugging is enabled, saving 32 bytes.
* | ash: relocatesize may differ from forkshell block sizeRon Yorston2020-01-181-9/+12
| | | | | | | | | | | | | | Currently the size of the relocate map is equal to the size of the forkshell struct plus funcblock and funcstring. This may not always be the case so record the size of the map separately. This doesn't affect the size of the binary.
* | ash: rework how pointers are adjusted during forkshellRon Yorston2020-01-161-229/+185
| | | | | | | | | | | | | | | | | | | | The original code kept an array of pointers to pointers that needed to be adjusted after forkshell (nodeptr). Switch to using a map to indicate which locations in the data block need to be adjusted. This requires a larger data block. However the *_size() functions which calculate the data block size need less information about the data structures. Saves about 100 bytes in the binary.
* | ash: minor fixes to forkshell handlingRon Yorston2020-01-141-4/+2
| | | | | | | | | | | | | | | | Ensure that tblentry structures are properly aligned. The cmdname array has a size of one but the code doesn't allow for this in case upstream ever switches to using an empty array. Remove a couple of unnecessary increments.
* | Merge branch 'busybox' into mergeRon Yorston2020-01-088-75/+184
|\|
| * hush: fix preprocessor directives indentationDenys Vlasenko2019-11-281-32/+32
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: restore redirected stdinDenys Vlasenko2019-11-015-7/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta restore_redirects 52 95 +43 save_fd_on_redirect 243 253 +10 hfopen 90 99 +9 fgetc_interactive 259 261 +2 builtin_type 117 115 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 64/-2) Total: 62 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * clang/llvm 9 fix - do not eliminate a store to a fake "const"Denys Vlasenko2019-10-251-3/+3
| | | | | | | | | | | | | | This is *much* better (9 kbytes better) than dropping "*const" optimization trick. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: better comments in BASE#nn codeDenys Vlasenko2019-10-221-10/+14
| | | | | | | | | | | | | | function old new delta evaluate_string 932 930 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/ulimit: code shrinkDenys Vlasenko2019-10-211-18/+59
| | | | | | | | | | | | | | | | text data bss dec hex filename 1001949 551 5612 1008112 f61f0 busybox_old 1001906 551 5612 1008069 f61c5 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix BASE###nn bashism for bases 36..64Denys Vlasenko2019-09-221-3/+21
| | | | | | | | | | | | | | function old new delta evaluate_string 876 932 +56 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix BASE###nn bashism to accept letter 'digits' for bases > 9Denys Vlasenko2019-09-221-2/+9
| | | | | | | | | | | | | | function old new delta evaluate_string 873 876 +3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: add a FIXME commentDenys Vlasenko2019-09-051-1/+7
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix "set -o INVALID" affecting -e flag stateDenys Vlasenko2019-09-051-11/+9
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: copy line editing history during forkshellRon Yorston2019-12-161-10/+94
| | | | | | | | | | Add code to store line editing history in the forkshell data block. This allows things like 'history | grep whatever' to work.
* | ash: copy alias table during forkshellRon Yorston2019-12-151-1/+77
| | | | | | | | | | | | | | | | The alias table has never been copied during forkshell. As a result any attempts to use the alias command in conjunction with pipes or backquote expansion, for example, fail. Fix this by adding the necessary code.
* | ash: revert change to behaviour of -s optionRon Yorston2019-08-161-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | Upstream BusyBox commit f3634584d (ash,hush: show 'c' in $- if run in "sh -c CMD") changed the behaviour of -s to match that of bash rather than dash. This means that the -s and -c options can't be combined. This combination of options is used by the Windows 'su' applet to prevent the new console window from shutting down after the command has run. It's also useful when the shell is to be run with an initialisation command (GitHub issue #100). Revert the change so -s behaves as in dash.
* | Merge branch 'busybox' into mergeRon Yorston2019-08-163-87/+153
|\|
| * ash: fix set -o to not show "nameless" optionsDenys Vlasenko2019-08-021-0/+2
| | | | | | | | | | | | Patch by Martijn Dekker <martijn@inlv.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: only catch unexpected exceptions in PS1 expansionRon Yorston2019-07-311-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit d1a2fa2a4 (ash: catch error in arithmetic expansion in PS1) catches all exceptions raised by expandarg(). Some exceptions, such as the EXEXIT raised when command expansion is used, are expected: export PS1='$(echo "$ ")' These should be processed normally or the shell hangs at the prompt. function old new delta expandstr 344 353 +9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 9/0) Total: 9 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne2019-07-022-17/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: show 'c' in $- if run in "sh -c CMD"Denys Vlasenko2019-06-032-25/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta options 552 599 +47 expand_one_var 2375 2385 +10 optletters_optnames 60 64 +4 hush_main 1108 1111 +3 ash_main 1150 1152 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 66/0) Total: 66 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: allocate line editing structure only if neededDenys Vlasenko2019-06-011-37/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta optschanged 91 128 +37 historycmd 13 17 +4 setcmd 80 78 -2 ash_main 1167 1150 -17 options 576 552 -24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/3 up/down: 41/-43) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2019-05-2714-257/+404
|\|
| * shell: move all definitions of strto_arith_t() togetherDenys Vlasenko2019-05-262-11/+7
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: show 's' in $-Denys Vlasenko2019-05-191-3/+5
| | | | | | | | | | | | | | | | | | | | function old new delta expand_one_var 2362 2375 +13 hush_main 1104 1108 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 17/0) Total: 17 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: allocate line edit buffer only for interactive shellDenys Vlasenko2019-05-191-5/+9
| | | | | | | | | | | | | | function old new delta builtin_history 16 20 +4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>