| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When `fstat` fails, `st` is left uninitialised. In our case, Ben Kohler
noticed our release media builds were failing in Gentoo on x86 when building
busybox with occasional SIGBUS. This turned out to be EOVERFLOW (from 32-bit
ino_t) which wasn't being reported because nothing was checking the return value
from `fstat`.
Fix that to avoid UB (use of uninit var) and to give a more friendly
error to the user.
This actually turns out to be fixed already in the kernel from back in
2010 [0] and 2016 [1].
[0] https://github.com/torvalds/linux/commit/a3ba81131aca243bfecfa78c42edec0cd69f72d6
[1] https://github.com/torvalds/linux/commit/46fe94ad18aa7ce6b3dad8c035fb538942020f2b
Reported-by: Ben Kohler <bkohler@gentoo.org>
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
POSIX generally requires normal output to go to stdout and
diagnostic (i.e. error) output to go to stderr.
When usage messages for BusyBox applets are specifically requested
by the user (e.g. 'find --help') they should go to stdout; when
they're emitted due to an error they should go to stderr.
function old new delta
bb_show_usage 148 146 -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes
Signed-off-by: Avi Halachmi <avihpit@yahoo.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
There are two calls to dup2() in busybox_main(). These were
introduced to coerce full_write2_str() into writing to stdout.
The relevant commits were: 21278dff7 (busybox: do not print help
to fd 2, print it to fd 1) and 5a7c72015 (busybox --list option.
+140 bytes. Rob wanted it.)
Later, in commit 729ecb87b (bbconfig: make it independent from
printf functions), the function full_write1_str() was added.
Using this in busybox_main() allows us to drop the dup2() calls.
function old new delta
run_applet_and_exit 796 760 -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-36) Total: -36 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
function old new delta
save_history 267 266 -1
hush_exit 98 97 -1
exitshell 140 138 -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-4) Total: -4 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>
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit 1ade2225d2 (winansi: allow alternative screen buffer to be
disabled) added a workaround for the broken alternative screen
buffer in the Wine console.
The problem has been fixed in Wine for well over a year:
https://bugs.winehq.org/show_bug.cgi?id=54287
Remove the workaround.
Saves 80-96 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Recent binaries released on frippery.org use the time of the
latest commit as the build time. This is achieved through the
SOURCE_DATE_EPOCH environment variable, which is respected by
the upstream BusyBox build system.
The sample build scripts have been updated to do the same. This
doesn't result in perfectly reproducible builds as the toolchains
used don't all support SOURCE_DATE_EPOCH.
Add some more details to the README file.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
A command like 'cut -f1 -s' would print empty lines even though
they don't contain a delimiter.
Add a test to avoid this.
Based on a submission to the upstream mailing list:
http://lists.busybox.net/pipermail/busybox/2024-July/090834.html
Adds 32 bytes in 32-bit build, saves 32 in 64-bit.
(GitHub issue #459)
|
| |
| |
| |
| |
| |
| |
| |
| | |
With CONFIG_DEBUG_PESSIMIZE=y (-O0) the ffs intrinsic is left as a
function call, resulting in a linker error. The prefixed builtin is
generally part of the "GNU C" dialect and is usable in any "GNU C"
implementation, i.e. any compiler that defines __GNUC__. That includes
Clang, GCC, and more.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The global variables 'makefile' and 'lineno' weren't properly
reset after a recursive call to input(). As a result error
messages for included files could refer to the wrong file or
line number.
Restore 'makefile' and 'lineno' immediately after a rescursive
call to input(). This also requires a different fix for commit
b21546ddb (make: fix test for include with no pathnames).
Adds 16 bytes in the 32-bit build.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
In POSIX 2024 the behaviour of an include line with no pathnames
is unspecified. The test for this condition was incorrect in
certain circumstances.
Files containing dependencies may be generated by the compiler and
included in the makefile. On an initial build no dependency files
will be present and the include line is made to ignore errors. In
this case the test for no pathnames returned true, even though many
pathnames may have been present.
Fix the problem by always setting 'makefile' even if the named
file can't be opened.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Try to match how different makes handle leading whitespace in
makefiles. (Tested with GNU, BSD, Schily and UNIX Version 7
make.)
- Commands in rules must start with a tab. It's the law.
- BSD make doesn't allow any whitespace at the start of an include
line. Enforce this restriction in POSIX mode: 'the word include
... appears at the beginning of a line'. As an extension allow
arbitrary tabs or spaces.
- All implementations allow a space as the first character of a
macro definition or rule. Permit this in all cases.
- Only GNU make allows a tab as the first character of a macro
definition, but POSIX 2024 seems to permit it too: 'string1 is
defined as all characters from the first non-<blank> character to
the last non-<blank> character, inclusive'. Allow this in POSIX
2024 mode and as an extension.
- No implementation allows a tab as the first character of a rule.
Disallow this in all cases.
Adds 32-64 bytes.
(pdpmake GitHub issue 63)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit e90345c10 (make: allow empty commands) rearranged readline()
in a way that broke the use of conditionals within the definition
of a rule.
Add a test case to detect this. Adjust readline() so that
conditionals are processed before returning command lines or
checking for empty lines and comments.
Remove the test for a leading tab in skip_lines(). This allows
conditionals in the definition of a rule to be indented with a
leading tab.
|
| |
| |
| |
| |
| |
| |
| | |
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.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit f3f72ac1d (make: show location of errors during build)
stored a pointer to the name of the makefile with each command,
for use in diagnostic messages.
While this is fine for makefiles defined on the command line, the
names of included files will have been freed before they can be
used.
Always take a copy of the makefile name stored with commands.
Adds 32-48 bytes.
(GitHub issue #449)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
tryexec() in ash relies on all callers of shellexec() having an
additional unused element before the start of its argv array.
In busybox-w32 this was not the case when shellexec() was called
from forkshell_shellexec(), as only the actual contents of the
argv array were copied into the forkshell data block. In practice
argv[-1] is only currently used when the 'which' applet is about
to be run, so whatever got overwritten (probably cmdtable[30])
was unlikely to matter.
Still, let's be correct and allocate the additional element.
Adds 16 bytes.
|
| |
| |
| |
| |
| | |
Add the FAST_FUNC qualifier to several Windows-specific functions.
This has no effect in 64-bit builds but saves 336 bytes for 32-bit.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
To avoid problems with dates in 2038 and beyond use 64-bit time
values on 32-bit platforms.
- Mostly this just requires a few preprocessor macros to choose
the appropriate functions, structs and typedefs.
- We have our own implementations of nanosleep(), clock_gettime()
and clock_settime(). Omit the Windows include file that declares
them.
- Apply the hack for struct timeval in the 'ts' applet on 32-bit.
Adds 1624 bytes on 32-bit, none on 64-bit.
(GitHub issue #446)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The '%s' format of our strftime(3) wrapper (display number of
seconds since the Unix epoch) returned incorrect results on 64-bit
systems for times more than 2^31 seconds after the epoch.
Use the correct format.
Adds 16 bytes.
(GitHub issue #446)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
GNU make doesn't allow inference rules or the .DEFAULT target to
be used for phony targets.
POSIX is unclear on the matter but there doesn't seem to be an
explicit prohibition of inference rules or .DEFAULT.
Follow the GNU make behaviour as a non-POSIX extension.
Adds 48-80 bytes.
(pdpmake GitHub issue 56)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
If we can't open a file to preserve its access time (perhaps
because it doesn't belong to us) just try again without bothering
about the access time. I thought I'd already done that, but
that must have been in an alternative reality.
Adds 16 bytes.
(GitHub issue #443)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
pdpmake didn't allow rules to have empty commands. There are
circumstances where this may be useful.
Make the following changes:
- Add a flag to readline() to indicate the next line is expected
to be a command. If this flag is true and the input line starts
with a tab return it immediately, thus skipping the check for
an empty line or comment line.
- In docmds() skip tabs and spaces after a command prefix. If the
resulting command is empty don't print it or try to execute it.
- In newcmd() allow empty commands.
Adds 48-96 bytes.
(pdpmake GitHub issue 56)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Use the '/c' option to pass a command to cmd.exe. This is similar
to what was previously done for 'su': commit e5244175b (su: use
correct option when cmd.exe is used as shell).
Adds 48-64 bytes.
(GitHub issue #438)
|
| |
| |
| |
| |
| |
| | |
Saves 8-16 bytes
(GitHub issue #438)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Testing some uses of 'su' can be challenging because any errors
appear in the new console window which may close as a result.
Add the '-t' option to enable test mode. This starts a new shell
using ShellExecuteEx(), but without elevated privileges and a new
console. All other options and arguments are handled much as
before, though some differences in behaviour are to be expected due
to the lack of elevated privilege.
Adds 80-96 bytes.
(GitHub issue #438)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Most Unix shells (and PowerShell) use the '-c' option to specify
commands to execute. cmd.exe uses '/c' instead.
Detect when cmd.exe is the 'shell' being used with 'su -s' and
adjust the command option to suit.
Adds 48-56 bytes.
(GitHub issue #438)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Add the '-s' option to allow an alternative shell to be given.
No PATH search is performed for the shell, so an absolute or
relative path to a suitable executable must be provided.
Adds 80-96 bytes.
(GitHub issue #438)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Add the '-s' option to allow an alternative shell to be given.
No PATH search is performed for the shell, so an absolute or
relative path to a suitable executable must be provided.
Certain features are only available when the built-in shell is
used:
- The '-N' option, which allows the console window to remain open
when the shell exits.
- The fix which allows the current directory to be retained despite
the efforts of ShellExecute() to change it.
- The friendly message in the console title.
Adds 128 bytes.
(GitHub issue #438)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When privilege has been dropped by the 'drop' applet, the 'su'
applet is unable to raise it again because ShellExecuteEx()
thinks it unnecessary.
Detect this situation, report an error and return exit code 2.
Costs 72-112 bytes.
(GitHub issue #437)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
A common use of 'dd' is to copy boot images to removable media.
This didn't work on Windows because opening a physical drive
failed with the default flags used by 'dd'.
If the output file is a physical drive remove incompatible flags.
Writing to a physical drive requires elevated privileges and the
drive must be offline.
Adds 80 bytes.
(GitHub issue #435)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
After the previous commit there was still a slight disparity
between shell performance with and without background jobs.
Reduce this disparity by the following changes:
- Remove the pidlist array. The PID of the exiting process can be
obtained from its handle.
- Save the proclist array between calls. It will always grow to
support the required number of PIDs.
- Combine the loops to compute the required size of proclist and
to fill it. This saves a few bytes with no measurable impact
on performance.
Saves 8 bytes in a 32-bit build, adds 32 in 64-bit.
(GitHub issue #434)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
It was noted that a simple 'while' loop would take considerably
longer to run in a shell which had spawned a background job
compared to one that hadn't.
The problem originates with commit 4d8a277d59 (Implement nonblocking
wait) which introduced a nonblocking wait in ash.
This was found to cause the shell to use 100% of CPU when running
'sleep 60'. This was 'fixed' by commit 88b8cb61e (ash: Add a very
small timeout to nonblocking wait).
Subsequently commit 96c9c0044 (ash: allow waitpid_child to block)
fixed a problem with the logic of the original commit, but it left
the small timeout in place. It is this timeout which slows down
the shell when a background job is present.
The solution is to restore the 0 timeout for the nonblocking wait.
Saves 0-16 bytes.
(GitHub issue #434)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit fd47f0567 (lineedit: print prompt and editing operations
to stderr) changed various print statements to output to stderr.
The change in show_history() caused the shell history builtin to
send its output to stderr.
Revert that part of the commit.
Saves 16 bytes.
(GitHub issue #433)
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The wget applet allows several common headers to be overridden by
the user. Add 'Content-Length' to the list.
Adds 32-64 bytes.
(GitHub issue #432)
|
| |
| |
| |
| |
| |
| |
| | |
The default size of the line edit buffer is 1024 bytes which was
found to be too restrictive. Increase it to 8192 bytes.
(GitHub issue #429)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Commit f444dc586 (win32: only search PATH for compressor) made
mingw_fork_compressor() perform a PATH lookup for the xz and lzma
compression programs. This avoided relying on CreateProcess() to
perform the search.
Other callers of the pipe creation code should also avoid reliance
on CreateProcess's executable search:
- Move the applet test and PATH lookup into mingw_popen_internal().
The first argument to CreateProcess() will always be a path to
an executable.
- mingw_fork_compressor() uses the new "w+" mode to indicate that
xz and lzma compressors should be found on PATH.
- mingw_popen() no longer needs to check for an applet itself, as
that's now handled in mingw_popen_internal().
- spawn_ssl_client() in 'wget' can rely on the popen code to look
up the 'ssl_client' applet.
- Remove unnecessary argument checks in mingw_popen_internal().
Adds 0-24 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
- Replace the half-baked code to quote the command passed to
popen(3) with a call to quote_arg().
- Where the command to be run is a non-overridden applet in the
current binary pass the path to the binary to CreateProcess()
instead of adding '--busybox' to the command.
Saves 128-136 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Some third-party terminal programs have a hidden console host to
interact with console applications. When the busybox-w32 shell
was used with such a terminal the hidden console host could be
revealed because the shell expected it to be iconified.
Since it doesn't much matter in this case whether the console host
is hidden or iconified treat these states as equivalent.
The user's preference set by the 'noiconify' option will still be
respected when a console window is concealed.
(GitHub issue #430)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When text is inserted by insertLine() the lines following the
insertion are moved down and the insertion point is made the new
current line. To avoid too much scanning of the linked list of
lines setCurNum() may use the position of the old current line to
determine the location of the new current line.
If the insertion point is before the old current line in the file
the latter will have been moved down, so its line pointer needs to
be adjusted.
(GitHub issue #431)
|
| |
| |
| |
| |
| |
| |
| | |
Rewrite mingw_spawn_interpreter() to remove a duplicated recursive
call.
Saves 32-48 bytes.
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
dash has accepted a patch to remove the first argument of findvar().
It's commit e85e972 (var: move hashvar() calls into findvar()).
Apply the same change to BusyBox ash.
function old new delta
findvar 35 40 +5
mklocal 268 261 -7
exportcmd 164 157 -7
setvareq 319 310 -9
lookupvar 150 141 -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/4 up/down: 5/-32) Total: -27 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The 'timeout' applet uses parse_duration_str() to obtain its
timeout values. The default configuration enables float durations.
However, the applet silently ignores fractional seconds. This
results in unexpected behaviour:
$ timeout 5.99 sleep 5.1; echo $?
Terminated
143
When float durations are enabled ensure that any fractional seconds
are taken into account.
function old new delta
timeout_wait 44 92 +48
timeout_main 383 365 -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 48/-18) Total: 30 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| | |
function old new delta
print_intel_cstates 477 475 -2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|