aboutsummaryrefslogtreecommitdiff
path: root/shell (unfollow)
Commit message (Collapse)AuthorFilesLines
2024-09-26Start 1.38.0 development cycleDenys Vlasenko1-2/+2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-26Bump version to 1.37.0Denys Vlasenko1-1/+1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-26wget: fix compile warnings when WGET_FTP is not selectedDenys Vlasenko2-4/+7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-25Update sample build scriptsRon Yorston3-7/+25
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.
2024-09-23cut: don't print empty lines with '-s' optionRon Yorston1-0/+5
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)
2024-09-21Use builtin ffs also with GCCChristopher Wellons1-1/+1
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.
2024-09-21ash: reject unknown long optionsRon Yorston1-0/+5
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)
2024-09-15make: fix error reporting for included filesFRP-5467-g9376eebd8Ron Yorston1-5/+6
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.
2024-09-14make: fix test for include with no pathnamesRon Yorston1-1/+1
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.
2024-09-10make: handling of leading whitespace in makefilesRon Yorston1-14/+16
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)
2024-09-10make: reinstate conditional skipping of command linesRon Yorston2-11/+13
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.
2024-09-08ash: code shrinkRon Yorston1-6/+2
Allow ash_main() to be invoked directly even in a non-FS_SHELLEXEC shell. Saves 48-64 bytes.
2024-09-04ash: optimise running of scripts (2)Ron Yorston3-8/+26
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.
2024-08-22make: duplicate makefile name recorded with commandRon Yorston1-3/+12
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)
2024-08-19ash: optimise running of scriptsRon Yorston3-15/+68
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.
2024-08-17which,ash: code shrink detection of standalone shellRon Yorston2-28/+11
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.
2024-08-16ash: allow additional element in argv arrayRon Yorston1-2/+5
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.
2024-08-16win32: code shrinkRon Yorston5-34/+34
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.
2024-08-14win32: use 64-bit time on 32-bit platformsRon Yorston3-2/+22
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)
2024-08-14win32: fix strftime(3) '%s' formatRon Yorston1-1/+1
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)
2024-08-10make: disallow inference rules for phony targetsRon Yorston2-5/+22
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)
2024-08-09win32: fix another problem with stat(2)Ron Yorston1-2/+3
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)
2024-08-08make: allow empty commandsRon Yorston2-10/+23
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)
2024-08-08drop: use correct option when cmd.exe is used as shellRon Yorston1-0/+2
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)
2024-08-08su: note that test mode implies -W in usage messageRon Yorston1-1/+1
Saves 8-16 bytes (GitHub issue #438)
2024-08-07su: add test modeRon Yorston1-19/+27
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)
2024-08-05su: use correct option when cmd.exe is used as shellRon Yorston1-1/+3
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)
2024-08-05drop: allow an alternative shell to be selectedRon Yorston1-7/+16
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)
2024-08-04su: allow an alternative shell to be selectedRon Yorston1-19/+30
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)
2024-08-03su: detect inability to raise privilegeRon Yorston3-22/+37
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)
2024-08-02dd: add support for writing to physical drivesRon Yorston1-0/+17
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)
2024-07-30ash: rewrite waitpid_child() to improve performanceRon Yorston1-32/+19
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)
2024-07-28ash: fix slow running when background job is presentRon Yorston1-1/+1
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)
2024-07-27lineedit: use stdout for shell history builtinRon Yorston1-0/+5
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)
2024-07-26wget: let user override Content-LengthRon Yorston1-0/+21
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)
2024-07-26linedit: increase line edit buffer to 8192 bytesRon Yorston4-4/+4
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)
2024-07-20win32: consolidate executable handling in popen.cRon Yorston2-34/+29
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.
2024-07-19win32: code shrink popen(3)Ron Yorston1-40/+13
- 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.
2024-07-18ash: ignore hidden/iconified stateRon Yorston1-10/+3
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)
2024-07-18ed: fix line insertion before current lineRon Yorston2-0/+25
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)
2024-07-14win32: code shrink mingw_spawn_interpreter()Ron Yorston1-11/+8
Rewrite mingw_spawn_interpreter() to remove a duplicated recursive call. Saves 32-48 bytes.
2024-07-14ash: move hashvar() calls into findvar()Ron Yorston1-9/+8
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>
2024-07-13timeout: allow fractional seconds in timeout valuesRon Yorston1-4/+9
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>
2024-07-13powertop: code shrinkDenys Vlasenko1-19/+6
function old new delta print_intel_cstates 477 475 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13hush: do not exit interactive shell on some redirection errorsDenys Vlasenko7-18/+47
$ echo >&99 hush: dup2(99,1): Bad file descriptor $ echo >&9999 hush: fcntl(1,F_DUPFD,10000): Invalid argument $ echo 2>/dev/tty 10>&9999 hush: fcntl(10,F_DUPFD,10000): Invalid argument $ still alive!_ function old new delta static.setup_redirects 334 394 +60 .rodata 105661 105712 +51 dup_CLOEXEC 49 79 +30 save_fd_on_redirect 263 277 +14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 155/0) Total: 155 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13hush: fix "exec 3>FILE" aborting if 3 is exactly the next free fdDenys Vlasenko8-7/+42
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-13hush: avoid duplicate fcntl(F_SETFD, FD_CLOEXEC) during initDenys Vlasenko1-8/+3
function old new delta hush_main 1149 1150 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12ash: remove limitation on fd# lengthDenys Vlasenko1-7/+13
"echo text >&0000000000002" works as you would expect, "echo text >&9999999999" properly fails instead of creating a file named "9999999999". function old new delta expredir 219 232 +13 readtoken1 3045 3053 +8 parsefname 204 201 -3 isdigit_str9 45 - -45 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 2/1 up/down: 21/-48) Total: -27 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12ash: do not abort interactive mode on >&9999 redirectDenys Vlasenko1-4/+16
With very large fd#, the error code path is different from one for closed but small fd#. Make it not abort if we are interactive: $ echo text >&99 # this wasn't buggy ash: dup2(9,1): Bad file descriptor $ echo text >&9999 # this was ash: fcntl(1,F_DUPFD,10000): Invalid argument function old new delta .rodata 105637 105661 +24 dup2_or_raise 35 38 +3 redirect 1084 1044 -40 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 27/-40) Total: -13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12tls: fix CONFIG_FEATURE_TLS_SHA1=y + CONFIG_SHA1_HWACCEL=yDenys Vlasenko1-6/+23
The check for result hash size was buggy for CONFIG_SHA1_HWACCEL=y. While at it, document CPUID use a bit better. function old new delta get_shaNI - 28 +28 sha1_end 66 79 +13 sha256_begin 83 60 -23 sha1_begin 111 88 -23 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/2 up/down: 41/-46) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>