summaryrefslogtreecommitdiff
path: root/shell/ash.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
| * ash: [BUILTIN] Exit without arguments in a trap should use status outside trapsDenys Vlasenko2020-02-161-13/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-151-21/+39
|\|
| * ash,hush: allow builtins to be tab-completed, closes 7532Ron Yorston2020-01-291-1/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-081-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: 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-081-4/+10
|\|
| * 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>
| * ash: add a FIXME commentDenys Vlasenko2019-09-051-1/+7
| | | | | | | | 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-161-65/+128
|\|
| * 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>
| * ash,hush: show 'c' in $- if run in "sh -c CMD"Denys Vlasenko2019-06-031-20/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | 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 mergeFRP-3128-g241d4d4acRon Yorston2019-04-201-13/+23
|\|
| * ash: catch error in arithmetic expansion in PS1Ron Yorston2019-04-191-12/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Setting PS1 to: PS1='$((123+))' causes the shell to enter an infinite error loop: sh: arithmetic syntax error Catch any exception raised by expandarg() in expandstr() and allow processing to continue. function old new delta expandstr 262 344 +82 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 82/0) Total: 82 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: prevent error in backquotes in PS1 from exiting shellRon Yorston2019-04-191-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Setting PS1 to: PS1='`xxx(`' causes the shell to terminate with the error: sh: syntax error: unexpected end of file (expecting ")") This happens because old-style backquotes require the input to be reread and thus call setinputstring() a second time. Prevent the problem by unwinding all recently opened files in expandstr(). function old new delta unwindfiles - 22 +22 expandstr 247 262 +15 forkchild 631 625 -6 evalcommand 1694 1685 -9 ash_main 1346 1336 -10 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/3 up/down: 37/-25) Total: 12 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2019-04-171-20/+59
|\|
| * ash: add bash-compatible EPOCH variablesRon Yorston2019-04-161-21/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bash 5.0 added the dynamic variable EPOCHSECONDS and EPOCHREALTIME which return the number of seconds since the Unix Epoch as an integer or float. These are useful for logging or tracing. function old new delta change_epoch - 78 +78 .rodata 175167 175235 +68 varinit_data 264 312 +48 change_seconds - 24 +24 change_realtime - 24 +24 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 2/0 up/down: 242/0) Total: 242 bytes text data bss dec hex filename 938508 4203 1888 944599 e69d7 busybox_old 938702 4203 1888 944793 e6a99 busybox_unstripped v2: Cast tv_sec and tv_usec to unsigned quantities. Add brackets to macros. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: an unset dynamic variable should not be dynamicRon Yorston2019-04-161-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit b28d4c346 (ash: [VAR] Move unsetvar functionality into setvareq) dropped the code that caused dynamic variables to lose their special properties when unset. Add it back again. function old new delta setvareq 346 360 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 14/0) Total: 14 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2019-04-041-7/+8
|\|
| * ash: distinguish 'wait -n' from other bashismsRon Yorston2019-04-021-7/+8
| | | | | | | | | | | | | | | | Add a specific define to indicate which bash compatibility code implements 'wait -n'. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: try to make working directory names consistentRon Yorston2019-04-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Standardise the path names used for the current working directory by: - resolving with realpath(3); - making the drive name or host name uppercase. The first only really works for physical drives; results for mapped drives are patchy. The standardisation is applied in two places: - at the end of updatepwd() in ash; - when a symbolic link is resolved in mingw_chdir().
* | df: display origin of mapped driveRon Yorston2019-04-011-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When a drive is mapped to a network share or a path display the mapping in the 'Filesystem' column of df's output. Since this changes the mnt_fsname field of the mntent structure a slight alteration is needed to print_all_cwd() in ash. Revert the change in commit a8c63f25b that enabled FEATURE_DF_FANCY in the default configuration. None of the additional options is very useful. See GitHub issue #164.
* | Merge branch 'busybox' into mergeRon Yorston2019-03-311-6/+47
|\|
| * ash: add "wait -n" bashismDenys Vlasenko2019-03-271-6/+47
| | | | | | | | | | | | | | | | | | | | function old new delta waitcmd 205 288 +83 dowait 405 444 +39 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 122/0) Total: 122 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: improved support for c:path path namesRon Yorston2019-03-301-29/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Microsoft Windows permits path names of the form 'c:path', without a path separator after the colon. The system records a current directory for each drive and the path is interpreted relative to that. Since Windows API calls understand 'c:path' path names many commands in busybox-w32 already work with them. This commit adds the following: - The 'cd' shell built-in interprets 'c:path' path names correctly. Previously it treated them as relative to the shell's concept of the current working directory, not the current directory of the specified drive. - The 'pwd' shell built-in takes the '-a' option to list the current directory for all drives. - 'c:path' path names are subject to tab-completion. Paths of the form 'c:path' don't work for mapped network drives or paths that have been associated with a drive using SUBST. See GitHub issue #147.
* | win32: interpret absolute paths as relative to %SYSTEMDRIVE%Ron Yorston2019-03-281-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | BusyBox contains hardcoded references to absolute paths which are unique in the *nix world but on Microsoft Windows are interpreted as being on the current drive. To make these unique again consider them to be relative to %SYSTEMDRIVE%. Support this by adding functions to: - determine the system drive (not using the environment variable); - change a process's current directory to the root of the system drive; - make relative paths absolute before changing directory (if needed). The following applications have been modified: - ash references /etc/profile from the system drive; - dpkg places its data store on and installs files to the system drive; - rpm installs files to the system drive; - man looks for configuration files and man pages on the system drive. See GitHub issue #158.
* | win32: share code to find root prefix of pathRon Yorston2019-03-231-28/+2
| | | | | | | | | | | | | | Move unc_root_len() from ash to mingw32.c and use it in the new function root_len(), which can be used in make_directory(). This reduces changes to upstream code and saves a few bytes.
* | ash: rewrite PATH update to save a few bytesRon Yorston2019-03-181-12/+8
| |
* | ash: enforce ';' separator in CDPATH and MANPATH variablesRon Yorston2019-03-161-11/+23
| | | | | | | | | | | | | | | | | | | | Commit a23624237 (win32: special treatment for PATH) required the PATH variable to use ';' as the separator between components and enforced this by intercepting attempts to update it. Do the same for the CDPATH and MANPATH variables. Also, fix a case in cdcmd() where the wrong separator was used.
* | ash: set current working directory on startupRon Yorston2019-03-151-0/+7
| | | | | | | | | | | | | | | | | | | | | | When the shell starts behave as though the user had manually changed to the current working directory of the process, but only if it's an interactive, non-login shell and the '-d' flag isn't present. This gives more consistent behaviour when the shell is started in a drive mapped to a network share or a symlinked directory. This completes the changes requested in GitHub issue #148.
* | win32: add function to convert slashes to backslashesRon Yorston2019-03-151-2/+2
| | | | | | | | | | | | | | | | | | There are now two places where slashes are converted to backslashes throughout a string so it makes sense to create a function to do this. To avoid confusion rename convert_slashes() to bs_to_slash() and call the new function slash_to_bs().