aboutsummaryrefslogtreecommitdiff
path: root/util-linux/script.c (unfollow)
Commit message (Collapse)AuthorFilesLines
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.
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.