| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
When the shell invoked process substitution it retained a process
handle to the child. These handles could accumulate without limit.
The shell in upstream BusyBox doesn't bother to create a job
structure for process substitutions or here documents. This isn't
appropriate on Windows, where we need to track the child process
handles. Create job structures as required.
Saves 32-48 bytes.
(GitHub issue #587)
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Commits e23652908 and 686a0803f (ash: fix execution of applets via
Unix-style path) were necessary following a major revision of the
shell upstream.
Another problem was found:
$ sh
$ PATH="/usr/bin;$PATH" exec non-existent
resulted in a segfault. This happened because during a PATH search
tryexec() modified argv[0] when it detected a Unix-style path (in
this case '/usr/bin/non-existent') but failed to restore it if the
execution failed.
There were other issues:
- The logic of the new code failed to match the original: the test
for a Unix-style path should only have happened if an attempt to
execute the full path had already failed.
- The test for a script running an interpreter which is an applet
also modified argv. If the execution failed argv should have
been restored to its original state.
- During a PATH search the 'path' pointer walked through the
elements of the path. This pointer was also used to determine
if an applet was overridden by an executable. This is wrong:
the full PATH variable should have been used.
The code around tryexec()/shellexec() has been rewritten to take
these issues into account.
Adds 32-48 bytes.
(GitHub issue #584)
|
| |
|
|
|
|
|
|
| |
It wasn't possible to build ash if FEATURE_SH_STANDALONE was
disabled.
This issue was introduced during the large merge of upstream
changes to ash in commit e23652908.
|
| |\ |
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The size of the NFROMSTR struct wasn't initialised in the nodesize
array, so we got:
$ ./busybox sh
$ f() { cat <<< hello; }
$ f
Segmentation fault (core dumped) ./busybox sh
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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().
ash_command_name 92 91 -1
helpcmd 106 102 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-5) Total: -5 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| | |
Newer glibc is now smarter and can propagate const-ness from those!
function old new delta
readtoken1 3111 3108 -3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| |
| |
| |
| |
| | |
A here string in a subshell or function invocation caused a SEGV.
This was due to an upstream bug: the size of the NFROMSTR struct
wasn't initialised in the nodesize array.
(GitHub issue #567)
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| | |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |\| |
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| |\| |
|
| | |
| |
| |
| |
| |
| |
| | |
function old new delta
ash_main 1624 1645 +21
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |\| |
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| | |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| | |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| | |
| |
| |
| |
| |
| |
| | |
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.
|
| |\| |
|
| | |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |\| |
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |\| |
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Upstream commit
Date: Wed, 14 Dec 2022 02:06:05 +0100
parser: Invalid redirections are run-time, not syntax errors
This fixes a long-standing bug where
echo 'echo >&a' | sh
errors out with
sh: 2: Syntax error: Bad fd number
despite the error being on line 1
This patch makes the error
sh: 1: Bad fd number: a
as expected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| | |
| |
| |
| |
| |
| |
| | |
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>
|