summaryrefslogtreecommitdiff
path: root/shell/hush.c
AgeCommit message (Collapse)Author
2016-10-01hush: 'return' should have effect earlierDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30hush: enable "msh is deprecated" message in msh stubDenys Vlasenko
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>
2016-09-30hush: fix typo in commentDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30hush: fix interactive input handling of backslash+newlineDenys Vlasenko
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>
2016-09-29hush: G.user_input_buf[] is needed only if line editing is enabledDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29hush: speed optimizationsDenys Vlasenko
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>
2016-09-29hush: fix handling of by backslash-newline in $((arith)) and $(cmd)Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29hush: rework input char buffering to allow more than one-deep peekDenys Vlasenko
...this time with actual hush.c changes too :) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29hush: fix 'eval ""' handlingDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29hush: fix ". EMPTY_LINE" not setting $? to 0Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-20hush: document better where bad redirect syntax is detectedDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22hush: fix "redirects can close script fd" bugDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-20hush: do not leak script fds into NOEXEC childrenDenys Vlasenko
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>
2016-08-20hush: bit better comments in redirect code. No logic changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-19hush: `cmd` and arithmetic also need the fix for FILE rewindDenys Vlasenko
Discovered by running testsuite with a newest glibc Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-19hush: fix a bug in FEATURE_SH_STANDALONE=y config. Closes 9186Denys Vlasenko
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>
2016-07-21hush: fix a possible bugDenys Vlasenko
Not sure this was actually a triggerable bug, but the code looked flaky. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-11hush: code shrinkDenys Vlasenko
function old new delta builtin_wait 347 328 -19 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09remove global "jmp_buf die_jmp" from !FEATURE_PREFER_APPLETS buildsDenys Vlasenko
function old new delta xfunc_has_died - 21 +21 sleep_much - 12 +12 sleep10 - 9 +9 die_func - 4 +4 fflush_stdout_and_exit 35 36 +1 builtin_type 121 119 -2 die_sleep 4 - -4 xfunc_die 60 24 -36 hush_main 1128 1011 -117 die_jmp 156 - -156 ------------------------------------------------------------------------------ (add/remove: 4/2 grow/shrink: 1/3 up/down: 47/-315) Total: -268 bytes text data bss dec hex filename 939992 992 17652 958636 ea0ac busybox_old 939880 992 17496 958368 e9fa0 busybox_unstripped 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-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-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-09-04hush: fix a nommu bug where a part of function body is lost if run in a pipeDenys Vlasenko
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-25typo fixesManinder Singh
Signed-off-by: Maninder Singh <maninder1.s@samsung.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12libbb: introduce and use is_prefixed_with()Denys Vlasenko
function old new delta is_prefixed_with - 18 +18 complete_username 78 77 -1 man_main 737 735 -2 fsck_device 429 427 -2 unpack_ar_archive 80 76 -4 strip_unsafe_prefix 105 101 -4 singlemount 1054 1050 -4 rtc_adjtime_is_utc 90 86 -4 resolve_mount_spec 88 84 -4 parse_one_line 1029 1025 -4 parse_conf 1460 1456 -4 may_wakeup 83 79 -4 loadkmap_main 219 215 -4 get_irqs_from_stat 103 99 -4 get_header_cpio 913 909 -4 findfs_main 79 75 -4 fbsplash_main 1230 1226 -4 load_crontab 776 771 -5 expand_vars_to_list 1151 1146 -5 date_main 881 876 -5 skip_dev_pfx 30 24 -6 make_device 2199 2193 -6 complete_cmd_dir_file 773 767 -6 run_applet_and_exit 715 708 -7 uudecode_main 321 313 -8 pwdx_main 197 189 -8 execute 568 560 -8 i2cdetect_main 1186 1176 -10 procps_scan 1242 1230 -12 procps_read_smaps 1017 1005 -12 process_module 746 734 -12 patch_main 1903 1891 -12 nfsmount 3572 3560 -12 stack_machine 126 112 -14 process_timer_stats 449 435 -14 match_fstype 111 97 -14 do_ipaddr 1344 1330 -14 open_list_and_close 359 343 -16 get_header_tar 1795 1779 -16 prepend_new_eth_table 340 323 -17 fsck_main 1811 1794 -17 find_iface_state 56 38 -18 dnsd_main 1321 1303 -18 base_device 179 158 -21 find_keyword 104 82 -22 handle_incoming_and_exit 2785 2762 -23 parse_and_put_prompt 774 746 -28 modinfo 347 317 -30 find_action 204 171 -33 update_passwd 1470 1436 -34 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/49 up/down: 18/-540) Total: -522 bytes 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-08-13hush: make ${#var} unicode-awareDenys Vlasenko
This mimics bash 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>
2014-03-14hush: make "true" built-inDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-11-28hush: typo fixes in commentsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-07-08typo fix in commentDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-07-05unicode: check $LC_CTYPE too to detect Unicode modeDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-07-02unicode: check $LC_ALL to detect Unicode mode, not only $LANGDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-05-12hush: fix build failure if FEATURE_EDITING=y && !HUSH_INTERACTIVEDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-04-07ash,hush: history builtinFlemming Madsen
function old new delta show_history - 39 +39 builtin_history - 16 +16 historycmd - 13 +13 bltins1 312 324 +12 builtintab 336 344 +8 popstring 134 140 +6 hush_main 1048 1046 -2 ash_main 1398 1396 -2 size_from_HISTFILESIZE 44 40 -4 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 3/3 up/down: 94/-8) Total: 86 bytes Signed-off-by: Flemming Madsen <busybox@themadsens.dk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-04-07hush: fix for "while false && true; do echo BUG; break; done". closes 6170Denys Vlasenko
function old new delta run_list 959 941 -18 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-03-17hush: source builtin should override $N only if it has argsDenys Vlasenko
function old new delta builtin_source 174 184 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-01-15whitespace fixes. no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2013-01-14whitespace cleanup. no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-04-26hush: remove sighandler_t definition hack, platform.h has it tooDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-04-20fix build breakage found by randconfigDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2012-03-27hush: remove unused member struct command::is_stoppedDenys Vlasenko
function old new delta builtin_umask 133 132 -1 checkjobs 551 544 -7 builtin_fg_bg 291 267 -24 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-04lineedit: remove SAVE_HISTORY bit, ->hist_file can be used as indicatorDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-04lineedit: add support for history saving on exitDenys Vlasenko
Based on the patch by Dennis Groenen <tj.groenen@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-09-04lineedit: fix atomic replace of history file; hush: fix $HISTFILE handlingDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-08-09randomconfig fixesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-08-01hush: fix remaining known two bugs with IFS expansion. Closes 4027.Denys Vlasenko
function old new delta expand_vars_to_list 1054 1140 +86 parse_stream 2425 2479 +54 expand_on_ifs 258 310 +52 builtin_umask 133 132 -1 done_word 820 779 -41 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/2 up/down: 192/-42) Total: 150 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-08-01hush: partially fix wrong expansion on $IFS (bug 4027).Denys Vlasenko
In the added testcase, before patch we failed 8 out of 9 tests, now we fail only 2 (4th and 5th). function old new delta expand_on_ifs 225 258 +33 expand_vars_to_list 1038 1054 +16 o_save_ptr_helper 115 119 +4 builtin_umask 132 133 +1 o_addQstr 165 161 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 54/-4) Total: 50 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2011-06-01hush: better comment. No code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>