aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c
AgeCommit message (Collapse)Author
2016-02-01Fix compiling with musl's utmp stubsKylie McClain
This patch fixes compiling busybox with FEATURE_UTMP and _WTMP enabled. musl, while not really support utmp/wtmp, provides stub functions, as well as variables such as _PATH_UTMP, so that programs using utmp or wtmp can still compile fine. My reasoning for this patch is that on Exherbo, I'm currently trying to get us to be able to use the same busybox config file for both glibc and musl systems, using utmp/wtmp on systems that support it, and using the stubs on musl without needing two different configs. As of latest musl git, it provides all utmp functions needed; 1.1.12 doesn't, but I sent a patch to Rich to add the utmp{,x}name functions expected to exist, which was merged into musl upstream. Signed-off-by: Kylie McClain <somasissounds@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-02ash: suppress a compilation warningCristian Ionescu-Idbohrn
Reported by gcc (Debian 5.3.1-4) 5.3.1 20151219 shell/ash.c: In function 'evaltree': shell/ash.c:8432:19: warning: logical not is only applied to the left hand side of comparison Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04ash: add support for bash 'function' keywordRon Yorston
Where the POSIX shell allows functions to be defined as: name () compound-command [ redirections ] bash adds the alternative syntax: function name [()] compound-command [ redirections ] Implement this in ash's bash compatibility mode. Most compound commands work (for/while/until/if/case/[[]]/{}); one exception is: function f (echo "no way!") The other two variants work: f() (echo "ok") function f() (echo "also ok") function old new delta parse_command 1555 1744 +189 tokname_array 232 240 +8 .rodata 155612 155566 -46 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 197/-46) Total: 151 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30ash: allow popredir to be called if the stack is emptyRon Yorston
If /tmp/test.sh is a script that tries to run a second script which happens to be non-executable this: command . /tmp/test.sh causes a seg fault. This is because clearredir is called in the error path to clear the stack of redirections. The normal path then calls popredir, but popredir fails when the stack is empty. Reported-by: Bastian Bittorf <bittorf@bluebottle.com> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30ash: fix EXEXEC status clobberingRon Yorston
evalcommand always clobbers the exit status in case of an EXEXEC which means that exec always fails with exit status 2 regardless of what it actually returns. This patch adds the missing check for EXEXEC so that the correct exit status is preserved. It causes the test ash-misc/exec.tests to succeed. Based on commit 7f68426 in dash git, by Herbert Xu. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29ash: simplify EOF/newline handling in list parserRon Yorston
Processing of here documents in ash has had a couple of breakages which are now the subject of tests. This commit should fix both. It is based on the following commit in dash git by Herbert Xu: <7c245aa> [PARSER] Simplify EOF/newline handling in list parser (See git://git.kernel.org/pub/scm/utils/dash/dash.git) Reported-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29Revert "ash: fix a SEGV case in an invalid heredoc" xxxRon Yorston
This reverts commit 7e66102f762a7d80715f0c7e5925433256b78cee but leaves the test in place as it's still valid. Reported-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29ash: fix error during recursive processing of here documentRon Yorston
Save the value of the checkkwd flag to prevent it being clobbered during recursion. Based on commit ec2c84d from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu. function old new delta readtoken 190 203 +13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0) Total: 13 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29ash: only allow local variables in functionsRon Yorston
Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29ash: respect -p flag when command builtin is run with -v/-VRon Yorston
The command builtin should only check the default path, not $PATH, when the -p flag is used along with -v/-V. Based on commits 65ae84b (by Harald van Dijk) and 29ee27d (by Herbert Xu) from git://git.kernel.org/pub/scm/utils/dash/dash.git). function old new delta commandcmd 72 87 +15 describe_command 437 450 +13 typecmd 84 86 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 30/0) Total: 30 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29ash: fix command -- crashDenys Vlasenko
busybox sh -c 'command --' segfaults because parse_command_args returns a pointer to a null pointer. Based on commit 18071c7 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Gerrit Pape. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29ash: save a few bytes in code to parse case statementsRon Yorston
Based on commit 49b82fc from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu. function old new delta parse_command 1563 1555 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-8) Total: -8 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29ash: allow newline after variable name in for loopRon Yorston
Newline is a valid delimiter between the variable name and `in` keyword in for loops. Based on commit 22e8fb4 from git://git.kernel.org/pub/scm/utils/dash/dash.git by Herbert Xu. function old new delta parse_command 1568 1563 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5) Total: -5 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23tidy up strtok useDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-10ash: shrink umask codeDenys Vlasenko
function old new delta umaskcmd 258 248 -10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09ash: "you have mail" should ignore first change in mtimeDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09ash: simplify "you have mail" codeDenys Vlasenko
function old new delta mailtime_hash - 4 +4 redirect 1282 1280 -2 mailtime 40 - -40 cmdloop 429 378 -51 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/2 up/down: 4/-93) Total: -89 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09ash: make dowait() a bit more readable. Logic is unchangedDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07build system: -fno-builtin-printfDenys Vlasenko
Benefits are: drops reference to out-of-line putchar(), fixes a few cases of failed string merge. function old new delta i2cdump_main 1488 1502 +14 sha256_process_block64 423 433 +10 sendmail_main 1183 1185 +2 list_table 1114 1116 +2 i2cdetect_main 1235 1237 +2 fdisk_main 2852 2854 +2 builtin_type 119 121 +2 unicode_conv_to_printable2 325 324 -1 scan_recursive 380 378 -2 mkfs_minix_main 2687 2684 -3 buffer_fill_and_print 178 169 -9 putchar 152 - -152 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 7/4 up/down: 34/-167) Total: -133 bytes text data bss dec hex filename 937788 932 17676 956396 e97ec busybox_old 937564 932 17676 956172 e970c busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07ash: use a more typical form of "print four octal digits" formatDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07libbb: more compact API for bb_parse_mode()Denys Vlasenko
function old new delta make_device 2182 2188 +6 parse_command 1440 1443 +3 parse_params 1497 1499 +2 install_main 773 769 -4 mkdir_main 168 160 -8 getoptscmd 641 632 -9 builtin_umask 158 147 -11 bb_parse_mode 431 410 -21 umaskcmd 286 258 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/6 up/down: 11/-81) Total: -70 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07ash: shrink "umask -S" codeDenys Vlasenko
function old new delta umaskcmd 279 286 +7 static.permmode 3 - -3 static.permmask 18 - -18 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07hush: fix umask: umask(022) was setting umask(755)Denys Vlasenko
Based on the patch by Rich Felker <dalias@libc.org> function old new delta builtin_umask 121 161 +40 umaskcmd 318 279 -39 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07ash: a bunch of trivial simplificationsDenys Vlasenko
Also, in a few places made code more reliable wrt large sizeof(int) and sizeof(arith_t).. function old new delta sprint_status48 - 143 +143 newline_and_flush - 56 +56 showjob 365 382 +17 parse_command 1440 1443 +3 cmdputs 334 332 -2 cmdloop 434 429 -5 showjobs 70 64 -6 fg_bgcmd 296 290 -6 ash_vmsg 159 153 -6 ash_main 1487 1481 -6 jobscmd 94 82 -12 getoptscmd 687 632 -55 outcslow 56 - -56 sprint_status 156 - -156 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 2/8 up/down: 219/-310) Total: -91 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04ash: fix slash treatment in expmetaRon Yorston
Commit 549deab caused this sequence of commands: mkdir foo cd foo touch a b echo "./"* to return './*' instead of the expected './a ./b'. The problem was caused by the backport of commit 880d952 from dash. In dash the issue was fixed by two further commits by Herbert Xu: <d6d06ff> [EXPAND] Fixed non-leading slash treatment in expmeta <36f0fa8> [EXPAND] Fix slash treatment in expmeta (See git://git.kernel.org/pub/scm/utils/dash/dash.git) Apply these fixes to BusyBox ash, thus causing the new test glob3.tests to succeed. function old new delta expmeta 469 528 +59 Reported-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19libbb: add a function to make a copy of a region of memoryRon Yorston
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>
2015-07-13ash: use alloca to get rid of setjmpRon Yorston
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>
2015-07-13ash: remove parsebackquote flagRon Yorston
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>
2015-07-13Removes stray empty line from codeManinder Singh
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>
2015-05-18ash: fix breakage of ${v/pat/str}Ron Yorston
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>
2015-05-18ash: move parse-time quote flag detection to run-timeRon Yorston
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>
2015-05-18ash: remove arithmetic expansion collapsing at parse timeRon Yorston
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>
2015-05-18ash: remove superfluous code in arithmetic modeRon Yorston
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>
2015-05-18ash: do not expand tilde in parameter expansion within quotesRon Yorston
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>
2015-05-18ash: perform tilde expansion in all parameter expansion wordsRon Yorston
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>
2015-05-18ash: code shrink around varvalueRon Yorston
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>
2015-05-13ash: explain what "local -" doesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-05-13ash: consider "local -" case while iterating over local variables in mklocal.Eugene Rudoy
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>
2015-04-20libbb: remove unnecessary argument to nonblock_immune_readRon Yorston
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>
2015-04-18ash: fix handling of duplicate "local"Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22ash: do not split the result of tilde expansionRon Yorston
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>
2015-02-05ash: fix a SEGV case in an invalid heredocDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-29ash: fix a SEGV in ${#1}Denys Vlasenko
function old new delta varvalue 760 805 +45 evalvar 648 603 -45 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-17ash: fix handling of negative start value in ${v:start:len}Denys Vlasenko
function old new delta subevalvar 1140 1168 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-08ash: fix off-by-one in "jobs %4" handling. closes 7310Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-09-08ash: factor out ASH_HELP config optionDenys Vlasenko
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>
2014-08-13ash: make ${#var} unicode-awareDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-08-13ash,hush: run reinit_unicode() only if makes senseDenys Vlasenko
With static Unicode support, no need to check $LANG et al. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-06-22libbb: use a wrapper around sysconf(_SC_CLK_TCK) to save a few bytesBartosz Golaszewski
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>
2014-04-15ash,hush: set $HOSTNAME is bash compat. Closes 7028Denys Vlasenko
function old new delta hush_main 1056 1128 +72 ash_main 1442 1487 +45 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>