| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
| |
Since we don't use is_in_supplementary_groups() there's no need for
the cached_groupinfo structure to include the members required for
its support or for them to be initialised.
Saves 32 bytes.
|
|\ |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Recent upstream changes to file permission tests added a function
to check and cache values in the supplementary group list.
The implementation of getgroups() in the Windows port adds no
useful information beyond what can be obtained by checking the
current effective gid, which all callers of the new function
already do. The function can be replaced with a simple 'FALSE'.
Saves 232-288 bytes.
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
function old new delta
is_in_supplementary_groups - 54 +54
nexpr 766 721 -45
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 54/-45) Total: 9 bytes
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>
|
| |
| |
| |
| |
| |
| |
| |
| | |
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 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.
|
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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)
|
| |
| |
| |
| |
| |
| |
| | |
As well as trying to read '/etc/profile' also look for the script
'etc/profile' relative to the location of the running binary.
Adds 64-96 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
A previous commit (e3bfe3695) revised the use of getsysdir() to
obtain the system directory, and hence the system drive. See the
commit message for the history to that point.
Further improvements are possible:
- Remove getsysdir() and push the calls to GetSystemDirectory()
down into get_system_drive() and get_proc_addr().
- Check the return value of GetSystemDirectory(). It's unlikely
to fail, but better safe than sorry.
- Instead of making all callers of get_system_drive() check for a
NULL return value always return a non-NULL pointer. If the drive
can't be found an empty string is returned instead (which is what
the callers were using anyway).
- The function need_system_drive() was only used in one place (in
httpd). Move the code there and remove the function.
- Use concat_path_file() where possible.
Saves 76-144 bytes.
|
|\| |
|
| |
| |
| |
| | |
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Although "naive" counting function is not too slow and is smaller,
using it on e.g. each of 1024 words of CPU mask feels wrong.
function old new delta
bb_popcnt_32 - 52 +52
get_prefix 323 321 -2
nproc_main 206 199 -7
d4_run_script 739 731 -8
ipcalc_main 533 507 -26
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/4 up/down: 52/-43) Total: 9 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
function old new delta
get_malloc_cpu_affinity - 76 +76
nproc_main 216 206 -10
process_pid_str 250 206 -44
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 76/-54) Total: 22 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
If the environment variable BB_CRITICAL_ERROR_DIALOGS is set to
1 critical error dialogs are enabled. If unset or set to any
other value they aren't. In either case the error messages
introduced by commit 790e37727 (win32: revert 'don't set error
mode') are issued.
The shell exports BB_CRITICAL_ERROR_DIALOGS to the environment
immediately on any change so the setting takes effect at once.
Adds 104-160 bytes.
(GitHub issue #423)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
In recent versions of Windows the PATH environment variable has
a trailing semicolon. This is insignificant to Windows because
it's ignored. busybox-w32 conforms to the POSIX interpretation
of PATH which treats an empty path element as denoting the current
directory. As result, on these versions of Windows executables
may by default be run from the current directory, contrary to
usual Unix practice.
Attempt to detect and remove the trailing semicolon on applet
start up. If the user insists, they can add a trailing semicolon
to the shell variable PATH and it will be respected in the
conventional manner.
Adds 88-112 bytes.
(GitHub issue #422)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
busybox-w32 had a dummy implementation of getppid(2) which always
returned 1. Provide a more realistic version.
The effect is limited:
- The PPID shell variable should report a sensible value.
- The special value to omit the parent PID 'pidof -o %PPID'
should work.
Costs 48 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Recent changes to allow orphaned processes to report a parent PID
of 1 rely on the assumption that Process32First/Process32Next
return parents before children. This isn't guaranteed by the API.
Obtain all known PIDs on the first call to procps_scan() so that
dead parents can be detected reliably.
Costs 48 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
If the parent PID doesn't appear in the process table, report it
as 1. This more closely matches how orphaned children are handled
on UNIX.
Adds 96-128 bytes.
(GitHub issue #416)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
A process which has exited may still have its process handle
held open by its children. Such a process doesn't appear in
the process table. It is thus similar to a zombie process in
UNIX. Using kill(1) to interact with such a process was seen
to succeed, contrary to expectation.
The code for "ordinary" signals in kill(2) did check if the
process was still active but didn't treat an attempt to kill
an inactive process as an error. Furthermore, sending SIGKILL
or the fake signal 0 to a process didn't even check if the
process was still active.
Rearrange the implementation of kill(2) so that an attempt to
signal an inactive process is treated as an error. This also
consolidates handling of SIGKILL and signal 0 with "ordinary"
signals.
Saves 96 bytes.
(GitHub issue #416)
|
| |
| |
| |
| |
| |
| |
| |
| | |
Allow the default history size (used if HISTFILESIZE isn't set)
to be configured at build time. This may be less than or equal
to the standard history size.
(GitHub issue #411)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Implement a 'title' built-in for ash. It's very simple-minded,
performs almost no error checking and is completely non-portable.
- With no arguments it prints the current console title.
- If arguments are provided the *first only* is set as the console
title.
Costs 88-116 bytes.
(GitHub issue #401)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This commit adds a new wcwidth implementation at libbb/wcwidth_alt.c,
and uses it instead of the existing implementation when compiling for
windows and CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000 - which is the case
with the unicode configs/mingw64u_defconfig.
The windows-target condition keeps non-windows build unmodified, and
the last supported wchar threshold is a semi-hack to allow switching
between implementations without adding a new config option (the old
code supports codepoints up to 0x2ffff).
The new file wcwidth_alt.c was generated by a new scripts/mkwcwidth,
which prints a wcwidth implementation using latest unicode data from
a local clone of https://github.com/jquast/wcwidth . This repo is the
main python wcwidth implementation, and is maintained and up to date.
Functional differences from the existing implementation:
- Unicode 15.1.0 (latest) with the new version (about 450 ranges of
wide and zero-width codepoints), compared to roughly Unicode 5.0
of the existing code (nearly 20 years old spec, about 150 ranges).
The new spec includes, among others, various wide icons and emojis,
which can now be edited correctly at the shell prompt, have correct
alignment in 'ls', etc.
- The old implementation returns -1 (non-printable) for surrogates,
while the new code returns 1, though this is inconsequential, and
POSIX doesn't care. Also libc implementations vary in this regard.
Technical differences:
- The old version compiles less code/data when the last supported
wchar is smaller, while the new version doesn't. This doesn't
matter because the new version is enabled only for the full range.
- The new version is smaller and relatively straight forward, and
fully automated (generated), so updates to newer spec is trivial.
The old version mixes data, ad-hoc code (tailored to the data),
and preprocessor checks, and is hard to automate updates.
The old version has various forms of 32 and 16 bit data ranges, in
several arrays, while the new version uses single data array with
unified form of 32 bits per range, with two rules:
- A data range can't span Unicode planes (enforced, but unlikely
required, and if yes, code to split ranges would be simple).
- A range can't hold more than 32768 codepoints, so bigger ranges
are split automatically (currently there are 2 such ranges).
Performance wise, the new version should be faster, even with three
times the data ranges. Both versions do effectively at most one binary
search in one Unicode plane data, but the new version finds both
zero-width and wide-width results in this one search, while the old
version only finds zero-width, and to detect wide-width it does an
additional linear series of manual range tests, but since most results
are width 1, this sequence is performed in most (non-ASCII) calls.
In a cursory comparison of the new wcwidth with glibc and musl-libc
(both use O(1) lookup tables), with few bodies of text, we're in the
same ballpark, with typical speed of 60% or better.
Bloat-wise, the new version is about 180 bytes code and 1800 bytes
data. If it had similar number of data ranges as the old code (150),
the new version would be about 200 bytes smaller, but because the
new version has 450 data ranges, it's about 1K bigger.
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
- Rename some functions to be more meaningful.
- Adjust conditional compilation to clarify which code is required
for 'standalone shell' and 'exec prefers applets' settings.
This shouldn't result in any change to the behaviour or size of
default builds.
|
| |
| |
| |
| |
| |
| |
| | |
The conditional compilation to control standalone shell mode was
incorrect when building for POSIX. This hadn't been noticed before
as it had only been tested in the default configuration where
standalone shell mode is disabled.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The GCC documentation points out that the stdcall attribute doesn't
apply to functions which take a variable number of arguments. GCC
is silent about this during compilation but clang complains noisily.
Remove FAST_FUNC from all variadic functions. This has no effect
whatsoever on the binary resulting from a default 32-bit build.
Signed-off-by: Ron Yorston <rmy@pobox.com>
|
| |
| |
| |
| |
| |
| |
| | |
Add a convenience function to determine if the last character of
a string is a directory separator.
Adds 16-32 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
busybox-w32 binaries built using clang crashed so frequently that
they were pretty much unusable. The main issue seems to be with
assignments to the structures containing global variables which
are used in most applets.
Upstream commit 5156b2455 (Make const ptr assign as function call
in clang) addresses this, but is insufficient for the build on
Windows. Extend the idea to the ASSIGN_CONST_PTR() macro too.
Costs 32-80 bytes in the gcc build.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Since clang doesn't seem to know about ffs(3) make it use
__builtin_ffs() instead.
Fix a warning in process_escape() in winansi.c: result of comparison
of constant -1 with expression of type 'WORD' (aka 'unsigned short')
is always true. Change the error value returned by process_colour()
from -1 to 0xffff.
Costs 16 bytes.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
The upstream code uses fork/exec when running a CGI process.
Emulate this by:
- Spawning a child httpd process with the special '-I 0' option,
along with the options provided on the server command line. This
sets up the proper state then calls the cgi_handler() function.
- The cgi_handler() function fixes the pipe file descriptors and
starts another child process to run the CGI script.
These processes are detached from the console on creation. When
spawn() functions are run in P_DETACH mode they don't connect to
the standard file descriptors. Normally this doesn't matter but
the process which runs the CGI scripts needs to inherit the pipe
endpoints. The create_detached_process() function handles this.
See:
https://github.com/rprichard/win32-console-docs/blob/master/README.md
Adds about 2.9Kb to the size of the binary.
(GitHub issue #266)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When httpd was run in the background the return code of the parent
process was incorrect. It seems when spawn() is run in _P_DETACH
mode it returns 0 on success, not a process handle.
Fix the test for the return code and alter mingw_spawn_detach()
so it doesn't treat the return from spawn() as a handle.
Saves 32 bytes.
|
| |
| |
| |
| |
| | |
This doesn't affect the generated binary, at least in the default
configuration.
|
| |
| |
| |
| |
| |
| |
| |
| | |
Pass the PATH to be used to look up executables down from the shell
to the applet override code. This replaces the use of a static
variable and a function to fetch its value.
Saves 16-32 bytes.
|
|\| |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
function old new delta
start_stop_daemon_main 1186 1206 +20
bb_daemonize_or_rexec 196 212 +16
bb_banner 47 46 -1
packed_usage 34656 34645 -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 36/-12) Total: 24 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
function old new delta
sleep_main 116 119 +3
printf_main 860 837 -23
single_argv 50 25 -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-48) Total: -45 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
mingw_fork_compressor() uses CreateProcess() to run the compressor
program. This will often be an instance of BusyBox, but since the
xv and lzma applets in BusyBox don't support compression it can be
an external program.
It was intended that the external program should be found using PATH.
However, CreateProcess() looks in various other places before trying
PATH. In particular, it first looks in the directory of the current
executable, then in the current directory of the process. This can
result in the wrong xz.exe or lzma.exe being found.
Perform an explicit PATH search and force CreateProcess() to use the
result.
This change only affects the search for a compressor. The same
problem also affects other uses of our popen(3) emulation. These
may be addressed in future.
Costs 64-80 bytes.
(GitHub issue #376)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Add an implementation of strverscmp from musl so that the 'sort -V'
option works.
Add '-V' to the trivial usage message.
Costs 248-256 bytes.
(GitHub issue #370)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Add shell options:
- 'nohiddenglob' excludes files with the hidden attribute from
globbing
- 'nohidsysglob' excludes files with the hidden and system attributes
from globbing
If both options are enabled 'nohiddenglob' takes precedence.
These options also affect tab completion.
Files that are hidden because they start with a period aren't
affected (unless they also have the hidden attribute).
Costs 160-208 bytes.
(GitHub issue #367)
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Add two utility functions to convert Windows process exit codes.
- exit_code_to_wait_status() converts to a POSIX wait status.
This is used in ash and the implementations of system(3) and
mingw_wait3().
- exit_code_to_posix() converts to a POSIX exit code. (Not that
POSIX has much to say about them.)
As a result it's possible for more applets to report when child
processes are killed as if by a signal. 'time', 'drop' and 'su -W',
for example.
Adds 64-80 bytes.
|