aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
* ash: reduce size of forkshell relocation blockRon Yorston2024-01-151-12/+12
| | | | | | | | | | | | The forkshell relocation block had one byte for each byte of the forkshell structure and funcblock. It's only necessary to allow one byte for each pointer. (One or two bits would be enough, but would make the code more complex.) The impact of this change depends on the data and whether the CPU is 32- or 64-bit. It typically saves a few Kbytes. Costs 16-52 bytes.
* ash: code shrink forkshell debugRon Yorston2024-01-151-6/+0
| | | | | | | | Remove a check that there are no relocations for addresses in the funcstring block. At one point during development the relocation block had entries for that area, but not any more. This only affects non-default builds with forkshell debug enabled.
* ash: add more checks to forkshell debugRon Yorston2024-01-141-15/+36
| | | | | | Rearrange the handling of pointer relocation during forkshell and add a couple of additional sanity checks. There's no functional change to non-debug builds.
* ash: special case in creation of pipelineRon Yorston2024-01-141-1/+3
| | | | | | | | | | | | | When a pipeline is created the parent allocates an array of procstat structures sufficient for the number of members of the pipeline. The child processes, however, only see the number of processes created so far. Thus, the first child sees that a procstat array has been created but contains no processes. This resulted in an invalid pointer to the procstat array in the first child. This probably doesn't matter: if the number of processes is zero there should be no need to access the array. Set the pointer to NULL so if it is accessed we'll know about it.
* win32: make the clang build less crashyRon Yorston2024-01-031-6/+2
| | | | | | | | | | | | | busybox-w32 binaries built using clang crashed so frequently that they were pretty much unusable. The main issue seems to be with assignments to the structures containing global variables which are used in most applets. Upstream commit 5156b2455 (Make const ptr assign as function call in clang) addresses this, but is insufficient for the build on Windows. Extend the idea to the ASSIGN_CONST_PTR() macro too. Costs 32-80 bytes in the gcc build.
* ash: avoid crash when job table is emptyRon Yorston2023-12-251-6/+8
| | | | | | | | | | | | | | | Commit 7b692ddf0 (ash: improved support for jobs built-in) didn't correctly initialise the pointer to the job table if it was empty. This resulted in the following crashing: sh -c "cat <(echo HelloWorld | rev)" Fix forkshell_copy() so the job table pointer is NULL if there are no jobs. Adds 16 bytes. (GitHub issue #379)
* win32: code shrink applet overridesRon Yorston2023-12-101-45/+4
| | | | | | | | Pass the PATH to be used to look up executables down from the shell to the applet override code. This replaces the use of a static variable and a function to fetch its value. Saves 16-32 bytes.
* Merge branch 'busybox' into mergeFRP-5236-g7dff7f376Ron Yorston2023-12-051-8/+0
|\
| * 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>
* | ash: add options to control globbing of hidden filesRon Yorston2023-09-201-8/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add shell options: - 'nohiddenglob' excludes files with the hidden attribute from globbing - 'nohidsysglob' excludes files with the hidden and system attributes from globbing If both options are enabled 'nohiddenglob' takes precedence. These options also affect tab completion. Files that are hidden because they start with a period aren't affected (unless they also have the hidden attribute). Costs 160-208 bytes. (GitHub issue #367)
* | win32: convert exit codesRon Yorston2023-09-141-13/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add two utility functions to convert Windows process exit codes. - exit_code_to_wait_status() converts to a POSIX wait status. This is used in ash and the implementations of system(3) and mingw_wait3(). - exit_code_to_posix() converts to a POSIX exit code. (Not that POSIX has much to say about them.) As a result it's possible for more applets to report when child processes are killed as if by a signal. 'time', 'drop' and 'su -W', for example. Adds 64-80 bytes.
* | ash: fix signal handlingRon Yorston2023-09-131-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 89aa9d783 (win32: changes to signal handling) caused a regression: 'httpd -f' could no longer be interrupted by Ctrl-C. The specific issue is the use of exit(2) to replace raise(3) in raise_interrupt(). This change was made so the shell would return the expected exit code of 130 rather than the default code of 3 which Windows uses when a signal with SIG_DFL disposition is caught. The problem can be avoided by calling _exit(2) instead. A call to fflush_all() has also been added, as _exit(2) doesn't do that. (GitHub issue #365)
* | ash: initialize basepf.buf in ash (2)Ron Yorston2023-08-311-1/+1
| | | | | | | | | | | | Upstream commit ed4a24dfd (ash: initialize basepf.buf in ash) zeroes out the memory allocated for basepf.buf. busybox-w32 has a copy of this code early in ash_main(). Do the same there.
* | Merge branch 'busybox' into mergeRon Yorston2023-08-311-1/+1
|\|
| * ash: initialize basepf.buf in ashzhuyan2023-08-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | ash: changes to login shell functionalityRon Yorston2023-08-301-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream BusyBox supports the usual Unix functionality where the login process adds a '-' prefix to the shell's argv[0]. Since busybox-w32 doesn't have a login process this serves no purpose and can be removed. Instead it would be useful to have a way to invoke a login shell without requiring any arguments. Advantages would be: - easier to configure busybox-w32 'ash' as the SSH login shell; - double clicking on a shell binary could start a login shell. Add 'lash' as an alias for 'ash' which starts a login shell without requiring the '-l' option. Saves 16 bytes.
* | ash: detect console state on shell start upnoconsole2Ron Yorston2023-08-201-0/+31
| | | | | | | | | | | | | | | | | | | | | | Set 'noconsole' to match the actual state of the console (normal/ iconified) when the shell is started. Thus ShowWindow() will only be called if the actual state differs from the default or user defined state. Costs 20-24 bytes. (GitHub issue #325)
* | ash: detect native Windows environment on WineFRP-5181-g5c1a3b00eRon Yorston2023-08-171-2/+18
| | | | | | | | | | | | | | | | | | | | | | The shell detected a native Windows environment by checking for a mixed-case 'Path' environment variable. This has always worked on Windows but recent versions of Wine have a 'PATH' environment variable. Check also for 'ComSpec'. Costs 24-48 bytes.
* | ash: improved support for trap built-inRon Yorston2023-08-151-9/+23
| | | | | | | | | | | | | | Make it possible to use the 'trap' built-in with command substitution, process substitution and in pipelines. Costs 200-256 bytes.
* | ash: code shrinkRon Yorston2023-08-151-10/+6
| | | | | | | | | | | | | | Move the code to handle the case nprocs == 1 from jobtab_size() to procstat_size(). Saves 16 bytes.
* | ash: improved support for jobs built-inRon Yorston2023-08-081-7/+141
| | | | | | | | | | | | | | | | | | | | Pass job data to child shells. This makes it possible to use the 'jobs' built-in with command substitution, process substitution and in pipelines. Costs 576-672 bytes (GitHub issue #350)
* | Merge branch 'busybox' into mergeRon Yorston2023-07-1378-387/+874
|\|
| * Update applet size estimatesDenys Vlasenko2023-07-103-3/+3
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: tweak comments, no code changesDenys Vlasenko2023-07-101-6/+7
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: remove "volatile" specifier from suppress_intDenys Vlasenko2023-07-101-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * ash: disable sleep as builtin, closes 15619Denys Vlasenko2023-07-101-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * 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-043-11/+17
| | | | | | | | | | | | | | | | | | | | 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/math: avoid $((3**999999999999999999)) to take yearsDenys Vlasenko2023-07-021-3/+14
| | | | | | | | | | | | | | function old new delta arith_apply 991 1030 +39 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: do not accept $((36#@))Denys Vlasenko2023-07-021-16/+22
| | | | | | | | | | | | | | | | | | | | 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>
| * shell/math: code shrinkDenys Vlasenko2023-06-301-4/+7
| | | | | | | | | | | | | | | | | | | | 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>
| * shell/math: code shrinkDenys Vlasenko2023-06-291-11/+13
| | | | | | | | | | | | | | function old new delta arith_apply 1023 996 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: code shrinkDenys Vlasenko2023-06-281-8/+10
| | | | | | | | | | | | | | | | | | | | | | 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>
| * shell/math: improve commentsDenys Vlasenko2023-06-261-2/+4
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: rename TOK_NUM to TOK_VALUE, improve commentsDenys Vlasenko2023-06-261-24/+25
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: bash-compatible handling of too large numbersDenys Vlasenko2023-06-259-44/+118
| | | | | | | | | | | | | | | | | | | | 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>
| * shell/math: disable debug againDenys Vlasenko2023-06-191-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: $((1?)) has one-too-small opstack, fix thisDenys Vlasenko2023-06-191-1/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: fix comments about jammed-together num+num corner casesDenys Vlasenko2023-06-191-8/+16
| | | | | | | | | | | | | | function old new delta evaluate_string 1478 1470 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: add note on ERANGEDenys Vlasenko2023-06-181-4/+11
| | | | | | | | | | | | | | function old new delta evaluate_string 1488 1478 -10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: explain why we use separate &endDenys Vlasenko2023-06-181-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: code shrinkDenys Vlasenko2023-06-181-2/+5
| | | | | | | | | | | | | | function old new delta evaluate_string 1498 1491 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: eliminate redundant endofname()Denys Vlasenko2023-06-181-8/+8
| | | | | | | | | | | | | | function old new delta evaluate_string 1486 1498 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: typo fix in testsDenys Vlasenko2023-06-182-2/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: code shrinkDenys Vlasenko2023-06-181-11/+12
| | | | | | | | | | | | | | function old new delta evaluate_string 1489 1486 -3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/math: decrease stack usage by not allocating copies of variable namesDenys Vlasenko2023-06-181-32/+51
| | | | | | | | | | | | | | | | | | | | | | | | 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>
| * shell/math: decrease stack usageDenys Vlasenko2023-06-181-35/+27
| | | | | | | | | | | | | | function old new delta evaluate_string 1412 1467 +55 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: move varcmp() to shell_common.h and use it in hushDenys Vlasenko2023-06-174-50/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * ash: code shrinkDenys Vlasenko2023-06-171-1/+1
| | | | | | | | | | | | | | function old new delta setvar 166 164 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>