aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* hush: fix G.argv0_for_re_execing to avoid endless loopHajime Tazaki2024-12-091-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | When the busybox is used as /sbin/init and the inittab file contains below: ::respawn:-/bin/sh /sbin/init spawns hush for the first time with the argv[0] contains '-', and hush treats it as login shell. Then it reads /etc/profile and if the file contains the command execution like below, it invokes hush as login shell because the argv[0] argument is still '-/bin/sh' and reads /etc/profile again. This will last until some failure (e.g., memory failure) happens. [ "$(id -u)" -eq 0 ] && PS1="${PS1}# " || PS1="${PS1}\$ " This commit fixes this issues by adding an offset (+1) to the G.argv0_for_re_execing variable. This issue happens on our out-of-tree UML (use mode linux) with nommu configuration. Link: https://lore.kernel.org/all/cover.1731290567.git.thehajime@gmail.com/ Signed-off-by: Hajime Tazaki <thehajime@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: modify find_executable() to not temporarily write to PATHDenys Vlasenko2024-10-081-21/+14
| | | | | | | | | | | | | This allows to simplify "which" applet code function old new delta find_executable 93 111 +18 which_main 191 177 -14 builtin_source 316 294 -22 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 18/-36) Total: -18 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix "type ./cat" and "command -v ./cat" to not scan PATHDenys Vlasenko2024-10-071-13/+33
| | | | | | | | | | | | function old new delta find_executable_in_PATH - 67 +67 if_command_vV_print_and_exit 114 116 +2 .rodata 105712 105710 -2 builtin_type 137 128 -9 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/2 up/down: 69/-11) Total: 58 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: make "test -x" use cached groupinfoDenys Vlasenko2024-10-071-7/+22
| | | | | | | | | | | | | | | | While at it, correct "type" to skip non-executable files in PATH function old new delta builtin_source 211 316 +105 builtin_test 10 32 +22 hush_main 1150 1170 +20 builtin_type 122 137 +15 if_command_vV_print_and_exit 120 114 -6 find_in_path 131 - -131 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 4/1 up/down: 162/-137) Total: 25 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: whitespace and comment fixesDenys Vlasenko2024-09-281-43/+27
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: do not exit interactive shell on some redirection errorsDenys Vlasenko2024-07-131-12/+39
| | | | | | | | | | | | | | | | | | | | $ echo >&99 hush: dup2(99,1): Bad file descriptor $ echo >&9999 hush: fcntl(1,F_DUPFD,10000): Invalid argument $ echo 2>/dev/tty 10>&9999 hush: fcntl(10,F_DUPFD,10000): Invalid argument $ still alive!_ function old new delta static.setup_redirects 334 394 +60 .rodata 105661 105712 +51 dup_CLOEXEC 49 79 +30 save_fd_on_redirect 263 277 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 155/0) Total: 155 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix "exec 3>FILE" aborting if 3 is exactly the next free fdDenys Vlasenko2024-07-131-4/+9
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: avoid duplicate fcntl(F_SETFD, FD_CLOEXEC) during initDenys Vlasenko2024-07-131-8/+3
| | | | | | | function old new delta hush_main 1149 1150 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: detect when terminating "done"/"fi" is missingDenys Vlasenko2024-02-251-1/+10
| | | | | | | | | | function old new delta parse_stream 2271 2292 +21 .rodata 105408 105427 +19 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 40/0) Total: 40 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: set G.ifs sooner (prevents segfault)Denys Vlasenko2024-02-251-28/+34
| | | | | | | | | | | function old new delta set_G_ifs - 151 +151 run_list 1024 1031 +7 run_pipe 1567 1445 -122 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 158/-122) Total: 36 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* sleep: fix "sleep -- ARGS"Denys Vlasenko2023-10-021-8/+0
| | | | | | | | | | | function old new delta sleep_main 116 119 +3 printf_main 860 837 -23 single_argv 50 25 -25 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-48) Total: -45 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Update applet size estimatesDenys Vlasenko2023-07-101-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix a compile failureDenys Vlasenko2023-07-081-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash: disable check for "good" function name, bash does not check thisDenys Vlasenko2023-07-041-1/+6
| | | | | | | | | | function old new delta .rodata 105304 105261 -43 parse_command 1696 1633 -63 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-106) Total: -106 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: quote values in "readonly" outputDenys Vlasenko2023-07-031-4/+11
| | | | | | | | | | | function old new delta builtin_readonly 61 107 +46 builtin_export 140 145 +5 .rodata 105321 105304 -17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 51/-17) Total: 34 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: move varcmp() to shell_common.h and use it in hushDenys Vlasenko2023-06-171-26/+16
| | | | | | | | | | | | | | | | | | | function old new delta unset_local_var - 112 +112 findvar 31 35 +4 set_vars_and_save_old 144 141 -3 helper_export_local 235 230 -5 set_local_var 425 416 -9 handle_changed_special_names 38 27 -11 builtin_unset 154 141 -13 builtin_getopts 404 391 -13 get_local_var_value 281 260 -21 get_ptr_to_local_var 71 45 -26 unset_local_var_len 139 - -139 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/8 up/down: 116/-240) Total: -124 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix expansion of space in "a=${a:+$a }c" constructDenys Vlasenko2023-06-121-1/+1
| | | | | | | function old new delta encode_then_append_var_plusminus 554 552 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: make "false" built-inDenys Vlasenko2023-05-251-0/+7
| | | | | | | | | | function old new delta bltins1 384 396 +12 builtin_false - 6 +6 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 18/0) Total: 18 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix ELIF cmd1;cmd2 THEN ... not executing cmd2, closes 15571Denys Vlasenko2023-05-251-8/+16
| | | | | | | function old new delta run_list 1012 1024 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add comment about abort on syntax error %{^}Denys Vlasenko2023-05-091-0/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix an interactive abort on errorDenys Vlasenko2023-05-081-0/+8
| | | | | | | function old new delta parse_and_run_stream 140 155 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: tab completion of functions and aliasesRon Yorston2023-04-161-2/+12
| | | | | | | | | | | | | | | | | | | | | | Since commit 9e2a5668f (ash,hush: allow builtins to be tab-completed, closes 7532) ash and hush have supported tab completion of builtins. Other shells, bash and ksh for example, also support tab completion of functions and aliases. Add such support to ash and hush. function old new delta ash_command_name - 92 +92 hush_command_name - 63 +63 ash_builtin_name 17 - -17 hush_builtin_name 38 - -38 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 0/0 up/down: 169/-55) Total: 100 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Avi Halachmi <avihpit@yahoo.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: quote variable values printed by "set" (match ash behavior)Denys Vlasenko2023-04-131-2/+17
| | | | | | | function old new delta builtin_set 258 301 +43 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush (NOMMU): fix LINENO in execed childrenDenys Vlasenko2023-04-011-0/+15
| | | | | | | | | | | function old new delta hush_main 1815 1851 +36 re_execute_shell 601 635 +34 .rodata 102721 102726 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 75/0) Total: 75 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: speed up "big heredoc" codeDenys Vlasenko2023-04-011-7/+15
| | | | | | | | | | function old new delta hush_main 1810 1815 +5 .rodata 102723 102721 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-2) Total: 3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add TODO commentDenys Vlasenko2023-04-011-0/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: restore SIGHUP handling, this time explain why we do what we doDenys Vlasenko2023-01-301-20/+28
| | | | | | | function old new delta check_and_run_traps 229 278 +49 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: restore tty pgrp on SIGHUPDenys Vlasenko2023-01-301-5/+8
| | | | | | | | | | | | | Found one case where SIGHUP does need some handling. ash does not restore tty pgrp when killed by SIGHUP, and this means process which started ash needs to restore it, or it would get backgrounded when trying to use tty. function old new delta check_and_run_traps 214 229 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: remove special handling of SIGHUPDenys Vlasenko2023-01-301-18/+20
| | | | | | | | | | Kernel should do the right thing. (ash and dash do not have special SIGHUP handling.) function old new delta check_and_run_traps 278 214 -64 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256Denys Vlasenko2023-01-261-2/+8
| | | | | | | | | | function old new delta record_pending_signo 32 63 +31 lineedit_read_key 231 224 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 31/-7) Total: 24 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: code shrinkDenys Vlasenko2023-01-031-4/+9
| | | | | | | function old new delta run_list 1032 1012 -20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: fix compile failures in some configsDenys Vlasenko2023-01-031-1/+5
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: use HOME for tab completion and promptsRon Yorston2022-06-261-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | ash and hush correctly use the value of HOME for tilde expansion. However the line editing code in libbb obtains the user's home directory by calling getpwuid(). Thus tildes in tab completion and prompts may be interpreted differently than in tilde expansion. When the line editing code is invoked from a shell make it use the shell's interpretation of tilde. This is similar to how GNU readline and bash collaborate. function old new delta get_homedir_or_NULL 29 72 +43 optschanged 119 126 +7 hush_main 1204 1211 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 57/0) Total: 57 bytes v2: Always check for HOME before trying the password database: this is what GNU readline does. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* *: slap on a few ALIGN_PTR where appropriateDenys Vlasenko2022-02-061-5/+5
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* ash,hush: fix handling of SIGINT while waiting for interactive inputDenys Vlasenko2022-01-171-20/+47
| | | | | | | | | | | | | | | | function old new delta lineedit_read_key 160 237 +77 __pgetc 522 589 +67 fgetc_interactive 244 309 +65 safe_read_key - 39 +39 read_key 588 607 +19 record_pending_signo 23 32 +9 signal_handler 75 81 +6 .rodata 104312 104309 -3 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 6/1 up/down: 282/-3) Total: 279 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> SETUP_ENV_CHDIRDenys Vlasenko2022-01-131-1/+1
| | | | | | | | | | | | Double negatives are hard to grok. function old new delta login_main 986 988 +2 su_main 474 470 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-4) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: code shrink: introduce and use [_]exit_SUCCESS()Denys Vlasenko2022-01-051-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta exit_SUCCESS - 7 +7 _exit_SUCCESS - 7 +7 run_pipe 1562 1567 +5 pseudo_exec_argv 399 400 +1 finish 86 87 +1 start_stop_daemon_main 1109 1107 -2 shutdown_on_signal 38 36 -2 runsv_main 1662 1660 -2 redirect 1070 1068 -2 read_line 79 77 -2 pause_and_low_level_reboot 54 52 -2 list_i2c_busses_and_exit 483 481 -2 less_exit 12 10 -2 identify 4123 4121 -2 grep_file 1161 1159 -2 getty_main 1519 1517 -2 fsck_minix_main 2681 2679 -2 free_session 132 130 -2 fdisk_main 4739 4737 -2 clean_up_and_exit 53 51 -2 bsd_select 1566 1564 -2 bb_daemonize_or_rexec 198 196 -2 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 3/17 up/down: 21/-34) Total: -13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: tweak --helpDenys Vlasenko2021-10-131-1/+1
| | | | | | | | Even though formally it is -s [ARGS], "sh -s" without ARGS is the same as just "sh". And we are already over 80 chars wide for ash --help, so make it shorter. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: in a comment, document what -i might be doingDenys Vlasenko2021-10-131-3/+26
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* shell: use more compact SHELL_ASH / HUSH config defines. no code changesDenys Vlasenko2021-10-121-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* *: add NOINLINEs where code noticeably shrinksDenys Vlasenko2021-10-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta display 85 1463 +1378 -73 bytes select_and_cluster - 1088 +1088 -139 bytes parse_reply - 979 +979 -109 bytes zbc_num_sqrt - 632 +632 -191 bytes show_bridge_port - 585 +585 -56 bytes sp_256_proj_point_add_8 - 576 +576 -45 bytes encode_then_append_var_plusminus - 554 +554 -118 bytes read_mode_db - 537 +537 -47 bytes fbset_main 1331 747 -584 sp_256_ecc_mulmod_8 1157 536 -621 brctl_main 2189 1548 -641 expand_one_var 2544 1872 -672 zxc_vm_process 6412 5589 -823 send_queries 1813 725 -1088 recv_and_process_peer_pkt 2245 1018 -1227 bb_dump_dump 1531 80 -1451 ------------------------------------------------------------------------------ (add/remove: 7/0 grow/shrink: 1/8 up/down: 6329/-7107) Total: -778 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: speed up ${x//\*/|} tooDenys Vlasenko2021-10-091-4/+9
| | | | | | | function old new delta expand_one_var 2502 2544 +42 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix var_LINENO3.tests failureDenys Vlasenko2021-09-071-2/+8
| | | | | | | | | | function old new delta parse_and_run_string 40 62 +22 i_getch 105 102 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 22/-3) Total: 19 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix set -n to act immediately, not just after run_list()Denys Vlasenko2021-09-071-2/+6
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix "error: invalid preprocessing directive ##"Denys Vlasenko2021-08-151-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: tweak ${var/pattern/repl} optimizationDenys Vlasenko2021-07-271-5/+4
| | | | | | | function old new delta expand_one_var 2507 2502 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: optimize ${var/pattern/repl} for trivial patternsDenys Vlasenko2021-07-271-0/+13
| | | | | | | function old new delta expand_one_var 2353 2507 +154 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: add missed "undef"Denys Vlasenko2021-07-271-3/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: implement $'str' bashismDenys Vlasenko2021-07-261-1/+102
| | | | | | | | | | | function old new delta parse_dollar_squote - 441 +441 encode_then_expand_vararg 359 380 +21 parse_stream 2252 2271 +19 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 481/0) Total: 481 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* hush: fix bkslash+newline handling and number validation in ${NN} and ${#NN}Denys Vlasenko2021-06-191-1/+27
| | | | | | | | | | | | | Entering "${1a}" into interactive shell was making it exit. function old new delta parse_dollar 824 958 +134 i_getch_and_eat_bkslash_nl - 44 +44 parse_expr 917 938 +21 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 199/0) Total: 199 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>