summaryrefslogtreecommitdiff
path: root/shell
AgeCommit message (Collapse)Author
2024-02-26ash: fix handling of single-quoted strings in pattern substitutionDenys Vlasenko
function old new delta subevalvar 1576 1588 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-25hush: detect when terminating "done"/"fi" is missingDenys Vlasenko
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>
2024-02-25hush: set G.ifs sooner (prevents segfault)Denys Vlasenko
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>
2023-10-02sleep: fix "sleep -- ARGS"Denys Vlasenko
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>
2023-08-31ash: initialize basepf.buf in ashzhuyan
When I planned to print the command in read_line_input, I found that after the system started, the command printed for the first time was always garbled. After analysis, it is found that in the init() function of ash, the variable basepf.buf is not initialized after applying for memory, resulting in garbled initial data. Then assign it to the global variable g_parsefile->buf in ash.c, and then pass g_parsefile->buf to the parameter command of the function read_line_input in the function preadfd(), and finally cause it to be garbled when the command is printed by read_line_input. The call stack is as follows: #0 read_line_input (st=0xb6fff220, prompt=0xb6ffc910 "\\[\\033[32m\\]\\h \\w\\[\\033[m\\] \\$ ", command=command@entry=0xb6ffc230 "P\325\377\266P\325\377\266", maxsize=maxsize@entry=1024) at libbb/lineedit.c:2461 #1 0x0043ef8c in preadfd () at shell/ash.c:10812 #2 preadbuffer () at shell/ash.c:10914 #3 pgetc () at shell/ash.c:10997 #4 0x00440c20 in pgetc_eatbnl () at shell/ash.c:11039 #5 0x00440cbc in xxreadtoken () at shell/ash.c:13157 #6 0x00440f40 in readtoken () at shell/ash.c:13268 #7 0x00441234 in list (nlflag=nlflag@entry=1) at shell/ash.c:11782 #8 0x004420e8 in parsecmd (interact=<optimized out>) at shell/ash.c:13344 #9 0x00442c34 in cmdloop (top=top@entry=1) at shell/ash.c:13549 #10 0x00444e4c in ash_main (argc=<optimized out>, argv=0x444e4c <ash_main+1328>) at shell/ash.c:14747 #11 0x00407954 in run_applet_no_and_exit (applet_no=9, name=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1024 #12 0x00407b68 in run_applet_and_exit (name=0xbefffe56 "ash", argv=0x9) at libbb/appletlib.c:1047 #13 0x00407f88 in main (argc=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1181 Fixes: 82dd14a510ca ("ash: use CONFIG_FEATURE_EDITING_MAX_LEN") Signed-off-by: zhuyan <zhuyan34@huawei.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10Update applet size estimatesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10ash: tweak comments, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10ash: remove "volatile" specifier from suppress_intDenys Vlasenko
function old new delta aliascmd 274 278 +4 signal_handler 81 80 -1 static.redirectsafe 144 141 -3 unwindlocalvars 219 215 -4 trapcmd 333 329 -4 setvar 164 160 -4 setpwd 167 163 -4 setinputfile 216 212 -4 setcmd 76 72 -4 readcmd 221 217 -4 raise_exception 26 22 -4 out2str 37 33 -4 out1str 32 28 -4 freejob 89 85 -4 forkchild 616 612 -4 fg_bgcmd 298 294 -4 expandarg 949 945 -4 evaltree 753 749 -4 evalsubshell 173 169 -4 evalpipe 346 342 -4 evalfun 408 404 -4 cdcmd 699 695 -4 ash_main 1240 1236 -4 __pgetc 589 585 -4 unaliascmd 152 147 -5 unalias 51 46 -5 umaskcmd 253 248 -5 stalloc 97 92 -5 shiftcmd 144 139 -5 setinputstring 73 68 -5 redirect 1068 1063 -5 recordregion 81 76 -5 pushstring 160 155 -5 popstring 120 115 -5 popstackmark 69 64 -5 popredir 123 118 -5 popfile 110 105 -5 out1fmt 45 40 -5 newline_and_flush 39 34 -5 ifsfree 66 61 -5 growstackblock 146 141 -5 freestrings 95 90 -5 fmtstr 59 54 -5 flush_stdout_stderr 23 18 -5 dowait 577 572 -5 delete_cmd_entry 52 47 -5 clearcmdentry 98 93 -5 ash_arith 79 74 -5 argstr 1404 1399 -5 evalcommand 1523 1515 -8 removerecordregions 219 209 -10 mklocal 284 274 -10 find_command 893 883 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/52 up/down: 4/-251) Total: -247 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10ash: disable sleep as builtin, closes 15619Denys Vlasenko
Has a few annoying problems: * sleepcmd() -> sleep_main(), the parsing of bad arguments exits the shell. * sleep_for_duration() in sleep_main() has to be interruptible for ^C traps to work, which may be a problem for other users of sleep_for_duration(). * BUT, if sleep_for_duration() is interruptible, then SIGCHLD interrupts it as well (try "/bin/sleep 1 & sleep 10"). * sleep_main() must not allocate anything as ^C in ash longjmp's. (currently, allocations are only on error paths, in message printing). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-08hush: fix a compile failureDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-04ash: disable check for "good" function name, bash does not check thisDenys Vlasenko
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>
2023-07-03hush: quote values in "readonly" outputDenys Vlasenko
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>
2023-07-02shell/math: avoid $((3**999999999999999999)) to take yearsDenys Vlasenko
function old new delta arith_apply 991 1030 +39 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-02shell/math: do not accept $((36#@))Denys Vlasenko
function old new delta parse_with_base 170 174 +4 arith_apply 996 991 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-5) Total: -1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-30shell/math: code shrinkDenys Vlasenko
function old new delta arith_apply 999 996 -3 evaluate_string 1295 1291 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-7) Total: -7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-29shell/math: code shrinkDenys Vlasenko
function old new delta arith_apply 1023 996 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-28shell/math: code shrinkDenys Vlasenko
function old new delta arith_apply 1015 1023 +8 evaluate_string 1309 1295 -14 .rodata 105344 105321 -23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 8/-37) Total: -29 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-26shell/math: improve commentsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-26shell/math: rename TOK_NUM to TOK_VALUE, improve commentsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-25shell/math: bash-compatible handling of too large numbersDenys Vlasenko
function old new delta parse_with_base - 170 +170 evaluate_string 1477 1309 -168 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 170/-168) Total: 2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19shell/math: disable debug againDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19shell/math: $((1?)) has one-too-small opstack, fix thisDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-19shell/math: fix comments about jammed-together num+num corner casesDenys Vlasenko
function old new delta evaluate_string 1478 1470 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: add note on ERANGEDenys Vlasenko
function old new delta evaluate_string 1488 1478 -10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: explain why we use separate &endDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: code shrinkDenys Vlasenko
function old new delta evaluate_string 1498 1491 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: eliminate redundant endofname()Denys Vlasenko
function old new delta evaluate_string 1486 1498 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell: typo fix in testsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: code shrinkDenys Vlasenko
function old new delta evaluate_string 1489 1486 -3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: decrease stack usage by not allocating copies of variable namesDenys Vlasenko
We risk exhaust stack with alloca() with old code. function old new delta arith_apply 990 1023 +33 evaluate_string 1467 1494 +27 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 60/0) Total: 60 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-18shell/math: decrease stack usageDenys Vlasenko
function old new delta evaluate_string 1412 1467 +55 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17shell: move varcmp() to shell_common.h and use it in hushDenys Vlasenko
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>
2023-06-17ash: code shrinkDenys Vlasenko
function old new delta setvar 166 164 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17shell/read: do not allow empty variable nameDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17shell/math: eliminate some redundant stores on return code pathDenys Vlasenko
function old new delta evaluate_string 1432 1412 -20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17shell/math: change ?: nesting code to not have 63 level nesting limitationDenys Vlasenko
function old new delta evaluate_string 1406 1432 +26 arith 36 29 -7 arith_apply 998 990 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 26/-15) Total: 11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17shell/math.h: update comments, rearrange struct members for smaller codeDenys Vlasenko
function old new delta arith_apply 1000 998 -2 evaluate_string 1414 1406 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17shell/math: code shrinkDenys Vlasenko
function old new delta evaluate_string 1432 1414 -18 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-16shell/math: tweka commentsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-16shell/math: fix ?: to not evaluate not-taken branchesDenys Vlasenko
This fixes ash-arith-arith-ternary1/2.tests function old new delta evaluate_string 1271 1432 +161 arith_apply 968 1000 +32 arith 22 36 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 207/0) Total: 207 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: simplify handling of unary plusDenys Vlasenko
function old new delta evaluate_string 1257 1271 +14 arith_apply 977 968 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-9) Total: 5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: explain the logic, small tweak to make code smallerDenys Vlasenko
function old new delta evaluate_string 1258 1257 -1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: fix order of expansion of variables to numbersDenys Vlasenko
This fixes arith-assign-in-varexp1.tests function old new delta evaluate_string 1132 1258 +126 arith_lookup_val 143 - -143 arith_apply 1132 977 -155 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 126/-298) Total: -172 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell: document another arithmetic discrepancy with bashDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: remove special code to handle a?b?c:d:e, it works without it nowDenys Vlasenko
The "hack" to virtually parenthesize ? EXPR : made this unnecessary. The expression is effectively a?(b?(c):d):e and thus b?c:d is evaluated before continuing with the second : function old new delta evaluate_string 1148 1132 -16 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: fix parsing of ?: and explain why it's parsed that wayDenys Vlasenko
This fixes arith-precedence1.tests. This breaks arith-ternary2.tests again (we now evaluate variables on not-taken branches). We need a better logic here anyway: not only bare variables should not evaluate when not-taken: 1 ? eval_me : do_not_eval but any (arbitrarily complex) expressions shouldn't evaluate as well! 1 ? var_is_set=1 : ((var_is_not_set=2,var2*=4)) function old new delta evaluate_string 1097 1148 +51 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-15shell/math: simpler insertion of "fake" last RPARENDenys Vlasenko
Skip one pass through token table, since we know the result. function old new delta evaluate_string 1095 1097 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14shell: sync ash/hush test scriptsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14shell/math: trivial code shrinkDenys Vlasenko
function old new delta arith_apply 1143 1132 -11 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-14shell/math: fix the order of variable resolution in binopsDenys Vlasenko
function old new delta arith_apply 1134 1143 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>