aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* hush: support %%, %+ and % jobspec (meaning "current job")Denys Vlasenko2017-01-081-9/+21
| | | | | | | | function old new delta parse_jobspec 83 133 +50 builtin_wait 278 283 +5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: correct exitcode for unterminated ')' - exitcode2.tests testcaseDenys Vlasenko2017-01-031-2/+7
| | | | | | | function old new delta parse_stream 2595 2609 +14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Make it possible to select "sh" and "bash" aliases without selecting ash or hushDenys Vlasenko2016-12-231-35/+24
| | | | | | | The same can be done for msh, but we are probably better off just deleting it in a next versio or two. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: move "config" blocks above their use in coditional includesDenys Vlasenko2016-12-221-29/+29
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: suppress "unused var/func" warnings on some configsDenys Vlasenko2016-12-121-4/+4
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: make ^C in interactive mode visually much closer to bash behaviorDenys Vlasenko2016-11-251-6/+11
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: ^C from command line should set $? to 128+SIGINTDenys Vlasenko2016-11-241-5/+21
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: make getch/peek functions directly calledDenys Vlasenko2016-11-081-27/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Indirect calls are more difficult to predict. Unfortunately, on x64 direct call is 5 bytes while indirect "call (reg+ofs)" is 3 bytes: function old new delta i_getch - 82 +82 i_peek - 63 +63 parse_stream 2531 2579 +48 parse_dollar 771 797 +26 parse_redirect 296 321 +25 add_till_closing_bracket 408 420 +12 encode_string 256 265 +9 i_peek_and_eat_bkslash_nl 93 99 +6 add_till_backquote 110 114 +4 parse_and_run_stream 139 141 +2 expand_vars_to_list 1143 1144 +1 static_peek 6 - -6 setup_string_in_str 39 18 -21 setup_file_in_str 40 19 -21 static_get 27 - -27 file_peek 52 - -52 file_get 65 - -65 ------------------------------------------------------------------------------ (add/remove: 2/4 grow/shrink: 9/2 up/down: 278/-192) Total: 86 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: renumber PIPE_foo, make PIPE_SEQ = 0Denys Vlasenko2016-11-081-5/+4
| | | | | | | | | | PIPE_SEQ is used most often, having it zero makes code smaller: function old new delta done_word 719 707 -12 parse_stream 2546 2531 -15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: small optimization in run_listDenys Vlasenko2016-11-081-7/+8
| | | | | | | | | I thought gcc can detect this itself. It doesn't. function old new delta run_list 1030 1021 -9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: deindent large block of code, no code changesDenys Vlasenko2016-11-081-58/+57
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: simplify insert_bg_jobsDenys Vlasenko2016-11-081-10/+8
| | | | | | | function old new delta insert_bg_job 366 281 -85 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: make "wait %1" less likely to play with signal maskDenys Vlasenko2016-11-081-8/+7
| | | | | | | | | | | Was playing with "sleep 3 | exit 3 & wait %1" and noticed that often SIGCHLD arrives even before I get to signal masking. Can avoid it in this case. function old new delta wait_for_child_or_signal 228 265 +37 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: rework "wait %jobspec" to work in non-interactive shells tooDenys Vlasenko2016-11-081-13/+8
| | | | | | | | | Also add tests. wait5.tests so far fails (but works for ash and dash). function old new delta builtin_wait 305 283 -22 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: "wait $!; echo $?" should return 127 if $! already exitedDenys Vlasenko2016-11-071-4/+5
| | | | | | | It would be nice to provide bash-like "remember las exitcode" thingy, but it's a bit complex. For now, match ash and dash. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: implement "wait %jobspec"Denys Vlasenko2016-11-071-29/+88
| | | | | | | | | | | | | | | | function old new delta parse_jobspec - 83 +83 job_exited_or_stopped - 79 +79 builtin_wait 236 302 +66 wait_for_child_or_signal 199 228 +29 checkjobs 142 158 +16 builtin_jobs 59 68 +9 process_wait_result 453 408 -45 builtin_fg_bg 272 203 -69 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 4/2 up/down: 282/-114) Total: 168 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: factor out %jobspec parsingDenys Vlasenko2016-11-071-11/+22
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: comment fixDenys Vlasenko2016-11-071-2/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: do not allow sh -c '{ echo boo }'Denys Vlasenko2016-11-071-2/+4
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: case logic for setting $? was still wrongDenys Vlasenko2016-11-041-4/+12
| | | | | | | Resetting to 0 should happen in "esac". Matched branch must still see previous $?. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: non-matching "case" statement sets $? to 0Denys Vlasenko2016-11-041-0/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: allow { cmd } to not be terminated by semicolon in some casesDenys Vlasenko2016-11-041-6/+26
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix "(sleep 1; exit 3) & sleep 2; echo $?; wait $!; echo $?"Denys Vlasenko2016-10-281-4/+14
| | | | | | | "wait $!" may be just a bit too late: backgrounded $! is gone. Do not bomb out in this case. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix "wait PID"Denys Vlasenko2016-10-281-174/+230
| | | | | | | | | | | | | | | | | It was not properly interruptible, and did not update job status (the exited processes were still thought of as running). function old new delta process_wait_result - 453 +453 wait_for_child_or_signal - 199 +199 run_list 996 1002 +6 checkjobs_and_fg_shell 41 43 +2 builtin_wait 328 215 -113 checkjobs 516 142 -374 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 2/2 up/down: 660/-487) Total: 173 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: [SHELL] Expand ENV before using itDenys Vlasenko2016-10-271-0/+1
| | | | | | | | | | | | | Upstream commit: Date: Sun, 13 Jul 2008 21:51:52 +0800 [SHELL] Expand ENV before using it Per POSIX ENV needs to undergo parameter expansion. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: set exit code 127 in "sh /does/not/exist" caseDenys Vlasenko2016-10-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit 1 for ash: [ERROR] Allow the originator of EXERROR to set the exit status Some errors have exit status values specified by POSIX and it is therefore desirable to be able to set the exit status at the EXERROR source rather than in main.c. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Upstream commit 2 for ash: [INPUT] Use exit status 127 when the script to run does not exist This commit makes dash exit with return code 127 instead of 2 if started as non-interactive shell with a non-existent command_file specified as argument (or a directory), as documented in http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html#tag_04_128_14 The wrong exit code was reported by Clint Adams and Jari Aalto through http://bugs.debian.org/548743 http://bugs.debian.org/548687 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> NB: in fact, http://bugs.debian.org/548687 was not fixed by this: "sh /dir/" thinks that EISDIR error on read is EOF, and exits 0. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add commented-out debug printouts in "memleak" built-inDenys Vlasenko2016-10-031-0/+9
| | | | | | | Allocation addresses of malloc() are jittery, thought I had a mem leak in hush, but it was malloc variability. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix a memory corruption when exported variable is modifiedDenys Vlasenko2016-10-031-7/+19
| | | | | | | | | | | | The construct such as this: t=1 export t t=new_value1 had a small probability of momentarily using free()d value. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix exitcode on exec failure with EACCES - should be 126Denys Vlasenko2016-10-031-1/+5
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* whitespace fixesDenys Vlasenko2016-10-021-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix var3.testsDenys Vlasenko2016-10-021-206/+214
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* sh: do not print empty line at the end of "help" outputDenys Vlasenko2016-10-021-1/+0
| | | | | | It's pointless. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: 'return' should have effect earlierDenys Vlasenko2016-10-011-14/+20
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: enable "msh is deprecated" message in msh stubDenys Vlasenko2016-09-301-1/+1
| | | | | | | After giving a few more years for everyone to notice and migrate, can nuke all remains of msh. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix typo in commentDenys Vlasenko2016-09-301-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix interactive input handling of backslash+newlineDenys Vlasenko2016-09-301-74/+89
| | | | | | | | | | | | | | | | | function old new delta fgetc_interactive - 258 +258 i_peek_and_eat_bkslash_nl 43 93 +50 static_peek2 7 - -7 setup_string_in_str 46 39 -7 setup_file_in_str 47 40 -7 file_peek 72 52 -20 expand_vars_to_list 1167 1143 -24 file_peek2 74 - -74 file_get 326 65 -261 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 1/5 up/down: 308/-400) Total: -92 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: G.user_input_buf[] is needed only if line editing is enabledDenys Vlasenko2016-09-291-2/+7
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: speed optimizationsDenys Vlasenko2016-09-291-6/+27
| | | | | | | | | | | | | | Make o_addchr() faster: do not call o_grow_by() each time. Create i_getch_and_eat_bkslash_nl(), use it instead of peek+getch pair. function old new delta o_addchr 42 54 +12 parse_dollar 761 771 +10 o_grow_by 48 37 -11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 24/-11) Total: 11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix handling of by backslash-newline in $((arith)) and $(cmd)Denys Vlasenko2016-09-291-15/+39
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: rework input char buffering to allow more than one-deep peekDenys Vlasenko2016-09-291-68/+125
| | | | | | ...this time with actual hush.c changes too :) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix 'eval ""' handlingDenys Vlasenko2016-09-291-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix ". EMPTY_LINE" not setting $? to 0Denys Vlasenko2016-09-291-0/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: document better where bad redirect syntax is detectedDenys Vlasenko2016-09-201-3/+20
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix "redirects can close script fd" bugDenys Vlasenko2016-08-221-61/+140
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: do not leak script fds into NOEXEC childrenDenys Vlasenko2016-08-201-10/+68
| | | | | | | | | | | | | | | | | | | | | We set all opened script fds to CLOEXEC, thus making then go away after fork+exec. Unfortunately, CLOFORK does not exist. NOEXEC children will still see those fds open. For one, "ls" applet is NOEXEC. Therefore running "ls -l /proc/self/fd" in a script from standalone shell shows this: lrwx------ 1 root root 64 Aug 20 15:17 0 -> /dev/pts/3 lrwx------ 1 root root 64 Aug 20 15:17 1 -> /dev/pts/3 lrwx------ 1 root root 64 Aug 20 15:17 2 -> /dev/pts/3 lr-x------ 1 root root 64 Aug 20 15:17 3 -> /path/to/top/level/script lr-x------ 1 root root 64 Aug 20 15:17 4 -> /path/to/sourced/SCRIPT1 ... with as many open fds as there are ". SCRIPTn" nest levels. Fix it by closing these fds after fork (only for NOEXEC children). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: bit better comments in redirect code. No logic changesDenys Vlasenko2016-08-201-11/+38
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: `cmd` and arithmetic also need the fix for FILE rewindDenys Vlasenko2016-08-191-32/+39
| | | | | | Discovered by running testsuite with a newest glibc Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix a bug in FEATURE_SH_STANDALONE=y config. Closes 9186Denys Vlasenko2016-08-191-3/+20
| | | | | | | | | | | | | | | | | | | | | Run this in a "sh SCRIPT": sha256sum /dev/null echo END sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s. By this time, entire script is read, and buffered in a FILE object from fopen("SCRIPT"). But fgetc() did not consume entire input. exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'. (this may be libc-specific). This change of fd position *is shared with the parent*! Now parent can read more, and it thinks there is another "echo END". End result: two "echo END"s are run. Fix this by _exit()ing instead. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix a possible bugDenys Vlasenko2016-07-211-1/+3
| | | | | | Not sure this was actually a triggerable bug, but the code looked flaky. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: code shrinkDenys Vlasenko2015-10-111-4/+1
| | | | | | | function old new delta builtin_wait 347 328 -19 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>