aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
| * cut: rename some variables to hopefully better namesDenys Vlasenko2024-12-101-13/+19
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * cut: "orig_line" is redundant, remove itDenys Vlasenko2024-12-101-2/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * cut: allocate "printed" only if OPT_CHAR or OPT_BYTEDenys Vlasenko2024-12-101-3/+4
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * cut: localize 'spos' variable, convert !NUMVAR to NUMVAR == 0Denys Vlasenko2024-12-101-5/+6
| | | | | | | | | | | | This imporves readability Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * cut: simplify OPT_ names, eliminate one variableDenys Vlasenko2024-12-101-24/+27
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * cut: improve detection of invalid rangesRon Yorston2024-12-102-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. function old new delta .rodata 100273 100287 +14 cut_main 1239 1237 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-2) Total: 12 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * cut: fix "-s" flag to omit blank linesColin McAllister2024-12-102-5/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using cut with the delimiter flag ("-d") with the "-s" flag to only output lines containing the delimiter will print blank lines. This is deviant behavior from cut provided by GNU Coreutils. Blank lines should be omitted if "-s" is used with "-d". This change introduces a somewhat naiive, yet efficient solution, where line length is checked before looping though bytes. If line length is zero and the "-s" flag is used, the code will jump to parsing the next line to avoid printing a newline character. function old new delta cut_main 1196 1185 -11 Signed-off-by: Colin McAllister <colinmca242@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hexdump: fix regression with -n4 -e '"%u"'Natanael Copa2024-12-092-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | Fix bug introduced in busybox 1.37.0 that broke kernel builds. Fixes commit e2287f99fe6f (od: for !DESKTOP, match output more closely to GNU coreutils 9.1, implement -s) function old new delta rewrite 967 976 +9 Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: tidy argument checks in getopt32()Ron Yorston2024-12-091-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When getopt32() has complementary options it's possible to specify the minimum and maximum number of arguments allowed. Checking these values was inconsistent: - '?' correctly checked that it was followed by a digit but set the otherwise unused spec_flgs variable on error. - '=' failed to check that it was followed by a digit. function old new delta vgetopt32 1307 1319 +12 Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * chpst: fix error check of nice(2) callChristian Franke2024-12-091-1/+2
| | | | | | | | | | | | | | | | Check errno instead of return value because -1 is a valid return value also on success. Signed-off-by: Christian Franke <christian.franke@t-online.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: fix G.argv0_for_re_execing to avoid endless loopHajime Tazaki2024-12-091-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the busybox is used as /sbin/init and the inittab file contains below: ::respawn:-/bin/sh /sbin/init spawns hush for the first time with the argv[0] contains '-', and hush treats it as login shell. Then it reads /etc/profile and if the file contains the command execution like below, it invokes hush as login shell because the argv[0] argument is still '-/bin/sh' and reads /etc/profile again. This will last until some failure (e.g., memory failure) happens. [ "$(id -u)" -eq 0 ] && PS1="${PS1}# " || PS1="${PS1}\$ " This commit fixes this issues by adding an offset (+1) to the G.argv0_for_re_execing variable. This issue happens on our out-of-tree UML (use mode linux) with nommu configuration. Link: https://lore.kernel.org/all/cover.1731290567.git.thehajime@gmail.com/ Signed-off-by: Hajime Tazaki <thehajime@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | xargs: allow for quotes in commands on WindowsRon Yorston2024-12-301-2/+103
| | | | | | | | | | | | | | | | | | | | | | When xargs limited the length of the command lines it generated it didn't allow for the quoting Windows spawn() introduces. Properly account for any additional characters required when a command is spawned on Windows. If the command is a NOFORK applet this isn't necessary. Adds 384-464 bytes.
* | win32: code shrink quote_arg()Ron Yorston2024-12-301-24/+20
| | | | | | | | | | | | | | | | Alter quote_arg() to perform a single pass over the string in the case where no change is required. Based on a proposal by @avih in GitHub PR #317. Saves 16 bytes.
* | ash: strip trailing slash from directory if necessaryRon Yorston2024-12-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | The previous commit removed trailing dots and spaces from the last component of a pathname when changing directory. If the result has a trailing slash remove that too. But not if it's a drive root, to avoid 'cd C:/' showing a current directory of 'C:'. Adds 48 bytes. (GitHub issue #478)
* | ash: match behaviour of cmd.exe in cd builtinRon Yorston2024-11-193-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The Windows API strips trailing dots and spaces from the last component of a path. cmd.exe handles this quirk when changing directory by adjusting its idea of the current directory to match reality. The shell in busybox-w32 didn't do this, leading to some confusion. Fix the shell's cd builtin so it works more like cmd.exe. Adds 64-80 bytes. (GitHub issue #478)
* | tar: try harder to detect old tar filesRon Yorston2024-11-081-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code to autodetect compressed tar files failed to detect a bunzip2-compressed archive. When tar was invoked with the 'j' option it worked fine. The autodetection code looks for the magic string 'ustar' or a series of five NULs to determine that an archive is uncompressed. The failing archives had more than five NULs in the header and were taken to be uncompressed. Look for a longer run of NULs: 16 is certainly sufficient for the archives in question. Adds 8-16 bytes. (GitHub issue #475)
* | nproc: remove old codeRon Yorston2024-11-071-3/+1
| | | | | | | | | | | | | | | | | | Upstream commit 5a68a246e (nproc: prepare for arbitrarily large CPU masks) dynamically allocated the 'masks' array. When this was merged into busybox-w32 the old code was inadvertantly left in place. Remove it now. This has no effect on Windows builds.
* | libarchive: pdpmake requires some ar functionsRon Yorston2024-11-061-0/+1
| | | | | | | | | | | | | | pdpmake, like make, requires get_header_ar.o and unpack_ar_archive.o from libarchive. This dependency wasn't made explicit in Kbuild.src so building pdpmake failed unless other applets requiring those files were enabled (ar, dpkg, dpkg-deb or make).
* | win32: drop stream i/o workaroundRon Yorston2024-10-301-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | It seems that one of the workarounds for problems with stream i/o in MSVCRT was unnecessary. It also caused display glitches when the 32-bit binary was run on 64-bit systems. Remove it. Saves 112 bytes in the 32-bit build. (GitHub issue #472)
* | win32: try harder to prevent output to stdoutRon Yorston2024-10-291-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)
* | win32: more problems with stream i/o and MSVCRTRon Yorston2024-10-291-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)
* | ash: fix waiting for status of background jobRon Yorston2024-10-281-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)
* | ash: correctly identify nofork applets in error messageRon Yorston2024-10-281-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.
* | cut: improve detection of invalid rangesRon Yorston2024-10-281-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)
* | win32: update poll(2) to match latest gnulib versionRon Yorston2024-10-251-5/+6
| |
* | win32: workaround for pipe writability in poll(2)Ron Yorston2024-10-251-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)
* | make: .WAIT shoudn't have prerequisitesRon Yorston2024-10-231-1/+1
| | | | | | | | | | | | Commit f0dea6674 (make: enforce restrictions on prerequisites/ commands) set the flags for .WAIT incorrectly: in POSIX mode it shouldn't have prerequisites.
* | cut: detect error when bounds are reversedRon Yorston2024-10-222-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)
* | make: enforce restrictions on prerequisites/commandsRon Yorston2024-10-201-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.
* | make: changes to .DEFAULT/inference rulesRon Yorston2024-10-202-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.
* | make: fix test for empty command in inference ruleRon Yorston2024-10-201-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.
* | make: relax definition of comment lineRon Yorston2024-10-181-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.
* | make: improve chaining of implicit rulesRon Yorston2024-10-171-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.
* | make: look for PDPmakefileRon Yorston2024-10-171-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.
* | ash: update commentRon Yorston2024-10-131-1/+0
| | | | | | | | PPID is no longer fake.
* | win32: close exec'ing process if possibleRon Yorston2024-10-131-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)
* | kill: fix regression in 'kill -9'Ron Yorston2024-10-121-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)
* | win32: fix problem interrupting shell loopRon Yorston2024-10-111-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.
* | win32: fix regression in chdir(2)Ron Yorston2024-10-101-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.
* | id: code shrinkRon Yorston2024-10-093-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.
* | test: code shrink supplementary groupsRon Yorston2024-10-092-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.
* | Merge branch 'busybox' into mergeRon Yorston2024-10-087-66/+102
|\|
| * hexdump: accept hex numbers in -n, closes 16195Denys Vlasenko2024-10-081-3/+8
| | | | | | | | | | | | | | function old new delta hexdump_main 366 383 +17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: modify find_executable() to not temporarily write to PATHDenys Vlasenko2024-10-084-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>
| * hush: fix "type ./cat" and "command -v ./cat" to not scan PATHDenys Vlasenko2024-10-071-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>
| * hush: make "test -x" use cached groupinfoDenys Vlasenko2024-10-071-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>
* | libbb: code shrink supplementary group testRon Yorston2024-10-082-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.
* | Merge branch 'busybox' into mergeRon Yorston2024-10-086-49/+169
|\|
| * test: -x can return 0/1 early if all X bits are the sameDenys Vlasenko2024-10-071-10/+10
| | | | | | | | | | | | | | function old new delta nexpr 702 725 +23 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: cache more of uid/gid syscallsDenys Vlasenko2024-10-074-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>