aboutsummaryrefslogtreecommitdiff
path: root/shell (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'busybox' into mergeRon Yorston2023-04-173-10/+59
|\
| * ash,hush: tab completion of functions and aliasesRon Yorston2023-04-162-6/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * hush: quote variable values printed by "set" (match ash behavior)Denys Vlasenko2023-04-132-4/+19
| | | | | | | | | | | | | | function old new delta builtin_set 258 301 +43 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-094-44/+89
|\|
| * 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>
| * hush (NOMMU): fix LINENO in execed childrenDenys Vlasenko2023-04-011-0/+15
| | | | | | | | | | | | | | | | | | | | | | function old new delta hush_main 1815 1851 +36 re_execute_shell 601 635 +34 .rodata 102721 102726 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 75/0) Total: 75 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: speed up "big heredoc" codeDenys Vlasenko2023-04-011-7/+15
| | | | | | | | | | | | | | | | | | | | function old new delta hush_main 1810 1815 +5 .rodata 102723 102721 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 5/-2) Total: 3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: add TODO commentDenys Vlasenko2023-04-011-0/+3
| | | | | | | | 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-313-6/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-092-29/+10
| | | | | | | | | | | | | | | | | | | | | | | | 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: 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.
* | 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: 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: 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-132-17/+37
|\|
| * hush: restore SIGHUP handling, this time explain why we do what we doDenys Vlasenko2023-01-301-20/+28
| | | | | | | | | | | | | | function old new delta check_and_run_traps 229 278 +49 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: restore tty pgrp on SIGHUPDenys Vlasenko2023-01-301-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | Found one case where SIGHUP does need some handling. ash does not restore tty pgrp when killed by SIGHUP, and this means process which started ash needs to restore it, or it would get backgrounded when trying to use tty. function old new delta check_and_run_traps 214 229 +15 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * hush: remove special handling of SIGHUPDenys Vlasenko2023-01-301-18/+20
| | | | | | | | | | | | | | | | | | | | Kernel should do the right thing. (ash and dash do not have special SIGHUP handling.) function old new delta check_and_run_traps 278 214 -64 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256Denys Vlasenko2023-01-262-3/+10
| | | | | | | | | | | | | | | | | | | | 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: 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-102-4/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-052-8/+21
|\|
| * hush: code shrinkDenys Vlasenko2023-01-031-4/+9
| | | | | | | | | | | | | | function old new delta run_list 1032 1012 -20 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| * 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-032-3/+11
| | | | | | | | 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-125-2/+44
|\|