aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
| * ash: optional sleep builtinShawn Landden2022-08-271-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | function old new delta sleepcmd - 10 +10 builtintab 352 360 +8 .rodata 105264 105271 +7 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 25/0) Total: 25 bytes Signed-off-by: Shawn Landden <shawnlandden@tutanota.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix use-after-free in bash pattern substitutionSören Tempel2022-08-021-0/+7
| | | | | | | | | | | | | | | | function old new delta subevalvar 1566 1564 -2 Signed-off-by: Sören Tempel <soeren@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix use-after-free in pattern substituon codeDenys Vlasenko2022-08-021-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by soeren@soeren-tempel.net The idx variable points to a value in the stack string (as managed by STPUTC). STPUTC may resize this stack string via realloc(3). If this happens, the idx pointer needs to be updated. Otherwise, dereferencing idx may result in a use-after free. function old new delta subevalvar 1562 1566 +4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix ifs cleanup on error pathsDenys Vlasenko2022-08-025-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Alex Gorinson <algore3698@gmail.com> function old new delta evalvar 477 495 +18 varvalue 603 618 +15 subevalvar 1557 1572 +15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 48/0) Total: 48 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge branch 'busybox' into mergeRon Yorston2022-06-272-7/+5
|\|
| * ash,hush: use HOME for tab completion and promptsRon Yorston2022-06-262-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ash and hush correctly use the value of HOME for tilde expansion. However the line editing code in libbb obtains the user's home directory by calling getpwuid(). Thus tildes in tab completion and prompts may be interpreted differently than in tilde expansion. When the line editing code is invoked from a shell make it use the shell's interpretation of tilde. This is similar to how GNU readline and bash collaborate. function old new delta get_homedir_or_NULL 29 72 +43 optschanged 119 126 +7 hush_main 1204 1211 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 57/0) Total: 57 bytes v2: Always check for HOME before trying the password database: this is what GNU readline does. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: code shrinkRon Yorston2022-05-201-46/+50
| | | | | | | | | | | | | | | | | | | | | | Commit 6f8b2f450 (ash: forkshell code shrink) noted that certain global variables were being passed around in the forkshell structure unnecessarily. In fact, since the variables are global there's no need to pass them to the *_size()/*_copy() functions at all. This only saves 32 bytes of bloat (the compiler got there ahead of us) but it does make the code tidier.
* | ash: restore special variables when replaced by localRon Yorston2022-05-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit 3194a475d (ash: export certain variables to the environment immediately) caused the special variables BB_OVERRIDE_APPLETS, BB_SKIP_ANSI_EMULATION and BB_SYSTEMROOT to be exported to the environment. If one of these variables is replaced by a local variable its previous value should be re-exported on leaving the local context (function or simple command). (GitHub issue #256)
* | Merge branch 'busybox' into mergeRon Yorston2022-05-121-1/+1
|\|
| * style fixDenys Vlasenko2022-05-011-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: code shrinkRon Yorston2022-05-101-2/+1
| | | | | | | | | | Changing one of the constants used by is_bb_var() saves a few bytes in the 32-bit build.
* | ash: export certain variables to the environment immediatelyRon Yorston2022-05-081-1/+41
| | | | | | | | | | | | | | | | | | | | | | The environment variables BB_OVERRIDE_APPLETS, BB_SKIP_ANSI_EMULATION and BB_SYSTEMROOT affect of the behaviour of the shell itself. Setting them as shell variables is insufficient for them to affect the current shell. When these three variables are exported from the shell they are now placed in the environment immediately. Conversely, when they're unset or unexported they're removed from the environment.
* | ash: don't set OLDPWD on startupRon Yorston2022-05-071-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Commit f9b753e70 (ash: set current working directory on startup) set the current working directory of an interactive, non-login shell during startup to ensure drives mapped to a network share and symlinks were reported correctly. It had the side effect of setting OLDPWD. This is unnecessary because the current working directory won't have changed. (GitHub issue #253)
* | win32: allow preference for applets to be disabled at runtimeRon Yorston2022-05-061-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default busybox-w32 configuration enables the PREFER_APPLETS and SH_STANDALONE features. Sometimes it may be desirable to override the default preference for applets, for example, if an applet needs to be replaced by an external program with additional features. Add support for the environment variable BB_OVERRIDE_APPLETS. Its value may be: - a single dash ('-'): all applets are overridden; - a space-separated list of names: only the specified applets are overridden.
* | win32: search PATH for missing Unix-style executablesRon Yorston2022-05-061-23/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 41ef232fc5 (win32: use built-in applets for non-existent binaries with Unix-style paths) alters what happens when trying to find an executable. If all of the following apply: - the pathname starts with one of the standard directories for Unix executables (/bin, /usr/bin, /sbin, /usr/sbin); - the file isn't found relative to the system root; - the basename matches an applet then the applet is run. Further extend the procedure so that if the first two conditions are met and either: - the PREFER_APPLETS and SH_STANDALONE features are enabled and the basename *doesn't* match an applet or - the PREFER_APPLETS and SH_STANDALONE features are disabled then PATH is searched for the basename. This affects: - how interpreters and binaries are spawned by mingw_spawn_interpreter() and mingw_spawnvp(); - how 'which' and the shell search for binaries. Special steps need to be taken in the shell to avoid treating shell built-ins and functions as applets. As a consequence of this change: - An executable that isn't an applet, say curl.exe, can be run as /usr/bin/curl so long as it's in a directory in PATH. It doesn't have to be in C:/usr/bin. - If the PREFER_APPLETS and SH_STANDALONE features are disabled binaries can be run using paths referring to standard Unix directories even if they're installed elsewhere in PATH.
* | which,ash: changes to which/command/typeRon Yorston2022-05-011-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change how 'which' detects if it was run from a standalone shell: the shell passes the undocumented '-s' option. This is stricter and more reliable than the previous method of checking the name of the binary. Add a function to determine the binary associated with a given applet name. This makes it possible for 'which' and 'command -v' to list the correct binary even for applets other than 'busybox'. For example, when the binary is called 'sh.exe' 'which sh' will report its path. In standalone shell mode 'command -V' and 'type' now report "xxx is a builtin applet" rather than "xxx is xxx", which is true but not very illuminating. (GitHub issue #248)
* | ash: avoid misleading '.exe' in standalone shell modeRon Yorston2022-04-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In dash a command with an explicit path has an index value of -1 in its cmdentry structure. Upstream BusyBox extends this to allow other negative values for applets in standalone shell mode. busybox-w32 adds a further extension, with the index value INT_MIN indicating an applet with a Unix-style path. In describe_command() the command should only have a '.exe' extension added for index == -1, the original dash case of an explicit path. (GitHub issue #248)
* | Merge branch 'busybox'Ron Yorston2022-04-075-4/+18
|\|
| * ash: do not truncate failed tilde expansion on unknown user namesDenys Vlasenko2022-03-011-3/+1
| | | | | | | | | | | | | | | | | | | | | | Do not skip over "*p = c;" statement. Testcase: echo ~~nouser/qwe function old new delta argstr 1396 1406 +10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix unsafe use of mempcpyDenys Vlasenko2022-03-011-1/+7
| | | | | | | | | | | | | | function old new delta subevalvar 1549 1557 +8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: don't read past end of var in subvareval for bash substitutionsSören Tempel2022-03-015-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this patch, BusyBox handles bash pattern substitutions without a terminating '/' character incorrectly. Consider the following shell script: _bootstrapver=5.0.211-r0 _referencesdir="/usr/${_bootstrapver/-*}/Sources" echo $_referencesdir This should output `/usr/5.0.211/Sources`. However, without this patch it instead outputs `/usr/5.0.211Sources`. This is due to the fact that BusyBox expects the bash pattern substitutions to always be terminated with a '/' (at least in this part of subvareval) and thus reads passed the substitution itself and consumes the '/' character which is part of the literal string. If there is no '/' after the substitution then BusyBox might perform an out-of-bounds read under certain circumstances. When replacing the bash pattern substitution with `${_bootstrapver/-*/}`, or with this patch applied, ash outputs the correct value. Signed-off-by: Sören Tempel <soeren@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: let $HOME set home directory of login shellRon Yorston2022-03-221-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In busybox-w32 the shell option '-l' sets HOME to the user's home directory, as determined by a call to GetUserProfileDirectory(). This is differs from how shells work on Unix, where HOME is usually set by login(1). Allow the user to override this behaviour by setting HOME before starting the shell. If HOME isn't set or contains an empty string the previous behaviour applies. If HOME is set to a non-empty string the user should ensure that it represents a valid absolute path. (GitHub issue #244)
* | ash: try harder to avoid ctrl-c issueRon Yorston2022-02-271-24/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Commit 96a647690 (ash: prevent issue with ctrl-c and echo in loop) attempted to fix the problem that interrupting a loop like: while true; do echo hello; done caused the shell to exit. However, it wasn't completely effective and it only applied to echo and printf, not other builtins. Revert 96a647690 and instead don't call raise_interrupt() from crtl_handler() for the foreground interactive shell.
* | ash: workaround for UCRT bugRon Yorston2022-02-121-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There seems to be a bug in UCRT such that if a process has been started by passing a non-NULL environment block to CreateProcess() any subsequent call to spawnve() with a non-NULL environment pointer results in a crash. Commit 5b48ca53b (win32: pass NULL to spawnve, not environ) fixed the problem in busybox-w32 for those cases where a NULL environment pointer was sufficient. It didn't handle the case where the shell passes a modified environment to its child. All calls to spawnve() in the shell occur in a process which will terminate whether or not the call succeeds. It therefore doesn't matter if we mess with the environment of this process to allow spawnve() to be passed a NULL environment pointer. Do this for UCRT builds only. (GitHub issue #234)
* | Merge busybox into mergeRon Yorston2022-02-093-38/+90
|\| | | | | | | | | | | | | | | Fix conflicts in reset and ash. Redefine the new safe_read_key() as a reference to read_key(). Disable SHA256_HWACCEL.
| * *: slap on a few ALIGN_PTR where appropriateDenys Vlasenko2022-02-061-5/+5
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * *: slap on a few ALIGN* where appropriateDenys Vlasenko2022-02-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map" function old new delta .rodata 108586 108460 -126 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-126) Total: -126 bytes text data bss dec hex filename 970412 4219 1848 976479 ee65f busybox_old 970286 4219 1848 976353 ee5e1 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash,hush: fix handling of SIGINT while waiting for interactive inputDenys Vlasenko2022-01-172-29/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta lineedit_read_key 160 237 +77 __pgetc 522 589 +67 fgetc_interactive 244 309 +65 safe_read_key - 39 +39 read_key 588 607 +19 record_pending_signo 23 32 +9 signal_handler 75 81 +6 .rodata 104312 104309 -3 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 6/1 up/down: 282/-3) Total: 279 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: add comments about SIGINT-related problemsDenys Vlasenko2022-01-162-5/+9
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> SETUP_ENV_CHDIRDenys Vlasenko2022-01-132-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | Double negatives are hard to grok. function old new delta login_main 986 988 +2 su_main 474 470 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-4) Total: -2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge busybox into mergeRon Yorston2022-01-131-4/+13
|\| | | | | | | | | | | | | Fix merge conflicts in coreutils/ls.c and shell/ash.c. Update config files to turn off SHA1_HWACCEL. It uses non-portable assembler.
| * ash: ^C with SIG_INGed SIGINT should not exit the shellDenys Vlasenko2022-01-131-1/+7
| | | | | | | | | | | | | | function old new delta __pgetc 501 522 +21 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * reset: better --help textDenys Vlasenko2022-01-121-3/+6
| | | | | | | | | | | | | | function old new delta packed_usage 34175 34233 +58 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | Merge busybox into mergeRon Yorston2022-01-062-4/+4
|\| | | | | | | | | | | Fix merge conflict in miscutils/less.c. Use exit_SUCCESS() where possible.
| * libbb: code shrink: introduce and use [_]exit_SUCCESS()Denys Vlasenko2022-01-052-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta exit_SUCCESS - 7 +7 _exit_SUCCESS - 7 +7 run_pipe 1562 1567 +5 pseudo_exec_argv 399 400 +1 finish 86 87 +1 start_stop_daemon_main 1109 1107 -2 shutdown_on_signal 38 36 -2 runsv_main 1662 1660 -2 redirect 1070 1068 -2 read_line 79 77 -2 pause_and_low_level_reboot 54 52 -2 list_i2c_busses_and_exit 483 481 -2 less_exit 12 10 -2 identify 4123 4121 -2 grep_file 1161 1159 -2 getty_main 1519 1517 -2 fsck_minix_main 2681 2679 -2 free_session 132 130 -2 fdisk_main 4739 4737 -2 clean_up_and_exit 53 51 -2 bsd_select 1566 1564 -2 bb_daemonize_or_rexec 198 196 -2 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 3/17 up/down: 21/-34) Total: -13 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: pass NULL to spawnve, not environRon Yorston2021-10-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Building busybox-w32 for use with UCRT results in mysterious failures. (GitHub issue #234) These are somehow related to the environment values passed to spawnve. In several places the global environ pointer was being passed to spawnve so the child would inherit its environment from the parent. This can also be achieved by passing a NULL pointer. This prevents the failures in at least some cases and also makes the binary smaller.
* | ash: display job id and pid of background commandsRon Yorston2021-10-141-1/+5
| | | | | | | | | | | | | | Several common shells display the job id and pid of background commands. Even the Unix V7 Bourne shell displays the pid. This is unrelated to whether job control is available or enabled.
* | ash: silence compiler warningsRon Yorston2021-10-141-3/+3
| | | | | | | | | | On 64-bit systems mingw-w64 defines pid_t as a 64-bit integer so some printf calls caused compiler warnings.
* | Merge branch 'busybox' into mergeRon Yorston2021-10-1319-184/+331
|\|
| * shell: tweak --helpDenys Vlasenko2021-10-132-2/+2
| | | | | | | | | | | | | | | | Even though formally it is -s [ARGS], "sh -s" without ARGS is the same as just "sh". And we are already over 80 chars wide for ash --help, so make it shorter. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: in a comment, document what -i might be doingDenys Vlasenko2021-10-132-6/+28
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: use more compact SHELL_ASH / HUSH config defines. no code changesDenys Vlasenko2021-10-121-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: fix script's comm field if ENABLE_FEATURE_PREFER_APPLETS=yDenys Vlasenko2021-10-114-0/+52
| | | | | | | | | | | | | | | | | | | | function old new delta re_execed_comm - 46 +46 main 72 86 +14 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 60/0) Total: 60 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * *: add NOINLINEs where code noticeably shrinksDenys Vlasenko2021-10-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta display 85 1463 +1378 -73 bytes select_and_cluster - 1088 +1088 -139 bytes parse_reply - 979 +979 -109 bytes zbc_num_sqrt - 632 +632 -191 bytes show_bridge_port - 585 +585 -56 bytes sp_256_proj_point_add_8 - 576 +576 -45 bytes encode_then_append_var_plusminus - 554 +554 -118 bytes read_mode_db - 537 +537 -47 bytes fbset_main 1331 747 -584 sp_256_ecc_mulmod_8 1157 536 -621 brctl_main 2189 1548 -641 expand_one_var 2544 1872 -672 zxc_vm_process 6412 5589 -823 send_queries 1813 725 -1088 recv_and_process_peer_pkt 2245 1018 -1227 bb_dump_dump 1531 80 -1451 ------------------------------------------------------------------------------ (add/remove: 7/0 grow/shrink: 1/8 up/down: 6329/-7107) Total: -778 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * Make const ptr assign as function call in clangYU Jincheng2021-10-091-3/+3
| | | | | | | | | | | | | | | | - This can act as memory barrier in clang to avoid read before assign of a const ptr Signed-off-by: LoveSy <shana@zju.edu.cn> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: speed up ${x//\*/|} tooDenys Vlasenko2021-10-091-4/+9
| | | | | | | | | | | | | | function old new delta expand_one_var 2502 2544 +42 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: speed up ${x//\*/|} too, make it independent of ASH_OPTIMIZE_FOR_SIZEDenys Vlasenko2021-10-091-6/+12
| | | | | | | | | | | | | | function old new delta subevalvar 1503 1545 +42 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash.c: speedup ${s:} substring (no quotes)Alin Mr2021-10-091-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | This trivial patch makes ${s:...} at least as fast as ${s#??..} in simple tests. It's probably faster for longer substrings, but then one wouldn't use ${s#"1024???s"} anyway - one would switch away from sh. function old new delta subevalvar 1457 1503 +46 Signed-off-by: Alin Mr <almr.oss@outlook.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * *: generalize "const trick"YU Jincheng2021-10-071-20/+3
| | | | | | | | | | | | | | | | While at it, change all "__asm__" to "asm" Co-authored-by: canyie <31466456+canyie@users.noreply.github.com> Signed-off-by: YU Jincheng <shana@zju.edu.cn> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix compile breakage in !ENABLE_ASH_ALIAS configDenys Vlasenko2021-09-281-2/+2
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>