aboutsummaryrefslogtreecommitdiff
path: root/shell/shell_common.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* ash: fix 'read' built-in performance regressionRon Yorston2024-03-061-0/+4
| | | | | | | | | | | | | | Commits 8e6991733 and b2901ce8e fixed problems with the 'read' shell built-in when the '-t' option was used. However, they result in a performance penalty. This pipeline: seq -w 0 999999 | while read line; do :; done takes 10 times longer than prior to the changes. If no timeout is specified don't call poll(2). Costs 16 bytes in a 32-bit build; 0 in 64-bit.
* Merge branch 'busybox' into mergeRon Yorston2023-07-131-1/+20
|\
| * shell: move varcmp() to shell_common.h and use it in hushDenys Vlasenko2023-06-171-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta unset_local_var - 112 +112 findvar 31 35 +4 set_vars_and_save_old 144 141 -3 helper_export_local 235 230 -5 set_local_var 425 416 -9 handle_changed_special_names 38 27 -11 builtin_unset 154 141 -13 builtin_getopts 404 391 -13 get_local_var_value 281 260 -21 get_ptr_to_local_var 71 45 -26 unset_local_var_len 139 - -139 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/8 up/down: 116/-240) Total: -124 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell/read: do not allow empty variable nameDenys Vlasenko2023-06-171-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: fix 'read' shell built-in (1)Ron Yorston2023-07-121-16/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this test case: { echo -n te; sleep 3; echo st; } | (read -t 1 x; echo "$x") - bash echoes "te" after 1 second. - Upstream BusyBox echoes an empty "$x" after 1 second. - busybox-w32 echoes an empty "$x" after 3 seconds. The delayed echo in busybox-w32 arises because the 'read' shell built-in omits the code to poll for input. Rearrange the code so that polling takes place. This doesn't address the difference between BusyBox and bash. Costs 48-64 bytes.
* | ash: properly echo console input to 'read' built-inRon Yorston2023-07-121-2/+2
| | | | | | | | | | | | | | The 'read' shell built-in echoed console input to stdout. Echo directly to the console instead. Costs 124-136 bytes.
* | ash: remove ASH_IGNORE_CR config optionRon Yorston2023-04-091-10/+1
| | | | | | | | | | | | | | | | | | | | | | | | No further problems with CRLF handling have been reported. Remove the configuration option that allowed some recent changes to be turned off. Also, prevent some WIN32 code from being included in the POSIX build. The faulty code is from commit 64c8f5f3d (ash: add support for INT trap). These changes don't alter the default WIN32 build.
* | win32: virtual terminal input fixesRon Yorston2023-03-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | - Disable ENABLE_PROCESSED_INPUT in raw mode. Otherwise ^C isn't immediately detected during shell command line editing with virtual terminal input enabled. - Switch read_key()/unix_readkey() to windows_read_key()/read_key(). This allows the shell `read` builtin to use windows_read_key(). Without this change `read` fails when virtual terminal input is enabled.
* | ash: drop workaround for 'read -t 0'Ron Yorston2023-03-051-12/+0
| | | | | | | | | | | | | | | | | | Commit 0eda390d6 (ash: improve handling of 'read -t 0') added code to work around the limitations of our poll(2) implementation. Now that poll(2) has been improved the workaround is unnecessary. Saves 64 bytes.
* | ash: improve CRLF handling in readRon Yorston2023-02-121-0/+24
| | | | | | | | | | | | | | | | | | | | | | Commit deae0c7bf3 (Skip carriage return in read builtin command) caused all CRs to be removed from input to the read builtin. Only remove CRs that are part of a CRLF pair. Adds 64-80 bytes. (GitHub issue #285)
* | ash: remove CRs from CRLF during field splittingRon Yorston2023-02-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit e371e46fa0 (shell: add \r to IFS) added '\r' to the IFS variable so field splitting would remove carriage returns. Rather than change IFS, remove CRs preceding LFs in regions being scanned for field splitting before IFS is applied. This prevents free-standing CRs from being removed. Costs 112-120 bytes. (GitHub issue #285)
* | Merge busybox into mergeRon Yorston2022-02-091-0/+1
|\| | | | | | | | | | | | | | | Fix conflicts in reset and ash. Redefine the new safe_read_key() as a reference to read_key(). Disable SHA256_HWACCEL.
| * shell: add comments about SIGINT-related problemsDenys Vlasenko2022-01-161-0/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2021-06-071-2/+2
|\|
| * shells: do not allow bare "read" in non-bash compat configsDenys Vlasenko2021-06-061-1/+1
| | | | | | | | | | | | | | | | On Sat, Feb 9, 2019 Cristian Ionescu-Idbohrn wrote: > In my case (at work), I have to watch and prevent people from doing > unportable things. For me, that's a burden. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: also do word splitting when -d DELIM is usedEicke Herbertz2021-06-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original commit 3bef5d89b0 introduced an additional check for an unset `opt_d` before doing word splitting. I'm unsure why it's there in the first place, but the commit message also describes a different behaviour than what -d actually does in bash, while the code mostly does the right thing. `opt_d` sets the line delimiter for read to stop reading and should not affect word splitting. Testcase: $ echo qwe rty | { read -d Z a b; echo a:$a b:$b; } a:qwe b:rty function old new delta shell_builtin_read 1314 1304 -10 Signed-off-by: Eicke Herbertz <wolletd@posteo.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2021-01-141-4/+17
|\|
| * shells: a fix for systems without RLIMIT_NICEDenys Vlasenko2020-12-171-3/+16
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * decrease paddign: gcc-9.3.1 slaps 32-byte alignment on arrays willy-nillyDenys Vlasenko2020-11-301-1/+1
| | | | | | | | | | | | | | | | text data bss dec hex filename 1021988 559 5052 1027599 fae0f busybox_old 1021236 559 5052 1026847 fab1f busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2020-08-231-1/+5
|\|
| * shell: Fix "read -d ''" behaviorChristian Eggers2020-07-311-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | With bash's read builtin it is possible to read from a file (e.g. device-tree) until the first '\0' character: IFS= read -r -d '' VARIABLE < file In busybox ash the -d extension is also implemented, but checking the read character for '\0' has to be performed after comparing with the delimiter. Signed-off-by: Christian Eggers <ceggers@arri.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: proper accounting for backspaces in the read builtinRon Yorston2020-05-141-0/+1
| | | | | | | | | | | | When the '-n' option of the 'read' builtin is used we need to account for backspaces: increase 'nchars' when backspace removes a character from the buffer.
* | ash: fixes to handling of ctrl-C in read builtinRon Yorston2020-02-081-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this script: while read -r; do echo $REPLY; done echo hello There are currently two problems with this when the read is interrupted by ctrl-C: - The error return code is 0 when it should be 130; - The echo command is executed. Fix these issues by propagating the control event to the process that would have caught it if the read builtin hadn't grabbed keyboard input.
* | ash: catch EOF in read builtinRon Yorston2020-02-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The read builtin didn't detect EOF so it wasn't possible to cleanly terminate a loop like: while read -r; do echo $REPLY; done Consider how Linux handles EOF (represented as ^D, though this isn't echoed): $ awk '{print}' | xxd abc^D123 ^D 00000000: 6162 6331 3233 0a abc123. Contrast with busybox-w32 on Windows (where the ^Z is echoed): $ awk '{print}' | xxd abc^Z123 ^Z 00000000: 6162 631a 3132 330a abc.123. In both cases EOF is only detected at the start of a line. On Linux EOF within a line is dropped; on Windows it's output as a literal ctrl-Z. Implement similar behaviour for the read builtin.
* | ash: process backspace in read builtinRon Yorston2020-02-071-0/+10
| | | | | | | | | | | | | | | | | | | | | | Previously the 'read' builtin had no special treatment for backspace characters entered in interactive mode: they were simply added to the string being read. Change this so that backspace deletes the previous character from the buffer and updates the display to match. It still doesn't handle tabs in the input or lines that are larger than the console width.
* | Merge branch 'busybox' into mergeRon Yorston2020-01-081-18/+59
|\|
| * shell/ulimit: code shrinkDenys Vlasenko2019-10-211-18/+59
| | | | | | | | | | | | | | | | text data bss dec hex filename 1001949 551 5612 1008112 f61f0 busybox_old 1001906 551 5612 1008069 f61c5 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2019-08-161-1/+1
|\|
| * libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne2019-07-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2019-05-271-129/+214
|\|
| * hush: fix "export PS1=xyz" and "local PS1=xyz" messing up promptDenys Vlasenko2019-05-141-14/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta helper_export_local 215 253 +38 leave_var_nest_level 107 127 +20 run_pipe 1840 1857 +17 handle_changed_special_names 101 105 +4 shell_builtin_read 1399 1398 -1 done_word 767 766 -1 parse_stream 2249 2245 -4 set_local_var 437 430 -7 is_well_formed_var_name 66 - -66 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 4/4 up/down: 79/-79) Total: 0 bytes text data bss dec hex filename 952376 485 7296 960157 ea69d busybox_old 952400 485 7296 960181 ea6b5 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: ulimit: add -i RLIMIT_SIGPENDING, -q RLIMIT_MSGQUEUEDenys Vlasenko2019-04-281-3/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta limits_tbl 104 120 +16 ulimit_opt_string 44 50 +6 limit_chars 14 16 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 24/0) Total: 24 bytes text data bss dec hex filename 981996 485 7296 989777 f1a51 busybox_old 982065 485 7296 989846 f1a96 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: bash compat for ulimit: reorder to matchDenys Vlasenko2019-04-281-72/+53
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: bash compat for ulimit: -w => -x, -p => -uDenys Vlasenko2019-04-271-12/+16
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: fix ulimit to be more bash-compat, closes 11791Denys Vlasenko2019-04-271-84/+181
| | | | | | | | | | | | | | | | | | | | function old new delta shell_builtin_ulimit 486 651 +165 limit_chars - 14 +14 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 179/0) Total: 179 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: improve handling of 'read -t 0'Ron Yorston2019-02-081-4/+12
| | | | | | | | | | | | | | | | | | | | Instead of always returning that no input is available: - for a disk file return 'available'; - for the console return 'not available'; - for anything else (e.g. pipe) return whatever poll says. This fixes the test ash-read/read_t0.tests.
* | win32: add support for the euro currency symbolRon Yorston2019-02-021-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The euro currency symbol was added to some OEM code pages. See: https://www.aivosto.com/articles/charsets-codepages-dos.html Add a configuration option (enabled by default) to support this. When enabled: - The read_key() function requests wide character key events. This allows the euro symbol to be entered regardless of the console OEM code page, though it needs to be available in the ANSI code page. - Conversions between OEM and ANSI code pages in winansi.c are modified to work around a bug in the Microsoft routines. - If the OEM code page is 850 when BusyBox starts it's changed to 858. This is the only currently supported OEM code page. Also, the shell read builtin is modified to use read_key() whenever input is being taken from the console.
* | Merge branch 'busybox' into mergeRon Yorston2018-09-101-30/+27
|\|
| * ash,hush: fold shell_builtin_read() way-too-many params into a struct paramDenys Vlasenko2018-08-051-29/+26
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta getoptscmd 587 584 -3 readcmd 240 224 -16 shell_builtin_read 1426 1399 -27 builtin_read 210 182 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-74) Total: -74 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2018-05-131-1/+36
|\|
| * hush: fix IFS handling in readDenys Vlasenko2018-04-111-1/+36
| | | | | | | | | | | | | | | | | | | | | | | | $ echo "X:Y:" | (IFS=": " read x y; echo "|$x|$y|") |X|Y| $ echo "X:Y : " | (IFS=": " read x y; echo "|$x|$y|") |X|Y| function old new delta shell_builtin_read 1320 1426 +106 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: make 'read -s' workRon Yorston2018-04-101-1/+2
| | | | | | | | | | | | Raw input should also be used when the -s flag is present. Related to GitHub issue #112.
* | Merge branch 'busybox' into mergeRon Yorston2018-04-091-1/+0
|\|
| * libbb.h: always include sys/resource.hDenys Vlasenko2018-04-081-1/+0
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: emulate raw input to read builtinRon Yorston2018-04-051-2/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | Use read_key to emulate raw input when reading from the console. Limit this to cases where raw input is necessary: - a maximum number of characters is to be read (-n) - a timeout has been specified (-t) - a non-standard delimiter is in use (-d) This should fix GitHub issue #112 (and other things too!). Also, omit sections of code that serve no purpose on WIN32.
* | Merge branch 'busybox' into mergeRon Yorston2017-09-271-2/+2
|\|
| * hush: GETOPT_RESET() _after_ getopts too.Denys Vlasenko2017-08-291-2/+2
| | | | | | | | | | | | | | | | | | NOEXEC'ed applets which use getopt() need this. function old new delta builtin_getopts 403 413 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2017-08-221-3/+6
|\|
| * shell: more efficient check for EOL in readDenys Vlasenko2017-08-091-4/+3
| | | | | | | | | | | | | | function old new delta shell_builtin_read 1334 1320 -14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: implement -d DELIM option for readJohannes Schindelin2017-08-091-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The POSIX standard only requires the read builtin to handle -r: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html However, Bash introduced the option -d <DELIM> to override IFS for just one invocation, and it is quite useful. It is also super easy to implement in BusyBox' ash, so let's do that. The motivation: This option is used by Git's test suite. function old new delta .rodata 163505 163587 +82 shell_builtin_read 1244 1289 +45 readcmd 233 259 +26 builtin_read 258 263 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 158/0) Total: 158 bytes Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>