aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
* ash: allow execution of busybox-w32 binary without extensionRon Yorston2026-02-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | If the busybox-w32 binary didn't have an extension the shell was unable to spawn itself: $ ls -l busybox -rwxrwxr-x 1 rmy rmy 661006 Feb 25 09:37 busybox $ ./busybox sh $ ls sh: unable to spawn shell This happened because the shell used spawnve() from the C runtime to execute itself. Microsoft insists on trying to add an extension to the name of the binary unless it has an explicit '.' as its last character. Use the internal spawnveq() instead, as it handles various quirks like the above. Adds 16-32 bytes. (GitHub issue #566)
* ash: fix execution of applets via Unix-style pathRon Yorston2026-02-141-18/+15
| | | | | | | | | Merging of upstream changes to ash failed to ensure that applets could be executed using a Unix-style path. Move the necessary code from shellexec() to tryexec(). (GitHub issue #565)
* Merge branch 'busybox' into mergeRon Yorston2026-02-122-5/+2
|\
| * *: use is_prefixed_with() where appropriateDenys Vlasenko2026-02-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | function old new delta resume_main 560 556 -4 uuidcache_check_device 107 101 -6 ntp_init 1005 997 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-18) Total: -18 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * *: use xasprintf_inplace() in more placesDenys Vlasenko2026-02-061-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta .rodata 107009 107018 +9 parse_stream 3075 3069 -6 buffer_print 612 603 -9 expand_args 159 144 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 9/-30) Total: -21 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: fix help builtin and tab completion of builtinsRon Yorston2026-02-091-0/+8
| | | | | | | | | | | | | | | | | | | | | | Commit 56143ea63 (ash: code shrink: eliminate pstrcmp1()) changed the layout of struct builtincmd so the name member points to the start of the name, not the flag in the first element of the string. This broke the help builtin and tab completion of builtins. Remove the unnecessary '+ 1' in ash_command_name() and helpcmd(). This patch has been submitted upstream.
* | Merge branch 'busybox' into mergeRon Yorston2026-02-091-1281/+1366
|\|
| * ash: fix \ooo octal printout in DEBUG codeDenys Vlasenko2026-01-281-16/+12
| | | | | | | | | | | | | | function old new delta ash_main 1624 1645 +21 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: code shrink: eliminate pstrcmp1()Denys Vlasenko2026-01-281-66/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta find_command 961 963 +2 evalcommand 1631 1633 +2 hashcmd 299 300 +1 describe_command 320 321 +1 clearcmdentry 93 94 +1 cdcmd 695 696 +1 pstrcmp1 16 - -16 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 6/0 up/down: 8/-16) Total: -8 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: remove non-standard chdir builtinDenys Vlasenko2026-01-281-17/+14
| | | | | | | | | | | | | | | | | | | | function old new delta .rodata 106853 106846 -7 builtintab 352 344 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-15) Total: -15 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: get rid of a static in cmdlookup()/delete_cmd_entry()Denys Vlasenko2026-01-281-26/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta cmdlookup_pp - 120 +120 find_command 953 961 +8 unsetcmd 74 76 +2 hashcmd 297 299 +2 lastcmdentry 4 - -4 delete_cmd_entry 47 43 -4 cmdlookup 132 - -132 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 3/1 up/down: 132/-140) Total: -8 bytes text data bss dec hex filename 47470 8 149 47627 ba0b shell/ash.o.orig 47466 8 145 47619 ba03 shell/ash.o Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: group command hashing/searching code together, no code changesDenys Vlasenko2026-01-281-346/+351
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: move casematch() directly to its only caller, no code changesDenys Vlasenko2026-01-271-31/+36
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: reorder functions to reduce forward declarations, no code changesDenys Vlasenko2026-01-271-165/+156
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: JOBSTOPPED can only be set if job control is compiled in - ↵Denys Vlasenko2026-01-271-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | conditionalize code which depends on it With !ASH_JOB_CONTROL: function old new delta cmdloop 363 351 -12 exitcmd 47 31 -16 .rodata 106422 106398 -24 stoppedjobs 58 - -58 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-110) Total: -110 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: reorder functions to reduce forward declarations, no code changesDenys Vlasenko2026-01-271-450/+453
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: move applet handling out of tryexec() - making it similar to dashDenys Vlasenko2026-01-271-62/+61
| | | | | | | | | | | | | | | | | | | | function old new delta tryexec - 60 +60 shellexec 476 349 -127 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 60/-127) Total: -67 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: unset traps before entering NOEXEC programs after [v]forkDenys Vlasenko2026-01-271-7/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we don't do that, if INT trap was set, ^C will set a flag "run trap later" and _return_, which is not expected by the NOFORK! function old new delta clear_traps - 107 +107 evalcommand 1617 1631 +14 shellexec 471 476 +5 setsignal 333 327 -6 forkchild 620 480 -140 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 126/-146) Total: -20 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2026-02-042-5/+17
|\|
| * ash: code shrinkDenys Vlasenko2026-01-241-0/+4
| | | | | | | | | | | | | | | | | | | | function old new delta fg_bgcmd 294 296 +2 killpg 43 - -43 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 1/0 up/down: 2/-43) Total: -41 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: allow 0x in arith (bash supports it for 0x$v case when v='')Denys Vlasenko2026-01-241-5/+13
| | | | | | | | | | | | | | function old new delta parse_with_base 174 196 +22 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: remove unnecessary conditional compilationRon Yorston2026-01-301-4/+0
| | | | | | | | | | | | | | | | Additional support for background jobs was added in commits 010abea6f and 1403d81c4. The condition ENABLE_PLATFORM_POSIX || JOBS_WIN32 in showjob() is always true. The conditional compilation can be removed.
* | ash: don't skip exec() if std streams are invalidRon Yorston2026-01-291-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This didn't produce the expected output when run from ash: ash -c "echo abc | sed s/a/x/" <&- In general, if the last command in the pipe read from stdin the command didn't work; if it read from file descriptor 0 (e.g. cat) it did. Closing a file descriptor caused the corresponding stream to become invalid. For performance reasons the shell in busybox-w32 runs applets without an exec(), but that results in their seeing the invalid stream from their parent. Avoid the problem by calling exec() in such cases. This causes the child process to get a new stdin stream initialised from the file descriptor. The test also applies to stdout and stderr. There's no discernable affect on performance when running the test suite. Adds 64-96 bytes. (GitHub issue #558)
* | ash: don't display ^C twiceRon Yorston2026-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | Since commit f7bcc977c (ash: make ctrl-c trap handling closer to upstream) when ctrl-c was entered at an interactive prompt without a 'trap INT' in force, '^C' was echoed to the console twice. Detect this condition and avoid the duplication. Adds 16 bytes.
* | ash: Extend ARM msvcrt workaround to 32 bit ARM tooMartin Storsjö2025-12-081-1/+1
| | | | | | | | | | | | | | | | | | The fact that "environ" is not assignable goes the same for both 32 and 64 bit ARM on msvcrt - this is not an issue on UCRT as noted in c44f23f4acbbd854eccd962110e41343d8f03296. This extends the original workaround from ea8742bc1657cd0aae32ac555560c8228795488f to 32 bit ARM too.
* | ash: allow ctrl-c to interrupt read in minttyRon Yorston2025-11-231-19/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | The command 'read -t 10' couldn't be interrupted by ctrl-c when ash was running in the mintty terminal emulator. This issue was introduced by commits 8e6991733 and b2901ce8e which fixed other problems with the 'read' builtin. Rearrange the code to avoid calling poll(2) in an interactive shell on Windows. (GitHub issue #547)
* | win32: use RtlGenRandom for /dev/urandomRon Yorston2025-10-093-15/+0
| | | | | | | | | | | | | | | | | | Use the (somewhat ancient) Microsoft RtlGenRandom() function to provide random data for /dev/urandom. Saves 176-240 bytes. (GitHub issue #519)
* | ash: output '^C' direct to consoleRon Yorston2025-10-081-1/+1
| | | | | | | | | | | | | | | | | | The '^C' displayed on interrupt should go directly to the console to emulate the typical behaviour of the Unix tty driver. Adds 16 bytes. (GitHub issue #531)
* | ash: output '^C' when wait builtin is interruptedRon Yorston2025-10-061-3/+13
| | | | | | | | | | | | | | When the wait builtin detects an interrupt it should print '^C' to stdout, as is done in other similar cases. Saves 16 bytes in the 64-bit build.
* | Merge branch 'busybox' into mergeRon Yorston2025-10-061-7/+3
|\|
| * ash: change procargs() to match recent dash changeDenys Vlasenko2025-09-231-7/+3
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: allow ctrl-c to interrupt wait in presence of trapRon Yorston2025-10-051-4/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit 387d01161 (ash: allow wait builtin to be interrupted) allowed the wait builtin to be interrupted by ctrl-c. However, this didn't work in the presence of a trap. When waitpid_child() detects an interrupt propagate this up the call stack so the wait builtin terminates and the trap is invoked. Adds 80-88 bytes. (GitHub issue #530)
* | ash: make ctrl-c trap handling closer to upstreamRon Yorston2025-10-051-12/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit 64c8f5f3d0 (ash: add support for INT trap) didn't follow upstream behaviour. If a trap is supplied for SIGINT, upstream's signal handler detects this and doesn't call raise_interrupt(). The busybox-w32 implementation called raise_interrupt() but had it do nothing. Modify the code to match upstream's behaviour. Saves 16-36 bytes.
* | ash: allow wait builtin to be interruptedRon Yorston2025-10-031-11/+12
| | | | | | | | | | | | | | | | | | | | | | | | After commit f6be217fa (ash: wait builtin should block) it wasn't possible to interrupt a call to wait with Ctrl-C. A blocking wait should be stopped from time to time to check for an interrupt. Adds 32 bytes. (GitHub issue #529)
* | ash: wait builtin should blockRon Yorston2025-10-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It was found that the 'wait' shell builtin would use 100% of a core when waiting for a process to terminate: sleep 60 & wait This is a regression caused by commit bb8f6b688 (ash: fix slow running when background job is present). See the commit message and GitHub issue #434 for the long and involved history. The problem is in the Windows implementation of waitproc() in ash. The 'block' argument to waitproc() can take three values: DOWAIT_NONBLOCK DOWAIT_BLOCK DOWAIT_CHILD_OR_SIG The first two have obvious meanings. The third performs a non- blocking wait(2) and if no PID is returned it waits for SIGCHLD. So in effect it's a blocking wait. The Windows implementation would perform a non-blocking wait(2) but couldn't then wait for SIGCHLD, because Windows doesn't have such a signal. As a result the 'wait' builtin would loop calling waitproc(). To avoid this DOWAIT_CHILD_OR_SIG should be treated as a blocking wait in waitproc(). (GitHub issue #529)
* | Merge branch 'busybox' into mergeRon Yorston2025-09-114-35/+139
|\|
| * hush: changes to comments and whitespace, no code changesDenys Vlasenko2025-09-031-8/+8
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: implement <<<here_string syntaxDenys Vlasenko2025-09-023-26/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta write2pipe - 133 +133 .rodata 105992 106009 +17 readtoken1 3101 3111 +10 cmdtxt 631 641 +10 nodesize 27 28 +1 redirect 961 916 -45 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/1 up/down: 171/-45) Total: 126 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2025-09-1156-729/+1536
|\|
| * hush: fix several syntax corner cases with function definitionsDenys Vlasenko2025-08-189-2/+37
| | | | | | | | | | | | | | | | | | | | function old new delta parse_stream 3063 3075 +12 done_word 777 784 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 19/0) Total: 19 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: shrink "function" codeDenys Vlasenko2025-08-181-11/+11
| | | | | | | | | | | | | | | | | | | | | | function old new delta done_word 766 777 +11 static.reserved_match 16 12 -4 reserved_list 240 168 -72 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 11/-76) Total: -65 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: do not SEGV on if { echo foo; } then { echo bar; } fiDenys Vlasenko2025-08-181-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | For some reason, it was only happening in interactive use function old new delta initialize_context 39 54 +15 parse_stream 3077 3063 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 15/-14) Total: 1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: disentangle keyword detection, no logic changesDenys Vlasenko2025-08-181-25/+27
| | | | | | | | | | | | | | function old new delta done_word 790 766 -24 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: make "function" keyword support optionalDenys Vlasenko2025-08-171-11/+22
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: with --login, errors /etc/profile in must not exit shellDenys Vlasenko2025-08-171-3/+8
| | | | | | | | | | | | | | | | | | | | | | function old new delta die_if_script 28 34 +6 hush_main 1146 1150 +4 run_list 1031 1028 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 10/-3) Total: 7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: recognize "function FUNC { cmd; }" syntaxDenys Vlasenko2025-08-171-43/+103
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta reserved_list - 240 +240 parse_stream 2923 3077 +154 done_word 771 790 +19 .rodata 105975 105992 +17 static.reserved_match 12 16 +4 static.reserved_list 168 - -168 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 4/0 up/down: 434/-168) Total: 266 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: remove always-true conditionalDenys Vlasenko2025-08-171-1/+0
| | | | | | | | | | | | | | function old new delta parse_stream 2940 2923 -17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix infinite loop expanding alias a="nice&&a"Denys Vlasenko2025-08-171-6/+45
| | | | | | | | | | | | | | | | | | | | | | function old new delta parse_stream 2857 2940 +83 i_peek 55 69 +14 i_free_alias_buffer 33 37 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 101/0) Total: 101 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: comment fixesDenys Vlasenko2025-08-171-2/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: make "alias" print aliases in properly escaped formDenys Vlasenko2025-08-171-31/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta print_pfx_escaped_nl - 83 +83 builtin_alias 216 218 +2 .rodata 105985 105975 -10 parse_stream 2873 2857 -16 builtin_set 301 259 -42 builtin_readonly 107 59 -48 builtin_export 145 93 -52 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/5 up/down: 85/-168) Total: -83 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>