aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* | ash: eval: Reset handler when entering a subshellRon Yorston7 days1-14/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Apply upstream commit 81274d8b3. On Windows it isn't necessary to reset the exception handler in evalbackcmd() or evalpipe(), as that will have been done by forkshell_init(). The globals_misc structure now contains a setjmp() buffer. On 64-bit Windows this needs 16-byte alignment. This is achieved in the forkshell data structure by placing the globals_misc data immediately after the 16-byte aligned forkshell data. Saves 144 bytes in the 64-bit build.
* | ash: jobs: Block signals during tcsetpgrpRon Yorston9 days1-1/+16
| | | | | | | | Merge upstream commit 4ce8afe6b. This has no effect on Windows.
* | ash: eval: Add vfork supportRon Yorston9 days2-36/+114
| | | | | | | | | | | | | | Merge upstream commit df154028d. Since we don't have vfork() on Windows we continue to use the spawn_forkshell() mechanism. Although there is some rearrangement of the code it's functionally the same.
* | ash: rename got_sigchld, doing_jobctl, and INT_ON/OFF to match dashRon Yorston9 days1-158/+158
| | | | | | | | | | Merge upstream commit 9f490785e. The changes are cosmetic, to bring the code into line with dash.
* | Merge branch 'busybox' into mergeRon Yorston10 days18-75/+290
|\|
| * ash: fix fallout of no-more-set commandnameDenys Vlasenko2025-08-091-6/+7
| | | | | | | | | | | | Testsuite reports lots of message mismatches, fix that Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shells: fix a typo in var_backslash1.tests, expand it while at itDenys Vlasenko2025-08-094-8/+12
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: eval: Always set exitstatus in evaltreeDenys Vlasenko2025-08-091-6/+7
| | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Tue, 6 Dec 2022 16:49:14 +0800 eval: Always set exitstatus in evaltree There is no harm in setting exitstatus unconditionally in evaltree. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: options: Do not set commandname in procargsDenys Vlasenko2025-08-091-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Mon Feb 25 12:49:20 2019 +0800 options: Do not set commandname in procargs We set commandname in procargs when we don't have to. This results in a duplicated output of arg0 when an error occurs. function old new delta ash_main 1256 1236 -20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: jobs: drop unused node parameter in makejob()Denys Vlasenko2025-08-091-6/+6
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shells: add testsuite itemDenys Vlasenko2025-08-094-0/+124
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: reuse vstype_suffix[] in debug code, shrink itDenys Vlasenko2025-08-081-35/+37
| | | | | | | | | | | | | | | | | | | | function old new delta vstype_suffix - 39 +39 static.vstype 42 - -42 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/0 up/down: 39/-42) Total: -3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix cmdputs - was showing some variable forms incorrectlyDenys Vlasenko2025-08-071-20/+35
| | | | | | | | | | | | | | | | | | | | function old new delta cmdputs 402 418 +16 static.vstype 48 42 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-6) Total: 10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: smarter optimization for not-globbing [ and [[Denys Vlasenko2025-08-071-37/+23
| | | | | | | | | | | | | | function old new delta o_save_ptr 176 167 -9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix heredoc.tests broken by last commitDenys Vlasenko2025-08-071-15/+19
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta readtoken1 3053 3095 +42 xxreadtoken 215 212 -3 expandstr 255 252 -3 parseheredoc 148 127 -21 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 42/-27) Total: 15 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: fix corner cases with backslash-newlines in heredocsDenys Vlasenko2025-08-0714-5/+44
| | | | | | | | | | | | | | function old new delta fetch_heredocs 477 485 +8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: optimization: do not glob words "[" and "[["Denys Vlasenko2025-08-071-0/+40
| | | | | | | | | | | | | | function old new delta glob_needed 71 86 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2025-08-1516-237/+302
|\|
| * shell: typo and whitespace fixes, no code changesDenys Vlasenko2025-08-032-16/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix memory leak caused by compiler optimizing out a storeDenys Vlasenko2025-08-032-25/+84
| | | | | | | | | | | | | | | | | | | | function old new delta generate_stream_from_string 222 232 +10 setup_heredoc 329 330 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 11/0) Total: 11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: disentangle interactiveness/job_control setup codeDenys Vlasenko2025-08-031-79/+67
| | | | | | | | | | | | | | | | | | ...and discover that we can do away with 1-3 initialization syscalls. function old new delta hush_main 1152 1146 -6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix build failure if !CONFIG_HUSH_JOBDenys Vlasenko2025-08-031-2/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: make NORETURN declarations lees verbose, no code changesDenys Vlasenko2025-08-031-22/+6
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: do not save history on xfunc error, it's unsafeDenys Vlasenko2025-08-031-47/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Also, make second calls to install_special_sighandlers() less haphazard. It's not a fix for anything, but looking more organized now. function old new delta fflush_restore_ttypgrp_and__exit - 20 +20 restore_ttypgrp_and__exit 21 - -21 hush_main 1181 1152 -29 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/1 up/down: 20/-50) Total: -30 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: if !JOBS, skip tests which wouldn't workDenys Vlasenko2025-08-0313-2/+41
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: don't save history in subshells; on NOMMU, don't be interactive on reexecDenys Vlasenko2025-08-031-54/+72
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: rename hush_exit to save_history_run_exit_trap_and_exit, sigexit to ↵Denys Vlasenko2025-08-031-15/+15
| | | | | | | | | | | | restore_ttypgrp_and_killsig_or__exit Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2025-08-125-0/+11
|\|
| * hush: fix SEGV on "echo << >" and suchDenys Vlasenko2025-07-085-0/+11
| | | | | | | | | | | | | | | | | | | | function old new delta .rodata 105787 105823 +36 fetch_heredocs 461 477 +16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0) Total: 52 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2025-08-1012-57/+129
|\|
| * shell: empty HISTFILE disables history saving, just as unset one didDenys Vlasenko2025-07-042-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | The rationale here is that unsetting HISTFILE in /etc/profile does not "stick": if it's unset, the default one is set later (after /etc/profile is executed) by the shell. But setting (and exporting, so it is inherited by all (grand)child shells) an empty one works. function old new delta save_history 296 316 +20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: update HISTFILESIZE code to be actually usefulDenys Vlasenko2025-07-033-11/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "HISTFILESIZE=0" in profile wasn't working as intended, "unset HISTFILE" wasn't preventing creation of history files Now: HISTSIZE=n allows to reduce in-memory history buffer HISTFILESIZE=n allows to reduce history file size (0: truncate it) unset HISTFILE allows to not save history file at all function old new delta exitshell 138 194 +56 hush_exit 97 143 +46 save_history 266 296 +30 hush_main 1170 1186 +16 .rodata 105762 105771 +9 load_history 246 254 +8 size_from_HISTFILESIZE 44 41 -3 read_line_input 2746 2712 -34 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/2 up/down: 165/-37) Total: 128 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: fix race between signal handlers setting bb_got_signal and poll()Denys Vlasenko2025-07-023-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta __ppoll_time64 - 211 +211 check_got_signal_and_poll - 164 +164 read_key 607 601 -6 shell_builtin_read 1328 1318 -10 ------------------------------------------------------------------------------ (add/remove: 4/0 grow/shrink: 0/2 up/down: 375/-16) Total: 359 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * use pollfd[1] array for poll() argumentDenys Vlasenko2025-07-021-2/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: improve bash compatibility of read built-inRon Yorston2025-07-0111-33/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make the read built-in more compatible with bash: - Return an exit code of 142 on timeout. - When the timeout expires before a newline is detected in the input bash captures the partial input. This behaviour is new since bash version 4.4. BusyBox shells had the pre-4.4 behaviour where the input was lost. Update the tests to suit and fix a couple of compiler errors in the testsuite. function old new delta builtin_read 154 174 +20 readcmd 213 228 +15 shell_builtin_read 1364 1370 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 41/0) Total: 41 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | shell: avoid miscounting backslashes in read built-inRon Yorston2025-07-071-2/+5
| | | | | | | | | | | | | | | | | | | | When the '-n' option was used to limit the number of characters read, any backslashes in the input weren't correctly accounted for. Adds 16 bytes. (GitHub issue #504)
* | ash: don't mistake errors for timeouts in read built-inRon Yorston2025-07-011-6/+9
| | | | | | | | | | | | | | | | | | | | | | Commit e07a73a15 (ash: bring 'read' built-in closer to bash) added code to treat a timeout differently from an error returned by poll(2). This falsely assumed that only an EINTR error was relevant. We must allow for other errors. Adds 16 bytes. (GitHub issue #502)
* | ash: kill background processes on SIGINTRon Yorston2025-06-291-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this script: #!/bin/sh -e f() { for n in $(seq 1 10); do echo "Background $n ..." sleep 1 done } f 1 & f 2 & f 3 & wait If this was interrupted by Ctrl+C the background jobs continued to run. Avoid this by sending SIGINT to all children of the shell. Saves 16 bytes. (See GitHub PR #500)
* | ash: bring 'read' built-in closer to bashRon Yorston2025-06-292-8/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 8e6991733 (ash: fix 'read' shell built-in (1)) noted discrepancies between upstream BusyBox, busybox-w32 and bash. It aligned busybox-w32 with upstream BusyBox. Apply further changes in busybox-w32 to align 'read' more closely with bash. - When a timeout occurs before a newline in the input stream, capture and save the text collected so far. - Return an exit code of 142 on timeout. Also, since our implementation of poll(2) never sets errno to EINTR the code to handle this case can be omitted. Saves 16 bytes in the 64-bit build, adds 16 in 32-bit. (GitHub issue #502)
* | Merge branch 'busybox' into mergeRon Yorston2024-12-301-0/+3
|\|
| * 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>
* | ash: match behaviour of cmd.exe in cd builtinRon Yorston2024-11-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The Windows API strips trailing dots and spaces from the last component of a path. cmd.exe handles this quirk when changing directory by adjusting its idea of the current directory to match reality. The shell in busybox-w32 didn't do this, leading to some confusion. Fix the shell's cd builtin so it works more like cmd.exe. Adds 64-80 bytes. (GitHub issue #478)
* | win32: drop stream i/o workaroundRon Yorston2024-10-301-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | It seems that one of the workarounds for problems with stream i/o in MSVCRT was unnecessary. It also caused display glitches when the 32-bit binary was run on 64-bit systems. Remove it. Saves 112 bytes in the 32-bit build. (GitHub issue #472)
* | win32: try harder to prevent output to stdoutRon Yorston2024-10-291-1/+0
| | | | | | | | | | | | | | | | | | The previous commit failed to stop 'uname 1>&-' from writing to standard output with 32-bit MSVCRT. Close the stream _and_ the file descriptor. (Github issue #472)
* | win32: more problems with stream i/o and MSVCRTRon Yorston2024-10-291-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These commands: cut --wrong-opt 2>&1 echo $(cut --wrong-opt 2>&1) resulted in different output. In the first case the message about the invalid option appeared before the usage message; in the second after. The command uname --wrong-opt 1>&- 2>&- displayed the error message even though both output streams were closed. These issues appear to be related to those previously fixed by commits 4be93f32f and f192e6539: - They involve the interaction between shell redirection and stream input/output. - UCRT builds aren't affected. Apply two workarounds: - When the file descriptor associated with stderr is redirected remind stderr it should be unbuffered. (32- and 64-bit MSVCRT) - When the file descriptor associated with any of the standard i/o streams is to be closed do it by closing the stream instead. (32-bit MSVCRT) Adds 48-176 bytes. (GitHub commit #472)
* | ash: fix waiting for status of background jobRon Yorston2024-10-281-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following has never worked properly in busybox-w32: $ my_func() { return 5; } $ my_func & sleep 1; wait $!; echo $? The expected result is that 'echo' should display '5'. Actual results used to be '0' and more recently have been '127'. The culprit was commit fa6f44ea72 (win32: ash: reimplement waitpid(-1)). When the status of a job changed its pid was set to -1, which flagged processes of interest to the implementation of waitpid(). This is no longer necessary as waitpid() now uses the process handle instead. There's therefore no need to overwrite the pid. (GitHub issue #470)
* | ash: correctly identify nofork applets in error messageRon Yorston2024-10-281-0/+8
| | | | | | | | | | | | | | | | | | | | Commit 633e3a5eae (ash: correctly identify applet in getopt() error messages) made getopt() display the correct name for noexec applets in case of error. Do the same for nofork applets. Adds 32-48 bytes.
* | ash: update commentRon Yorston2024-10-131-1/+0
| | | | | | | | PPID is no longer fake.
* | Merge branch 'busybox' into mergeRon Yorston2024-10-081-29/+57
|\|
| * 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>