| Commit message (Collapse) | Author | Age | Files | Lines |
|\ |
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
...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>
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| | |
restore_ttypgrp_and_killsig_or__exit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
"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>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| |
| |
| |
| | |
PPID is no longer fake.
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
function old new delta
find_executable_in_PATH - 67 +67
if_command_vV_print_and_exit 114 116 +2
.rodata 105712 105710 -2
builtin_type 137 128 -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 69/-11) Total: 58 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
While at it, correct "type" to skip non-executable files in PATH
function old new delta
builtin_source 211 316 +105
builtin_test 10 32 +22
hush_main 1150 1170 +20
builtin_type 122 137 +15
if_command_vV_print_and_exit 120 114 -6
find_in_path 131 - -131
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 4/1 up/down: 162/-137) Total: 25 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Testcase:
setuidgid 1:1 strace ash -c 'test -x TODO; test -x TODO; echo $?'
should show that second "test -x" does not query ids again.
function old new delta
ash_main 1236 1256 +20
get_cached_euid - 19 +19
get_cached_egid - 19 +19
test_main 56 72 +16
test_exec 119 135 +16
is_in_supplementary_groups 52 57 +5
nexpr 718 702 -16
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/1 up/down: 95/-16) Total: 79 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
function old new delta
test_main2 - 407 +407
testcmd 10 23 +13
test_main 418 56 -362
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 420/-362) Total: 58 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
function old new delta
is_in_supplementary_groups 54 52 -2
nexpr 721 718 -3
test_exec 125 119 -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-11) Total: -11 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
executable
Upstream commit:
Date: Fri, 5 Apr 2024 17:55:46 +0800
exec: Check executable bit when searching path
Andrej Shadura <andrew.shadura@collabora.co.uk> wrote:
...
> https://bugs.debian.org/874264
> -------- Forwarded Message --------
> Subject: dash: 'command -v' mistakenly returns a shell script whose
> executable is not set
> Date: Mon, 04 Sep 2017 10:45:48 -0400
> From: Norman Ramsey <nr@cs.tufts.edu>
> To: Debian Bug Tracking System <submit@bugs.debian.org>
...
> I tracked a build bug in s-nail to a problem with dash. Symptom:
> building s-nail tries to run /home/nr/bin/clang, a script whose
> executable bit is not set. We tracked the problem to the result of
> running `command -v clang` with /bin/sh:
...
This is inherited from NetBSD. There is even a commented-out
block of code that tried to fix this.
Anyway, we now have faccessat so we can simply use it.
function old new delta
test_exec - 125 +125
find_command 911 918 +7
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 132/0) Total: 132 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
- Change the 'flags' argument to shellexec()/tryexec() so it only
indicates that it's permissible to run ash_main() directly. The
flag is only set TRUE in forkshell_shellexec().
- The check for a script with an interpreter which is an applet is
now performed for all calls to tryexec(), not just those that
originate from evalcommand().
Saves 64-80 bytes.
GitHub issue #461.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
It was noted this command didn't work properly:
su -t -c 'exec sh -s -c "echo 123"'
The child shell performed the 'echo' but then exited, despite the
'-s' flag. This is a regression introduced by commit 074ebfca21
(ash: code shrink).
This simpler command also failed the same way:
sh -c "exec sh -s"
This regression dates back even further, to commit da7c8cdf63
(ash: run ash_main() directly from a FS_SHELLEXEC shell).
The issue can be avoided if shells invoked by the 'exec' builtin
aren't run by calling ash_main() directly.
Adds 80-96 bytes.
GitHub issue #461.
|
|\| |
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit 64f70cc755 (Add --login support) added code in options()
to handle the bash-compatible '--login' option. In doing so it
committed BusyBox ash to silently accepting all other long
options.
Restore compatibility with other ash variants by rejecting unknown
long options.
function old new delta
options 589 624 +35
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit 64f70cc755 (Add --login support) added code in options()
to handle the bash-compatible '--login' option. In doing so it
committed BusyBox ash to silently accepting all other long
options.
Restore compatibility with other ash variants by rejecting unknown
long options.
(GitHub issue #457)
|
| |
| |
| |
| |
| |
| |
| | |
Allow ash_main() to be invoked directly even in a non-FS_SHELLEXEC
shell.
Saves 48-64 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit 4b7b4a960 (ash: optimise running of scripts) avoided creation
of a process when running a script. There's another case where we
can do the same: if the script is being run from a FS_SHELLEXEC
shell.
- Check the necessary conditions for this to happen.
- Allocate two extra slots in the argv array for FS_SHELLEXEC.
- Set the index of the script file in the argv array. Without this
the test 'pidof this' failed because the command name hadn't been
correctly set.
Adds 80-96 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The BusyBox shell detects certain cases where forking a command is
unnecessary (last command in a script or subshell, for example) and
calls execve(2) instead. This doesn't help in the Windows port
because execve(2) is implemented by creating a process.
There is one case where it is possible to apply this optimisation:
if the command is a script and the script interpreter is an applet.
- Have evalcommand() pass a flag to indicate this situation to
shellexec(). Also, allocate two spare elements before the start
of the argv array.
- If the flag is TRUE shellexec() passes the shell's PATH variable
down to tryexec() so it can perform a test for applet override.
- If tryexec() finds that all the necessary conditions apply it
can run a script by directly invoking the interpreter's main().
Adds 192-224 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit 6d87be4d7 (which,ash: changes to which/command/type) let
'which' detect when it's run from a standalone shell by having
the shell pass the undocumented '-s' option.
A better solution is to alter argv[0] when 'which' is run from a
standalone shell. This is possible because the code path through
run_noexec_applet_and_exit() and which_main() doesn't actually
use argv[0].
- No special treatment is required in ash when 'which' has no
arguments or the '--help' option.
- tryexec() no longer needs an extra element before the start of
argv. The commit 027fb22e2 can be reverted and the allocation
of argv in evalcommand() simplified.
- 'which' no longer needs to handle the '-s' option.
Saves 96-104 bytes.
|