aboutsummaryrefslogtreecommitdiff
path: root/docs (unfollow)
Commit message (Collapse)AuthorFilesLines
2024-10-29win32: try harder to prevent output to stdoutRon Yorston1-1/+0
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)
2024-10-29win32: more problems with stream i/o and MSVCRTRon Yorston1-0/+16
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)
2024-10-28ash: fix waiting for status of background jobRon Yorston1-1/+0
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)
2024-10-28ash: correctly identify nofork applets in error messageRon Yorston1-0/+8
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.
2024-10-28cut: improve detection of invalid rangesRon Yorston1-8/+11
Commit 0068ce2fa (cut: add toybox-compatible options -O OUTSEP, -D, -F LIST) added detection of reversed ranges. Further improvements are possible. - The test for reversed ranges compared the start after it had been decremented with the end before decrement. It thus missed ranges of the form 2-1. - Zero isn't a valid start value for a range. (Nor is it a valid end value, but that's caught by the test for a reversed range.) - The code if (!*ltok) e = INT_MAX; duplicates a check that's already been made. - Display the actual range in the error message to make it easier to find which range was at fault. Adds 0-48 bytes. (GitHub issue #467)
2024-10-25win32: update poll(2) to match latest gnulib versionRon Yorston1-5/+6
2024-10-25win32: workaround for pipe writability in poll(2)Ron Yorston1-0/+13
A CGI script was found to hang when a large amount of data was posted: #!/bin/sh echo "Content-type: text/plain;" echo if [ "$REQUEST_METHOD" = "POST" ]; then dd of=my.dat bs=1 count=${CONTENT_LENGTH} echo -n "success." else echo -n "error!" fi This appears to be due to problems determining whether a pipe is writable on Windows. The Git for Windows project has a workaround in their copy of GNUlib's poll(2) implementation. The details are in the commit message: https://github.com/git-for-windows/git/commit/94f4d01932279c419844aa708bec31a26056bc6b Apply the same workaround here. Saves 220-272 bytes. (GitHub issue #468)
2024-10-23make: .WAIT shoudn't have prerequisitesRon Yorston1-1/+1
Commit f0dea6674 (make: enforce restrictions on prerequisites/ commands) set the flags for .WAIT incorrectly: in POSIX mode it shouldn't have prerequisites.
2024-10-22cut: detect error when bounds are reversedRon Yorston2-1/+11
The command 'cut -b 3-2' failed to detect that the bounds were incorrectly ordered, though the check worked when the difference between the bounds was larger. The comparison was made after the lower bound has been decremented but before the upper bound had. Adds 0-16 bytes. (GitHub issue #467)
2024-10-20make: enforce restrictions on prerequisites/commandsRon Yorston1-9/+45
POSIX mentions some restrictions on whether rules may or may not have prerequisites or commands: - most special targets shouldn't have commnds; - inference/.DEFAULT rules shouldn't have prerequisites. Enforce these restrictions in POSIX mode. Generally, implementations are happy to accept prerequisites or commands even if they're subsequently ignored. Allow this as an extension. Adds 216-256 bytes.
2024-10-20make: changes to .DEFAULT/inference rulesRon Yorston2-19/+38
The POSIX standard allows inference rules to be redefined but not the .DEFAULT rule. There is no explicit exception for .DEFAULT to: Only one target rule for any given target can contain commands. Treat redefinition of a .DEFAULT rule as an error in POSIX mode but allow it as an extension. Also, the code didn't allow an inference rule with dependencies to redefine an existing inference rule. This is no longer the case. Adds 64-96 bytes.
2024-10-20make: fix test for empty command in inference ruleRon Yorston1-1/+1
Commit e90345c10 (make: allow empty commands) changed how empty commands are handled. This broke the POSIX mode test for inference rules of the form: rule: ; Adjust the setting of 'semicolon_cmd' to the new reality. Adds 16-32 bytes.
2024-10-18make: relax definition of comment lineRon Yorston1-1/+1
According to POSIX: Blank lines, empty lines, and lines with <number-sign> ('#') as the first character on the line are also known as comment lines. Most implementations also include lines where the first non-blank character is '#'. Allow this as an extension. Adds 0-16 bytes.
2024-10-17make: improve chaining of implicit rulesRon Yorston1-3/+19
Running 'make thing.z' with the following makefile: .SUFFIXES: .x .y .z .x.y: cp $< $@ .y.x: cp $< $@ .y.z: cp $< $@ resulted in infinite recursion and a segfault. Follow GNU make and don't allow any implicit rule to appear more than once in a chain. Adds 16-32 bytes.
2024-10-17make: look for PDPmakefileRon Yorston1-10/+9
As an extension have pdpmake look for the file 'PDPmakefile' before 'makefile' and 'Makefile'. This is similar to how GNU make first checks for 'GNUmakefile'. Adds 32-40 bytes.
2024-10-13ash: update commentRon Yorston1-1/+0
PPID is no longer fake.
2024-10-13win32: close exec'ing process if possibleRon Yorston1-0/+3
If a process performing an exec is an orphan there's no reason for it to wait for its child's exit code. Let it exit immediately. Adds 16 bytes. (GitHub issue #461)
2024-10-12kill: fix regression in 'kill -9'Ron Yorston1-6/+7
'kill -9' was found to fail with an 'Invalid argument' error. This is a regression introduced by commit 569de936a (kill: killing a zombie process should fail). Use the correct argument to OpenProcess() for SIGKILL so it can query the exit code of the target process. Adds 16 bytes. (GitHub issue #465)
2024-10-11win32: fix problem interrupting shell loopRon Yorston1-11/+13
It proved to be almost impossible to interrupt a loop like: while true; do sleep 1; done where 'sleep' was an external program, not an applet. The issue was introduced by commit 0475b7a64 (win32: convert exit codes). This passed a POSIX error code to the exit() in wait_for_child() so a parent was unable to detect when its child was interrupted. Pass the Windows exit code to exit() instead. Work around the changes introduced by commit 790e377273 (win32: revert 'don't set error mode'). Adds 16-32 bytes.
2024-10-10win32: fix regression in chdir(2)Ron Yorston1-7/+9
When mingw_chdir() was introduced it canonicalised its argument (585d17d26). This had the side effect of making its case match that of the directory as stored on disk. Subsequent changes retained that behaviour for symlinks but not otherwise (69d328022, b99032390). This was noted to affect the appearance of the directory specified by the (undocumented) 'sh -d' option. Fix the case of non-symlink directories too. Adds 16-32 bytes.
2024-10-09id: code shrinkRon Yorston3-1/+23
The bogus user/group ids we use on Windows are very limited. Make these limitations explicit in the 'id' applet. Saves 464 bytes.
2024-10-09test: code shrink supplementary groupsRon Yorston2-0/+8
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.
2024-10-08libbb: code shrink supplementary group testRon Yorston2-0/+10
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.
2024-10-08hexdump: accept hex numbers in -n, closes 16195Denys Vlasenko1-3/+8
function old new delta hexdump_main 366 383 +17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-08libbb: modify find_executable() to not temporarily write to PATHDenys Vlasenko4-54/+48
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>
2024-10-07hush: fix "type ./cat" and "command -v ./cat" to not scan PATHDenys Vlasenko1-13/+33
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>
2024-10-07hush: make "test -x" use cached groupinfoDenys Vlasenko1-7/+22
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>
2024-10-07ash: more changes to noexec appletsRon Yorston1-30/+16
- 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.
2024-10-07test: -x can return 0/1 early if all X bits are the sameDenys Vlasenko1-10/+10
function old new delta nexpr 702 725 +23 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07ash: cache more of uid/gid syscallsDenys Vlasenko4-10/+30
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>
2024-10-07ash: make "test -x" use cached groupinfoDenys Vlasenko3-6/+19
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>
2024-10-07libbb: simplify parameter passing in is_in_supplementary_groups()Denys Vlasenko4-20/+34
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>
2024-10-07ash: command -v CMD must skip (go to next path) when CMD exists, but is not ↵Denys Vlasenko1-3/+51
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>
2024-10-07libbb: move is_in_supplementary_groups() from test to libbbDenys Vlasenko3-19/+26
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>
2024-10-06test: Invert return value of test_eaccess and rename it to test_st_modeDenys Vlasenko1-16/+11
From dash: From: herbert <herbert@gondor.apana.org.au> Date: Wed, 2 Mar 2005 22:14:54 +1100 Invert return value of test_eaccess and rename it to test_st_mode. function old new delta nexpr 800 766 -34 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06test: code shrinkDenys Vlasenko1-1/+1
function old new delta nexpr 813 800 -13 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06networking/libiproute/iplink.c: fix support for older kernelsThomas Devoogdt1-0/+21
- The CAN netlink interface has been added in Linux v2.6.31 with only 3 options [1]: CAN_CTRLMODE_LOOPBACK 0x1 /* Loopback mode */ CAN_CTRLMODE_LISTENONLY 0x2 /* Listen-only mode */ CAN_CTRLMODE_3_SAMPLES 0x4 /* Triple sampling mode */ So define the other options. - IFLA_CAN_TERMINATION has been added in Linux 4.11 [2], define it for older kernels. [1] https://github.com/torvalds/linux/blob/v2.6.31/include/linux/can/netlink.h#L80-L82 [2] https://github.com/torvalds/linux/commit/12a6075cabc0d9ffbc0366b44daa22f278606312 Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06libbb: fix sha1 on !x86 if CONFIG_SHA1_HWACCEL=yRudi Heitbaum1-0/+2
fixes non i386 and x86 builds libbb/hash_md5_sha.c: In function 'sha1_end': libbb/hash_md5_sha.c:1316:35: error: 'sha1_process_block64_shaNI' undeclared 1316 | || ctx->process_block == sha1_process_block64_shaNI Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-06ash: fix regression with 'exec sh -s'Ron Yorston1-9/+15
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.
2024-10-02win32: adjust usage for timeout and pipe_progressRon Yorston2-3/+3
Reduce the divergence from upstream in the usage messages for timeout and pipe_progress. This only affects the source; there are no visible of functional changes.
2024-09-30win32: work around problem with stderr in MSVCRTRon Yorston2-4/+5
Try to run a non-existent command with standard error closed: xyz 2>&- In recent versions of busybox-w32 this resulted in problems with moving through history (either using up/down keys or ctrl-r) and tab completion. In all cases the order of the prompt and the command were reversed. Bisection showed the problem was first seen in PRE-5396 which merged some commits from upstream, including fd47f0567 (lineedit: print prompt and editing operations to stderr). This (eventually) called to mind a previous problem with stderr in xargs which was fixed by commit f192e6539 (xargs: fix 'xargs -sNUM' tests). In both cases it seemed that mixing calls to bb_putchar_stderr() and fprintf(stderr, ...) was at fault. The former uses a file descriptor while the latter uses a stream. It was almost as if the stream was buffered. - The problem with xargs affected 32-bit and 64-bit builds with MSVCRT. - The problem with '2>&-' only affected 32-bit builds with MSVCRT. - Neither problem was present with UCRT builds. As a workaround change bb_putchar_stderr() to use the stderr stream in builds for MSVCRT. Saves 16 bytes in the 32-bit build. (GitHub issue #460)
2024-09-28hush: whitespace and comment fixesDenys Vlasenko1-43/+27
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27ash: reject unknown long optionsRon Yorston1-1/+2
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>
2024-09-27lineedit: use stdout for shell history builtinRon Yorston1-1/+1
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. function old new delta show_history 47 42 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5) Total: -5 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27ed: fix line insertion before current line. Closes 15081Ron Yorston2-0/+23
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. function old new delta insertLine 162 180 +18 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 18/0) Total: 18 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-09-27fixdep: add fstat error handlingSam James1-2/+9
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>
2024-09-27libbb: send usage messages to correct streamRon Yorston1-13/+17
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>
2024-09-27libbb: use full_write1_str() to shrink busybox_main()Ron Yorston1-13/+11
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>
2024-09-27lineedit: make save_history() FAST_FUNCDenys Vlasenko2-6/+6
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>
2024-09-27win32: drop workaround for Wine console bufferRon Yorston2-10/+3
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.