aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* | win32: code shrinkRon Yorston2024-08-165-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.
* | win32: use 64-bit time on 32-bit platformsRon Yorston2024-08-143-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)
* | win32: fix strftime(3) '%s' formatRon Yorston2024-08-141-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)
* | make: disallow inference rules for phony targetsRon Yorston2024-08-102-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)
* | win32: fix another problem with stat(2)Ron Yorston2024-08-091-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)
* | make: allow empty commandsRon Yorston2024-08-082-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)
* | drop: use correct option when cmd.exe is used as shellRon Yorston2024-08-081-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)
* | su: note that test mode implies -W in usage messageRon Yorston2024-08-081-1/+1
| | | | | | | | | | | | Saves 8-16 bytes (GitHub issue #438)
* | su: add test modeRon Yorston2024-08-071-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)
* | su: use correct option when cmd.exe is used as shellRon Yorston2024-08-051-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)
* | drop: allow an alternative shell to be selectedRon Yorston2024-08-051-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)
* | su: allow an alternative shell to be selectedRon Yorston2024-08-041-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)
* | su: detect inability to raise privilegeRon Yorston2024-08-033-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)
* | dd: add support for writing to physical drivesRon Yorston2024-08-021-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)
* | ash: rewrite waitpid_child() to improve performanceRon Yorston2024-07-301-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)
* | ash: fix slow running when background job is presentRon Yorston2024-07-281-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)
* | lineedit: use stdout for shell history builtinRon Yorston2024-07-271-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)
* | wget: let user override Content-LengthRon Yorston2024-07-261-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)
* | linedit: increase line edit buffer to 8192 bytesRon Yorston2024-07-264-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)
* | win32: consolidate executable handling in popen.cRon Yorston2024-07-202-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.
* | win32: code shrink popen(3)Ron Yorston2024-07-191-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.
* | ash: ignore hidden/iconified stateRon Yorston2024-07-181-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)
* | ed: fix line insertion before current lineRon Yorston2024-07-182-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)
* | win32: code shrink mingw_spawn_interpreter()Ron Yorston2024-07-141-11/+8
| | | | | | | | | | | | | | Rewrite mingw_spawn_interpreter() to remove a duplicated recursive call. Saves 32-48 bytes.
* | Merge branch 'busybox' into mergeRon Yorston2024-07-143-40/+30
|\|
| * ash: move hashvar() calls into findvar()Ron Yorston2024-07-141-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>
| * timeout: allow fractional seconds in timeout valuesRon Yorston2024-07-131-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>
| * powertop: code shrinkDenys Vlasenko2024-07-131-19/+6
| | | | | | | | | | | | | | function old new delta print_intel_cstates 477 475 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2024-07-1317-84/+208
|\|
| * hush: do not exit interactive shell on some redirection errorsDenys Vlasenko2024-07-137-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>
| * hush: fix "exec 3>FILE" aborting if 3 is exactly the next free fdDenys Vlasenko2024-07-138-7/+42
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: avoid duplicate fcntl(F_SETFD, FD_CLOEXEC) during initDenys Vlasenko2024-07-131-8/+3
| | | | | | | | | | | | | | function old new delta hush_main 1149 1150 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: remove limitation on fd# lengthDenys Vlasenko2024-07-121-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>
| * ash: do not abort interactive mode on >&9999 redirectDenys Vlasenko2024-07-121-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>
| * tls: fix CONFIG_FEATURE_TLS_SHA1=y + CONFIG_SHA1_HWACCEL=yDenys Vlasenko2024-07-121-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>
| * tls: P256: improve x86_64 multiplication asm codeDenys Vlasenko2024-07-121-22/+36
| | | | | | | | | | | | | | | | | | | | | | | | gcc is being rather silly. Usues suboptimal registers, and does not realize that i and j are never negative, thus usese even _more_ registers for temporaries to sign-extend i/j to 64-bit offsets. function old new delta sp_256_mont_mul_8 155 132 -23 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * tls: P256: fix obscure x86_64 asm misbehavior, closes 15679Denys Vlasenko2024-07-111-10/+29
| | | | | | | | | | | | | | | | | | | | gcc does not necessarily clear upper bits in 64-bit regs if you ask it to load a 32-bit constant. Cast it to unsigned long. Better yet, hand-write loading of the constant with a smaller instruction. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * md5/shaXsum: accept uppercase hex stringsRon Yorston2024-07-111-1/+1
| | | | | | | | | | | | | | | | | | | | The coreutils versions of md5sum and the like accept uppercase hex strings from checksum files specified with the '-c' option. Use a case-insensitive comparison so BusyBox does the same. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * vi: Ensure that the edit buffer ends in a newlinePetja Patjas2024-07-111-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently vi assumes that the edit buffer ends in a newline. This may not be the case. For example: $ printf test > test $ vi test <press 'o'> We fix this by inserting a newline to the end during initialization. Signed-off-by: Petja Patjas <pp01415943@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | make: allow pragmas to apply recursivelyRon Yorston2024-07-121-14/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | Pragmas set when pdpmake is run are exported to the environment variable PDPMAKE_PRAGMAS as a space-separated list of pragma names. This environment variable is read when pdpmake starts and any pragmas it contains are applied. Thus pragmas are passed to recursive invocations of pdpmake. PDPMAKE_PRAGMAS can also be set by the user. Adds 240-288 bytes.
* | Merge branch 'busybox' into mergeRon Yorston2024-07-105-101/+159
|\|
| * ash: remove defunct control character to save a few bytesRon Yorston2024-07-101-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 549deab5a (ash: move parse-time quote flag detection to run-time) did away with the need to distinguish between backquotes inside and outside quotes. This left a gap among the control characters used in argument strings. Removing this gap saves a few bytes. function old new delta .rodata 167346 167338 -8 cmdputs 399 388 -11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19) Total: -19 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * Makefile.flags: suppress clang warnings when cross-compilingRon Yorston2024-07-101-3/+3
| | | | | | | | | | | | | | | | | | Extend the changes introduced by commit b4ef2e3467 (Makefile.flags: suppress some clang-9 warnings) so they also cover the case where clang is used as a cross-compiler. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix parsing of alias expansion + bash featuresRon Yorston2024-07-101-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An alias expansion immediately followed by '<' and a newline is parsed incorrectly: ~ $ alias x='echo yo' ~ $ x< yo ~ $ sh: syntax error: unexpected newline The echo is executed and an error is printed on the next command submission. In dash the echo isn't executed and the error is reported immediately: $ alias x='echo yo' $ x< dash: 3: Syntax error: newline unexpected $ The difference between BusyBox and dash is that BusyBox supports bash-style process substitution and output redirection. These require checking for '<(', '>(' and '&>' in readtoken1(). In the case above, when the end of the alias is found, the '<' and the following newline are both read to check for '<('. Since there's no match both characters are pushed back. The next input is obtained by reading the expansion of the alias. Once this string is exhausted the next call to __pgetc() calls preadbuffer() which pops the string, reverts to the previous input and recursively calls __pgetc(). This request is satisified from the pungetc buffer. But the first __pgetc() doesn't know this: it sees the character has come from preadbuffer() so it (incorrectly) updates the pungetc buffer. Resolve the issue by moving the code to pop the string and fetch the next character up from preadbuffer() into __pgetc(). function old new delta pgetc 28 589 +561 __pgetc 607 - -607 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 561/-607) Total: -46 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * awk: mktime() with no arguments is not allowedDenys Vlasenko2024-07-101-2/+1
| | | | | | | | | | | | It was SEGVing. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * awk: improve comments and constants, no code changesDenys Vlasenko2024-07-101-20/+27
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * qwk: code shrinkDenys Vlasenko2024-07-091-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta mk_splitter 100 96 -4 as_regex 103 99 -4 parse_expr 991 986 -5 awk_split 544 538 -6 awk_getline 559 552 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-26) Total: -26 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * awk: restore assignment precedence to be lower than ternary ?:Denys Vlasenko2024-07-092-22/+74
| | | | | | | | | | | | | | Something is fishy with constrcts like "3==v=3" in gawk, they should not work, but do. Ignore those for now. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * awk: do not infinitely recurse getvar_s() if CONVFMT is set to a numeric valueDenys Vlasenko2024-07-091-6/+14
| | | | | | | | | | | | | | | | | | | | | | function old new delta fmt_num 247 257 +10 evaluate 3385 3379 -6 getvar_s 111 102 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-15) Total: -5 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * awk: fix use after free (CVE-2023-42363)Natanael Copa2024-07-091-8/+13
| | | | | | | | | | | | | | | | | | | | function old new delta evaluate 3377 3385 +8 Fixes https://bugs.busybox.net/show_bug.cgi?id=15865 Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>