aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'busybox' into mergeRon Yorston2023-04-171-4/+28
|\
| * ash,hush: tab completion of functions and aliasesRon Yorston2023-04-161-4/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit 9e2a5668f (ash,hush: allow builtins to be tab-completed, closes 7532) ash and hush have supported tab completion of builtins. Other shells, bash and ksh for example, also support tab completion of functions and aliases. Add such support to ash and hush. function old new delta ash_command_name - 92 +92 hush_command_name - 63 +63 ash_builtin_name 17 - -17 hush_builtin_name 38 - -38 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 0/0 up/down: 169/-55) Total: 100 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Avi Halachmi <avihpit@yahoo.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: more Unix-style path fixesRon Yorston2023-04-161-7/+19
| | | | | | | | | | | | | | | | | | | | | | Commit 950b318a2 (ash: Unix-style paths, shell builtins and applets) broke running of Unix-style absolute paths from the shell by PATH search. The copy of the program name on the stack should only be used in the first call to tryexec() otherwise it interferes with the use of the stack by padvance(). Also, bring the code to handle Unix-style paths in find_command() into line with the revised code in shellexec().
* | Merge branch 'busybox' into mergeRon Yorston2023-04-091-37/+32
|\|
| * ash: code shrink: do not take address of prefix(), allowing it to inlineDenys Vlasenko2023-04-031-8/+4
| | | | | | | | | | | | | | | | | | | | function old new delta getjob 281 285 +4 prefix 13 - -13 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 4/-13) Total: -9 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: code shrink - reuse is_prefixed_with() from libbbDenys Vlasenko2023-04-031-2/+4
| | | | | | | | | | | | | | | | | | | | | | function old new delta changepath 67 68 +1 legal_pathopt 70 66 -4 prefix 34 13 -21 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 1/-25) Total: -24 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: get rid of separate mail_var_path_changed flag variableDenys Vlasenko2023-04-031-10/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We can just clear mailtime_hash to zero and have the same effect. function old new delta changemail 8 11 +3 mail_var_path_changed 1 - -1 cmdloop 398 382 -16 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 3/-17) Total: -14 bytes text data bss dec hex filename 1054786 559 5020 1060365 102e0d busybox_old 1054773 559 5020 1060352 102e00 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix still-broken new mail detectionDenys Vlasenko2023-04-031-4/+4
| | | | | | | | | | | | | | | | padvance() exit condition is return value < 0, not == 0. After MAIL changing twice, the logic erroneously concluded that "you have new mail". Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: fix broken new mail detectionDenys Vlasenko2023-04-031-1/+0
| | | | | | | | | | | | | | | | | | | | Mea culpa, in "Do not allocate stack string in padvance" commit (I left an extraneous "break" statement). function old new delta cmdloop 329 398 +69 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: code shrinkDenys Vlasenko2023-04-011-3/+3
| | | | | | | | | | | | | | | | | | | | function old new delta describe_command 323 320 -3 dotcmd 324 309 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18) Total: -18 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: exec: Stricter pathopt parsing - lost chunkDenys Vlasenko2023-03-311-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: improve trap and jobs builtins in child shellsRon Yorston2023-03-311-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The trap and jobs builtins can be used to report information about traps and jobs. This works when they're called from the current shell but in a child shell the required information is usually cleared. Special hacks allow: - trap to work with command substitution; - jobs to work with command substitution or in a pipeline. Neither works with process substitution. - Relax the test for the trap hack so it also supports pipelines. - Pass the command to be evaluated to forkshell() in evalbackcmd() so trap and jobs both work with process substitution. function old new delta forkchild 629 640 +11 argstr 1502 1496 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 11/-6) Total: 5 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * ash: make EPOCH variables work if RANDOM is disabledRon Yorston2023-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 1d37186fe2 (ash: add bash-compatible EPOCH variables) added support for the EPOCHSECONDS and EPOCHREALTIME variables. These variables are dynamic and therefore require the VDYNAMIC flag to be non-zero. However, this is only the case if support for the RANDOM variable is enabled. Give VDYNAMIC a non-zero value if either EPOCH variables or RANDOM are enabled. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: remove ASH_IGNORE_CR config optionRon Yorston2023-04-091-19/+9
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | ash: special treatment for read builtinRon Yorston2023-04-051-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When INT is being trapped the read builtin gets special treatment in bash. In a top-level interactive shell interrupting the read with Ctrl-C clears the input and allows the user to enter a new string. In a subshell Ctrl-C really does interrupt the read and the trap isn't executed. zsh works similarly, except that in the latter case the trap is executed. dash interrupts the read and executes the trap in both cases. ksh also interrupts the read in both cases but only executes the trap in the first. Implement the bash behaviour. (GitHub issue #303)
* | ash: reinstate fix for ctrl-c issueRon Yorston2023-04-051-1/+1
| | | | | | | | | | Reinstate the change introduced in commit 96c104a61c (ash: try harder to avoid ctrl-c issue). It was removed during recent work on traps.
* | ash: add support for INT trapRon Yorston2023-04-031-10/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The trap builtin now handles INT. As before, other signals (from a limited list) are accepted but their traps don't have any effect. There's some variability in how shells handle traps. This patch upholds that proud tradition. Various changes are needed to make this work: - Line editing has a new flag to ignore Ctrl-C. - If INT is being trapped or ignored don't call raise_interrupt(). - A minimal implementation of dotrap() is provided. - Call dotrap() when the read builtin or line input detect Ctrl-C. - Adjust Ctrl-C detection when the INT trap is changed. - Set may_have_traps when an INT trap is set. Costs 368-448 bytes. (GitHub issue #303)
* | ash: fix POSIX buildRon Yorston2023-04-031-0/+2
| | | | | | | | | | | | Commit 950b318a2 (ash: Unix-style paths, shell builtins and applets) added a call to stack_add_ext_space() which should only be included when building for Microsoft Windows.
* | ash: Unix-style paths, shell builtins and appletsRon Yorston2023-03-311-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some shell builtins also exist as applets: echo, printf, pwd and test, for example. If such an applet is referenced using a Unix- style path, e.g. /usr/bin/echo, the applet should be run rather than the builtin. Instead the current code says: sh: /usr/bin/echo: file not found Rearrange the tests in shellexec() so the correct behaviour occurs. Actually, the error message was also incorrect due to a separate bug. Commit d71cb67ff (win32: revert special treatment of Unix-style absolute paths) failed to allocate space on the stack so that the command passed to tryexec() could have an extension added if required.
* | ash: changes to evalsubshell()Ron Yorston2023-03-281-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When a spawn_forkshell() was required in evalsubshell() two calls to expredir() were being made: one in the parent and one in the child. Rearrange the code so there's only one call, in the child. The call to expredir() in the child is necessary because copynode() doesn't take a copy of expfname in the nfile node. Code could be added to do this but it's cheaper to call expredir(). Add code in forkshell_evalsubshell() to turn off the EV_TESTED flag for background processes. I haven't found a case where this makes a difference but no doubt somebody would have eventually.
* | drop: adjust environment on privilege changeRon Yorston2023-03-271-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some environment variables are subject to special treatment: USER, LOGNAME, HOME and SHELL are initialised when the shell starts if they don't already have a value. Some adjustments are necessary when changing privilege level: - USERNAME is added to the set of variables subject to special treatment. Unlike the others this is normally set on Windows. - The special variables are now also updated on shell start up if the current process is running with elevated privileges. This is necessary so USER, USERNAME and LOGNAME have the correct value. - USER, USERNAME and LOGNAME are set to the name of the unprivileged user when elevated privileges are dropped, though not if they've been changed from the expected value of "root". Costs 160-208 bytes. (GitHub issue #300)
* | win32: changes to console mode handlingRon Yorston2023-03-051-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add the environment variable BB_TERMINAL_MODE as a more general way of controlling console/terminal mode setting. The default remains unchanged: use virtual terminal mode for output if possible but fall back to the console API with emulated ANSI escape sequences. Currently valid settings are: 0 Force use of console mode 1 Force use of virtual terminal mode for output 5 Prefer virtual terminal mode for output, fall back to console Other values won't do anything useful until code elsewhere has been updated. BB_SKIP_ANSI_EMULATION remains available for backwards compatibility. If both variables are set BB_TERMINAL_MODE takes precedence.
* | ash: revised CRLF handling for scriptsRon Yorston2023-02-211-1/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in commit 2d848eba5 (ash: fix CRLF handling), removing CRs from CRLF pairs in preadbuffer() is complicated by the possibility that a CRLF pair might be split across the boundary between buffers. Add a wrapper around calls to nonblock_immune_read() to allow for this. Adds 104-128 bytes. (GitHub issue #280)
* | ash: revert changes to handle CRLF in scriptsRon Yorston2023-02-211-34/+4
| | | | | | | | | | | | | | Commit 4b894b60a doesn't seem to have worked out. Revert it and the fix in 6e0a6b7e5. We're now back to removing CRs unconditionally from shell scripts.
* | ash: really reset ANSI emulation in interactive modeRon Yorston2023-02-201-2/+2
| | | | | | | | | | | | | | | | | | Commit 329f907b2 (ash: only reset ANSI emulation in interactive loop) claimed to move resetting of ANSI emulation up into the main interactive loop. Unfortunately it *just* missed the if-block for interactive mode. Put the call to skip_ansi_emulation() in the right place.
* | ash: only reset ANSI emulation in interactive loopRon Yorston2023-02-191-3/+3
| | | | | | | | | | | | | | | | | | | | | | Commit 54d2ea4b4 (ash: reset ANSI emulation at prompt) worked around a problem with MSYS2 applications. This seems to have been fixed in more recent versions of MSYS2 but there's still value in retaining the workaround for other such cases. However, the call to reset ANSI emulation is probably being made more often than necessary. Move it out of setprompt_if() and into the main shell interactive loop.
* | ash: skip CR when detecting end of here documentFRP-4882-g6e0a6b7e5Ron Yorston2023-02-151-1/+1
| | | | | | | | | | | | The change introduced by commit 4b894b60a (ash: change CRLF handling) failed to detect the end of a here document with a CRLF line ending. Add the necessary check.
* | Merge branch 'busybox' into mergeRon Yorston2023-02-131-1/+2
|\|
| * shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256Denys Vlasenko2023-01-261-1/+2
| | | | | | | | | | | | | | | | | | | | function old new delta record_pending_signo 32 63 +31 lineedit_read_key 231 224 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 31/-7) Total: 24 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | ash: remove CRs from CRLF during field splittingRon Yorston2023-02-101-3/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* | ash: change CRLF handlingRon Yorston2023-02-071-3/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As noted in commit 2d848eba5 (ash: fix CRLF handling) all CRs are removed when scripts are read. Allow an alternative approach (configurable at build-time, enabled by default): - Do not strip CRs from input. - Treat CR as similar to space or tab in base syntax mode. - Adjust pgetc_eatbnl() to handle backslash-CRLF in the same way as backslash-LF. With these changes scripts containing CRLF line endings are more likely to work. Adds 48-56 bytes. (GitHub issue #285)
* | Fix POSIX buildRon Yorston2023-02-041-1/+1
| | | | | | | | | | A misplaced #endif in ash and the wrong sense of a test in parse_config.c broke the POSIX build.
* | ash: fix CRLF handlingRon Yorston2023-01-311-2/+7
| | | | | | | | | | | | | | | | Only remove CRs that are part of a CRLF pair in the output of command substitution. It would be nice to do the same in preadbuffer() but there's a small chance the CRLF might be split between buffers.
* | win32: provide a default value for HOMERon Yorston2023-01-291-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The busybox-w32 shell initialises HOME when it starts. However, if applets are run outside the environment provided by the shell they may find HOME is unset. This caused a problem for 'vi' as it was unable to locate its .exrc. If HOME isn't available in the environment make getenv(3) provide a sensible default value. The shell must use the *real* getenv(3) when determining if HOME is already set. Also, unrelated to the above, the shell shouldn't treat failure of getpwuid(3) as a fatal error. Costs 72-80 bytes.
* | Merge branch 'busybox' into mergeRon Yorston2023-01-051-3/+7
|\|
| * ash: trivial code shrinkDenys Vlasenko2023-01-031-1/+1
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: fix compile failures in some configsDenys Vlasenko2023-01-031-2/+6
| | | | | | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* | win32: revert special treatment of Unix-style absolute pathsRon Yorston2022-10-261-33/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 605972390 (win32: handle Unix-style absolute paths for executables) added special treatment of paths for executables starting with a slash. Such paths are absolute on Unix but are relative to the current drive on Windows. On reflection this commit did more than necessary. Later commits provided special treatment only for paths starting with locations traditionally used to contain binaries on Unix. This is probably sufficient. Problems introduced by commit 605972390 include: - If the current drive isn't the system drive tab completion of a command starting with a slash confusingly references the system drive. - Building busybox-w32 with w64devkit fails on drives other than the system drive. Revert the changes introduced by commit 605972390. This saves 192 bytes. (GitHub issue #239)
* | Merge branch 'busybox' into mergeRon Yorston2022-10-121-2/+24
|\|
| * 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-021-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-271-4/+3
|\|
| * ash,hush: use HOME for tab completion and promptsRon Yorston2022-06-261-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* | 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)