aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
| * *: code shrink using sigprocmask2() where appropriateDenys Vlasenko2025-08-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta sig_unblock 41 43 +2 sig_block 41 40 -1 sigprocmask_allsigs 33 31 -2 wait_for_child_or_signal 202 193 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 2/-12) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: converge waiting code to dash in its form, add comments, no code changesDenys Vlasenko2025-08-101-26/+30
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: move 100 bytes off global .data / .bss, no logic changesDenys Vlasenko2025-08-101-61/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | text data bss dec hex filename 1067871 559 5184 1073614 1061ce busybox_old 1068067 555 5088 1073710 10622e busybox_unstripped ^^^^^^^^^^^ function old new delta pgetc 580 623 +43 parse_command 1633 1651 +18 ash_main 1226 1239 +13 popstring 115 126 +11 redirect 951 961 +10 popfile 105 115 +10 expandstr 252 262 +10 evalbltin 306 314 +8 pushstring 155 162 +7 pushfile 31 38 +7 freestrings 90 97 +7 setinputstring 68 74 +6 readtoken1 3095 3101 +6 pungetc 9 15 +6 nlprompt 39 45 +6 nlnoprompt 33 39 +6 unwindfiles 20 25 +5 dotcmd 309 314 +5 setinputfile 190 194 +4 init 429 432 +3 forkchild 617 620 +3 evalcommand 1616 1617 +1 ash_vmsg 141 142 +1 g_parsefile 4 - -4 commandname 4 - -4 basepf 84 - -84 ------------------------------------------------------------------------------ (add/remove: 0/3 grow/shrink: 23/0 up/down: 196/-92) Total: 104 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: redir: Retry open on EINTRDenys Vlasenko2025-08-095-67/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Thu, 28 May 2020 21:31:45 +1000 redir: Retry open64 on EINTR It is possible for open64 to block on named pipes, and therefore it can be interrupted by signals and return EINTR. We should only let it fail with EINTR if real signals are pending (i.e., it should not fail on SIGCHLD if SIGCHLD has not been trapped). This patch adds a new helper sh_open to retry the open64 call if necessary. It also calls sh_error when appropriate. Fixes: 3800d4934391 ("[JOBS] Fix dowait signal race") Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: eval: Reset handler when entering a subshellDenys Vlasenko2025-08-091-3/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Sun, 3 Mar 2019 21:57:50 +0800 eval: Reset handler when entering a subshell As it is a subshell can execute code that is only meant for the parent shell when it executes a longjmp that is caught by something like evalcommand. This patch fixes it by resetting the handler when entering a subshell. function old new delta evalsubshell 169 183 +14 evalpipe 342 356 +14 argstr 1406 1416 +10 ash_main 1236 1226 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 65/-10) Total: 28 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ahs: jobs: Block signals during tcsetpgrpDenys Vlasenko2025-08-091-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Wed, 6 Jan 2021 15:45:12 +1100 jobs: Block signals during tcsetpgrp Harald van Dijk <harald@gigawatt.nl> wrote: > On 19/12/2020 22:21, Steffen Nurpmeso wrote: >> Steffen Nurpmeso wrote in >> <20201219172838.1B-WB%steffen@sdaoden.eu>: >> |Long story short, after falsely accusing BSD make of not working >> >> After dinner i shortened it a bit more, and attach it again, ok? >> It is terrible, but now less redundant than before. >> Sorry for being so terse, that problem crosses my head for about >> a week, and i was totally mislead and if you bang your head >> against the wall so many hours bugs or misbehaviours in a handful >> of other programs is not the expected outcome. > > I think a minimal test case is simply > > all: > $(SHELL) -c 'trap "echo TTOU" TTOU; set -m; echo all good' > > unless I accidentally oversimplified. > > The SIGTTOU is caused by setjobctl's xtcsetpgrp(fd, pgrp) call to make > its newly started process group the foreground process group when job > control is enabled, where xtcsetpgrp is a wrapper for tcsetpgrp. (That's > in dash, the other variants may have some small differences.) tcsetpgrp > has this little bit in its specification: > > Attempts to use tcsetpgrp() from a process which is a member of > a background process group on a fildes associated with its con‐ > trolling terminal shall cause the process group to be sent a > SIGTTOU signal. If the calling thread is blocking SIGTTOU sig‐ > nals or the process is ignoring SIGTTOU signals, the process > shall be allowed to perform the operation, and no signal is > sent. > > Ordinarily, when job control is enabled, SIGTTOU is ignored. However, > when a trap action is specified for SIGTTOU, the signal is not ignored, > and there is no blocking in place either, so the tcsetpgrp() call is not > allowed. > > The lowest impact change to make here, the one that otherwise preserves > the existing shell behaviour, is to block signals before calling > tcsetpgrp and unblocking them afterwards. This ensures SIGTTOU does not > get raised here, but also ensures that if SIGTTOU is sent to the shell > for another reason, there is no window where it gets silently ignored. > > Another way to fix this is by not trying to make the shell start a new > process group, or at least not make it the foreground process group. > Most other shells appear to not try to do this. This patch implements the blocking of SIGTTOU (and everything else) while we call tcsetpgrp. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: eval: Add vfork supportDenys Vlasenko2025-08-092-37/+103
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upstream commit: Date: Sat, 19 May 2018 02:39:56 +0800 eval: Add vfork support This patch adds basic vfork support for the case of a simple command. Upstream commit: Date: Tue, 12 Jan 2021 17:11:19 +1100 jobs: Always reset SIGINT/SIGQUIT handlers On Fri, Jan 08, 2021 at 08:55:41PM +0000, Harald van Dijk wrote: > On 18/05/2018 19:39, Herbert Xu wrote: > > This patch adds basic vfork support for the case of a simple command. > > ... @@ -879,17 +892,30 @@ forkchild(struct job *jp, union node *n, int > > mode) > > } > > } > > if (!oldlvl && iflag) { > > - setsignal(SIGINT); > > - setsignal(SIGQUIT); > > + if (mode != FORK_BG) { > > + setsignal(SIGINT); > > + setsignal(SIGQUIT); > > + } > > setsignal(SIGTERM); > > } > > + > > + if (lvforked) > > + return; > > + > > for (jp = curjob; jp; jp = jp->prev_job) > > freejob(jp); > > } > > This leaves SIGQUIT ignored in background jobs in interactive shells. > > ENV= dash -ic 'dash -c "kill -QUIT \$\$; echo huh" & wait' > > As of dash 0.5.11, this prints "huh". Before, the subprocess process killed > itself before it could print anything. Other shells do not leave SIGQUIT > ignored. > > (In a few other shells, this also prints "huh", but in those other shells, > that is because the inner shell chooses to ignore SIGQUIT, not because the > outer shell leaves it ignored.) Thanks for catching this. I have no idea how that got in there and it makes no sense whatsoever. This patch removes the if conditional. Fixes: e94a964e7dd0 ("eval: Add vfork support") Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: rename got_sigchld, doing_jobctl, and INT_ON/OFF to match dashDenys Vlasenko2025-08-091-150/+150
| | | | | | | | | | | | | | Comparing code with dash is more difficult with these differences. (We didn't know back then that dash will be revived...) Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: move 100 bytes off global .data / .bss, no logic changesRon Yorston2025-09-101-80/+79
| | | | | | | | | | | | | | | | | | Apply upstream commit f6fb3c603. This moves some static data into globals_misc. The Windows port had already moved commandname, so only g_parsefile and basepf are new. Some changes had to be made to the forkshell code. Adds 148-176 bytes.
* | shells: add tests missing from last commitRon Yorston2025-09-104-0/+30
| |
* | ash: redir: Retry open on EINTRRon Yorston2025-09-101-69/+92
| | | | | | | | | | | | Apply upstream commit 9b67dde8c. Adds 8 bytes in the 32-bit build.
* | ash: eval: Reset handler when entering a subshellRon Yorston2025-09-091-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 Yorston2025-09-071-1/+16
| | | | | | | | Merge upstream commit 4ce8afe6b. This has no effect on Windows.
* | ash: eval: Add vfork supportRon Yorston2025-09-072-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 Yorston2025-09-071-158/+158
| | | | | | | | | | Merge upstream commit 9f490785e. The changes are cosmetic, to bring the code into line with dash.
* | Merge branch 'busybox' into mergeRon Yorston2025-09-0618-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)