summaryrefslogtreecommitdiff
path: root/shell/ash.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
| * libbb: add a function to make a copy of a region of memoryRon Yorston2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce a library routine to package the idiom: p = xmalloc(b, n); memcpy(p, b, n); and use it where possible. The example in traceroute used xzalloc but it didn't need to. function old new delta xmemdup - 32 +32 last_main 834 826 -8 make_device 2321 2311 -10 common_traceroute_main 3698 3685 -13 readtoken1 3182 3168 -14 procps_scan 1222 1206 -16 forkchild 655 638 -17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/6 up/down: 32/-78) Total: -46 bytes Signed-off-by: Ron Yorston <rmy@frippery.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: don't convert path delimiters for certain environment variablesRon Yorston2015-07-301-0/+6
| | | | | | | | | | | | | | The SYSTEMROOT and COMSPEC environment variables are known to cause problems for Windows applications if they contain forward slashes rather than backslashes. So don't convert them, even if the -X flag isn't present.
* | Merge branch 'busybox' into mergeRon Yorston2015-07-141-43/+3
|\|
| * ash: use alloca to get rid of setjmpRon Yorston2015-07-131-34/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that the only thing protected by setjmp/longjmp is the saved string, we can allocate it on the stack to get rid of the jump. Based on commit bd35d8e from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu. function old new delta readtoken1 3182 3116 -66 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-66) Total: -66 bytes Signed-off-by: Ron Yorston <rmy@frippery.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: remove parsebackquote flagRon Yorston2015-07-131-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 503a0b8 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu says: >The parsebackquote flag is only used in a test where it always has the >value zero. So we can remove it altogether. The first statement is incorrect: parsebackquote is non-zero when backquotes (as opposed to $(...)) are used for command substitution. It is possible for the test to be executed with parsebackquote != 0 in that case. The test is question checks whether quotes have been closed, raising the error "unterminated quoted string" if they haven't. There seems to be no good reason to allow unclosed quotes within backquotes. Bash, hush and dash (after commit 503a0b8) all treat the following as an error: XX=`"pwd` whereas BusyBox ash doesn't. It just ignores the unclosed quote and executes pwd. So, parsebackquote should be removed but not for the reason stated. function old new delta parsebackquote 1 - -1 readtoken1 3222 3182 -40 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-41) Total: -41 bytes Signed-off-by: Ron Yorston <rmy@frippery.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * Removes stray empty line from codeManinder Singh2015-07-131-2/+0
| | | | | | | | | | | | | | | | | | This patch removes stray empty line from busybox code reported by script find_stray_empty_lines Signed-off-by: Maninder Singh <maninder1.s@samsung.com> Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: store pointers to be fixed as pointers, not intRon Yorston2015-07-141-14/+16
| | | | | | | | | | | | The data block passed during forkshell includes the nodeptr array of (internal) pointers to (other internal) pointers that need to be fixed. Store the pointers as pointers, not int.
* | ash: add winxp optionRon Yorston2015-06-051-6/+13
| | | | | | | | | | | | | | | | | | In some circumstances Windows XP and Windows Server 2003 seem to dislike environment variables with backslashes in paths. The 'winxp' option prevents BusyBox from changing backslashes to slashes in the environment. Although the option can be managed by the 'set' builtin it only works if '-X' is given as the first argument to the shell.
* | ash: skip PATH if executable and command are both busyboxRon Yorston2015-06-021-0/+21
| | | | | | | | | | | | If the command is 'busybox' and the executable is 'busybox.exe' don't bother checking PATH, just run the executable. This means that busybox.exe can be somewhere other than on PATH.
* | ash: seek to EOF when file is opened for appendRon Yorston2015-05-281-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This shouldn't be necessary but without it the offset becomes zero when an external command is run. rm -f log echo 1234567890 >>log cmd /c echo hi >>log echo 1234567890 >>log Before this change log would contain: hi 567890 1234567890
* | Merge branch 'busybox' into mergeFRPRon Yorston2015-05-181-221/+167
|\|
| * ash: fix breakage of ${v/pat/str}Ron Yorston2015-05-181-51/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The commit ash: move parse-time quote flag detection to run-time breaks pattern substitution in parameter expansion. Fix this and revise the code so that the different handling of the pattern and the replacement string takes place in rmescapes rather than the separate function parse_sub_pattern. function old new delta rmescapes 227 273 +46 static.qchars 3 4 +1 subevalvar 1177 1157 -20 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 47/-20) Total: 27 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: move parse-time quote flag detection to run-timeRon Yorston2015-05-181-98/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because the parser does not recursively parse parameter expansion with respect to quotes, we can't accurately determine quote status at parse time. This patch works around this by moving the quote detection to run-time where we do interpret it recursively. Test case: foo=\\ echo "<${foo#[\\]}>" Old result: <\> New result: <> Do not quote back slashes in parameter expansions outside quotes. Test case: a=/b/c/* b=\\ echo ${a%$b*} Old result: /b/c/* New result: /b/c/ Based on commits 880d952, 7cfd8be, 0d7d660 and a7c21a6 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu function old new delta argstr 1164 1193 +29 memtodest 147 174 +27 subevalvar 1153 1177 +24 redirect 1279 1282 +3 dolatstr 5 7 +2 static.spclchars 10 9 -1 expandarg 962 960 -2 evalcase 273 271 -2 evalcommand 1204 1197 -7 rmescapes 236 227 -9 preglob 27 8 -19 evalvar 604 582 -22 cmdputs 389 334 -55 readtoken1 3163 3061 -102 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/9 up/down: 85/-219) Total: -134 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: remove arithmetic expansion collapsing at parse timeRon Yorston2015-05-181-12/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Collapsing arithmetic expansion is incorrect when the inner arithmetic expansion is a part of a parameter expansion. Test case: unset a echo $((3 + ${a:=$((4 + 5))})) echo $a Old result: 12 (4 + 5) New result: 12 9 Based on commit bb777a6 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu function old new delta readtoken1 3180 3163 -17 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: remove superfluous code in arithmetic modeRon Yorston2015-05-181-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Based on commits 1a74845, cfc3d6a and ff13779 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu function old new delta evalcommand 1197 1204 +7 localcmd 327 325 -2 readtoken1 3200 3180 -20 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 7/-22) Total: -15 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: do not expand tilde in parameter expansion within quotesRon Yorston2015-05-181-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Test case: unset a echo "${a:-~root}" Old result: /root New result: ~root Based on commit 170f44d from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu function old new delta evalvar 598 604 +6 parse_command 1440 1443 +3 localcmd 325 327 +2 readtoken1 3199 3200 +1 argstr 1180 1164 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 12/-16) Total: -4 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: perform tilde expansion in all parameter expansion wordsRon Yorston2015-05-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously tilde expansion was not carried out for =?#% expansion words. Test case: a=~root:~root echo ${a#~root} Old result: /root:/root New result: :/root Based on commit dd721f71 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu function old new delta subevalvar 1152 1153 +1 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: code shrink around varvalueRon Yorston2015-05-181-46/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Based on commit c989d72 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu function old new delta strtodest - 40 +40 memtodest 123 147 +24 parse_command 1443 1440 -3 readtoken1 3205 3199 -6 argstr 1203 1180 -23 varvalue 788 660 -128 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/4 up/down: 64/-160) Total: -96 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: explain what "local -" doesDenys Vlasenko2015-05-131-1/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: consider "local -" case while iterating over local variables in mklocal.Eugene Rudoy2015-05-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | fixes segfault introduced in 0a0acb55db8d7c4dec445573f1b0528d126b9e1f with functions using "local -". test-case: f() { local -; local x; }; f note: with this change applied multiple 'local -'s still cause multiple entries to be added to the localvars list. this problem will be addressed in a separate commit. Signed-off-by: Eugene Rudoy <gene.devel@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: remove unnecessary argument to nonblock_immune_readRon Yorston2015-04-201-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The loop_on_EINTR argument to nonblock_immune_read is always set to 1. function old new delta xmalloc_reads 200 195 -5 pgetc 488 483 -5 argstr 1313 1308 -5 nonblock_immune_read 123 86 -37 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-52) Total: -52 bytes Signed-off-by: Ron Yorston <rmy@tigress.co.uk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix handling of duplicate "local"Denys Vlasenko2015-04-181-16/+35
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2015-03-231-3/+0
|\|
| * ash: do not split the result of tilde expansionRon Yorston2015-03-221-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A tilde expansion generates a valid pathname. Splitting it using IFS either leaves it unchanged or changes it to something unintended. Example: IFS=m HOME=/tmp; printf "%s\n" ~ Based on this commit authored by Jilles Tjoelker: http://git.kernel.org/cgit/utils/dash/dash.git/commit/?id=834629283f6c629a4da05ef60bae9445c954a19a Signed-off-by: Ron Yorston <rmy@tigress.co.uk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2015-03-141-13/+20
|\| | | | | | | | | | | Conflicts: coreutils/od_bloaty.c libbb/lineedit.c
| * ash: fix a SEGV case in an invalid heredocDenys Vlasenko2015-02-051-4/+11
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix a SEGV in ${#1}Denys Vlasenko2014-12-291-9/+9
| | | | | | | | | | | | | | | | function old new delta varvalue 760 805 +45 evalvar 648 603 -45 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2014-12-141-1/+9
|\| | | | | | | | | | | | | Conflicts: archival/libarchive/open_transformer.c libbb/lineedit.c miscutils/man.c
| * ash: fix handling of negative start value in ${v:start:len}Denys Vlasenko2014-11-171-1/+9
| | | | | | | | | | | | | | function old new delta subevalvar 1140 1168 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2014-10-061-23/+42
|\|
| * ash: fix off-by-one in "jobs %4" handling. closes 7310Denys Vlasenko2014-09-081-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: factor out ASH_HELP config optionDenys Vlasenko2014-09-081-11/+15
| | | | | | | | | | | | | | | | | | It used to be aliased to !FEATURE_SH_EXTRA_QUIET for ash, while hush had it separate from FEATURE_SH_EXTRA_QUIET. Bring ash in line with hush. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: make ${#var} unicode-awareDenys Vlasenko2014-08-131-13/+26
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: run reinit_unicode() only if makes senseDenys Vlasenko2014-08-131-1/+3
| | | | | | | | | | | | With static Unicode support, no need to check $LANG et al. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2014-06-301-1/+1
|\|
| * libbb: use a wrapper around sysconf(_SC_CLK_TCK) to save a few bytesBartosz Golaszewski2014-06-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta bb_sc_clk_tck - 10 +10 timescmd 118 113 -5 print_route 1763 1758 -5 mpstat_main 1288 1283 -5 iostat_main 1947 1942 -5 INET_setroute 879 871 -8 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/5 up/down: 10/-28) Total: -18 bytes Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: support UNC paths in cd commandRon Yorston2014-05-211-13/+20
| |
* | Merge branch 'busybox' into mergeRon Yorston2014-05-061-1/+10
|\| | | | | | | | | | | | | Conflicts: debianutils/which.c editors/vi.c libbb/executable.c
| * ash,hush: set $HOSTNAME is bash compat. Closes 7028Denys Vlasenko2014-04-151-0/+6
| | | | | | | | | | | | | | | | function old new delta hush_main 1056 1128 +72 ash_main 1442 1487 +45 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: make "locak VAR" unset VAR (bash does that)Denys Vlasenko2014-03-161-0/+3
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: remove redundant commentRon Yorston2014-05-011-1/+0
| |
* | ash: further tidying up of MinGW forkshellRon Yorston2014-04-301-41/+47
| | | | | | | | | | | | | | The forkpoint_fn in the forkshell structure was redundant as the fpid element indicated which function to call in the child. Explicitly set fpid before calling spawn_forkshell and replace the forkpoint_fn array with a function, forkshell_child.
* | ash: tidy up MinGW forkshellRon Yorston2014-04-291-120/+129
| | | | | | | | | | | | | | Move some MinGW-specific code into sections at the top and bottom of the file. Exclude some code that isn't used in the MinGW port.
* | ash: reset $RANDOM in subshellRon Yorston2014-04-281-0/+2
| |
* | Remove unnecessary differences from upstream BusyBoxRon Yorston2014-03-231-1/+0
| |
* | ash: set fake PPID valueRon Yorston2014-03-201-3/+2
| |
* | mingw: dummy implementation of times/sysconfRon Yorston2014-01-301-9/+0
| |
* | ash: reset pointers to builtin environment variables after forkRon Yorston2014-01-141-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The builtin environment variables can be accessed using macros that reference the varinit array. initvar puts pointers to varinit into the variable hash table. During forkshell_prepare two copies of the builtin variables are made: once as the varinit array and again through the pointers in the hash table. One of these copies is accessed by code that uses the macros and the other by code that looks up the variable by name. This is the cause of the strange behaviour of IFS in backticks: https://github.com/pclouds/busybox-w32/issues/12 To avoid the problem the pointers in the hash table are reset to the varinit array in forkshell_init. It seemed easier to do it this way than to try and prevent the duplicate copies being made in the first place.
* | ash: revert initialisation of SHLVL: fixed upstreamRon Yorston2014-01-131-4/+0
| |
* | Merge branch 'busybox' into mergeRon Yorston2014-01-131-1/+1
|\| | | | | | | | | | | Conflicts: include/platform.h scripts/basic/fixdep.c