Commit Graph

981 Commits (master)

Author SHA1 Message Date
Ron Yorston 371fe9f71d ash: move hashvar() calls into findvar()
dash has accepted a patch to remove the first argument of findvar().
It's commit e85e972 (var: move hashvar() calls into findvar()).

Apply the same change to BusyBox ash.

function                                             old     new   delta
findvar                                               35      40      +5
mklocal                                              268     261      -7
exportcmd                                            164     157      -7
setvareq                                             319     310      -9
lookupvar                                            150     141      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/4 up/down: 5/-32)             Total: -27 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-14 01:12:54 +02:00
Denys Vlasenko 08fb86726b ash: remove limitation on fd# length
"echo text >&0000000000002" works as you would expect,
"echo text >&9999999999" properly fails instead of creating a file
named "9999999999".

function                                             old     new   delta
expredir                                             219     232     +13
readtoken1                                          3045    3053      +8
parsefname                                           204     201      -3
isdigit_str9                                          45       -     -45
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 21/-48)            Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12 22:28:25 +02:00
Denys Vlasenko 0829fce079 ash: do not abort interactive mode on >&9999 redirect
With very large fd#, the error code path is different
from one for closed but small fd#.

Make it not abort if we are interactive:

$ echo text >&99    # this wasn't buggy
ash: dup2(9,1): Bad file descriptor
$ echo text >&9999  # this was
ash: fcntl(1,F_DUPFD,10000): Invalid argument

function                                             old     new   delta
.rodata                                           105637  105661     +24
dup2_or_raise                                         35      38      +3
redirect                                            1084    1044     -40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 27/-40)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-12 22:10:50 +02:00
Ron Yorston 0af28b84e5 ash: remove defunct control character to save a few bytes
Commit 549deab5a (ash: move parse-time quote flag detection to
run-time) did away with the need to distinguish between backquotes
inside and outside quotes.  This left a gap among the control
characters used in argument strings.  Removing this gap saves a
few bytes.

function                                             old     new   delta
.rodata                                           167346  167338      -8
cmdputs                                              399     388     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19)             Total: -19 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 07:35:26 +02:00
Ron Yorston ba0f94458b ash: fix parsing of alias expansion + bash features
An alias expansion immediately followed by '<' and a newline is
parsed incorrectly:

   ~ $ alias x='echo yo'
   ~ $ x<
   yo
   ~ $
   sh: syntax error: unexpected newline

The echo is executed and an error is printed on the next command
submission.  In dash the echo isn't executed and the error is
reported immediately:

   $ alias x='echo yo'
   $ x<
   dash: 3: Syntax error: newline unexpected
   $

The difference between BusyBox and dash is that BusyBox supports
bash-style process substitution and output redirection.  These
require checking for '<(', '>(' and '&>' in readtoken1().

In the case above, when the end of the alias is found, the '<' and
the following newline are both read to check for '<('.  Since
there's no match both characters are pushed back.

The next input is obtained by reading the expansion of the alias.
Once this string is exhausted the next call to __pgetc() calls
preadbuffer() which pops the string, reverts to the previous input
and recursively calls __pgetc().  This request is satisified from
the pungetc buffer.  But the first __pgetc() doesn't know this:
it sees the character has come from preadbuffer() so it (incorrectly)
updates the pungetc buffer.

Resolve the issue by moving the code to pop the string and fetch
the next character up from preadbuffer() into __pgetc().

function                                             old     new   delta
pgetc                                                 28     589    +561
__pgetc                                              607       -    -607
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 561/-607)          Total: -46 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-07-10 07:11:23 +02:00
Denys Vlasenko c5a1be25ba ash: fix handling of single-quoted strings in pattern substitution
function                                             old     new   delta
subevalvar                                          1576    1588     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-02-26 16:27:53 +01:00
zhuyan ed4a24dfd1 ash: initialize basepf.buf in ash
When I planned to print the command in read_line_input, I found that after
the system started, the command printed for the first time was always
garbled.

After analysis, it is found that in the init() function of ash, the
variable basepf.buf is not initialized after applying for memory, resulting
in garbled initial data. Then assign it to the global variable
g_parsefile->buf in ash.c, and then pass g_parsefile->buf to the parameter
command of the function read_line_input in the function preadfd(), and
finally cause it to be garbled when the command is printed by
read_line_input.

The call stack is as follows:
 #0  read_line_input (st=0xb6fff220, prompt=0xb6ffc910 "\\[\\033[32m\\]\\h \\w\\[\\033[m\\] \\$ ", command=command@entry=0xb6ffc230 "P\325\377\266P\325\377\266", maxsize=maxsize@entry=1024) at libbb/lineedit.c:2461
 #1  0x0043ef8c in preadfd () at shell/ash.c:10812
 #2  preadbuffer () at shell/ash.c:10914
 #3  pgetc () at shell/ash.c:10997
 #4  0x00440c20 in pgetc_eatbnl () at shell/ash.c:11039
 #5  0x00440cbc in xxreadtoken () at shell/ash.c:13157
 #6  0x00440f40 in readtoken () at shell/ash.c:13268
 #7  0x00441234 in list (nlflag=nlflag@entry=1) at shell/ash.c:11782
 #8  0x004420e8 in parsecmd (interact=<optimized out>) at shell/ash.c:13344
 #9  0x00442c34 in cmdloop (top=top@entry=1) at shell/ash.c:13549
 #10 0x00444e4c in ash_main (argc=<optimized out>, argv=0x444e4c <ash_main+1328>) at shell/ash.c:14747
 #11 0x00407954 in run_applet_no_and_exit (applet_no=9, name=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1024
 #12 0x00407b68 in run_applet_and_exit (name=0xbefffe56 "ash", argv=0x9) at libbb/appletlib.c:1047
 #13 0x00407f88 in main (argc=<optimized out>, argv=0xbefffd34) at libbb/appletlib.c:1181

Fixes: 82dd14a510 ("ash: use CONFIG_FEATURE_EDITING_MAX_LEN")

Signed-off-by: zhuyan <zhuyan34@huawei.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-08-31 02:20:19 +02:00
Denys Vlasenko 5353df91cb Update applet size estimates
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 17:25:21 +02:00
Denys Vlasenko a9047e0980 ash: tweak comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 12:02:34 +02:00
Denys Vlasenko ae351311da ash: remove "volatile" specifier from suppress_int
function                                             old     new   delta
aliascmd                                             274     278      +4
signal_handler                                        81      80      -1
static.redirectsafe                                  144     141      -3
unwindlocalvars                                      219     215      -4
trapcmd                                              333     329      -4
setvar                                               164     160      -4
setpwd                                               167     163      -4
setinputfile                                         216     212      -4
setcmd                                                76      72      -4
readcmd                                              221     217      -4
raise_exception                                       26      22      -4
out2str                                               37      33      -4
out1str                                               32      28      -4
freejob                                               89      85      -4
forkchild                                            616     612      -4
fg_bgcmd                                             298     294      -4
expandarg                                            949     945      -4
evaltree                                             753     749      -4
evalsubshell                                         173     169      -4
evalpipe                                             346     342      -4
evalfun                                              408     404      -4
cdcmd                                                699     695      -4
ash_main                                            1240    1236      -4
__pgetc                                              589     585      -4
unaliascmd                                           152     147      -5
unalias                                               51      46      -5
umaskcmd                                             253     248      -5
stalloc                                               97      92      -5
shiftcmd                                             144     139      -5
setinputstring                                        73      68      -5
redirect                                            1068    1063      -5
recordregion                                          81      76      -5
pushstring                                           160     155      -5
popstring                                            120     115      -5
popstackmark                                          69      64      -5
popredir                                             123     118      -5
popfile                                              110     105      -5
out1fmt                                               45      40      -5
newline_and_flush                                     39      34      -5
ifsfree                                               66      61      -5
growstackblock                                       146     141      -5
freestrings                                           95      90      -5
fmtstr                                                59      54      -5
flush_stdout_stderr                                   23      18      -5
dowait                                               577     572      -5
delete_cmd_entry                                      52      47      -5
clearcmdentry                                         98      93      -5
ash_arith                                             79      74      -5
argstr                                              1404    1399      -5
evalcommand                                         1523    1515      -8
removerecordregions                                  219     209     -10
mklocal                                              284     274     -10
find_command                                         893     883     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/52 up/down: 4/-251)          Total: -247 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 11:13:51 +02:00
Denys Vlasenko 5e0411a7fb ash: disable sleep as builtin, closes 15619
Has a few annoying problems:
* sleepcmd() -> sleep_main(), the parsing of bad arguments exits the shell.
* sleep_for_duration() in sleep_main() has to be interruptible for
  ^C traps to work, which may be a problem for other users
  of sleep_for_duration().
* BUT, if sleep_for_duration() is interruptible, then SIGCHLD interrupts it
  as well (try "/bin/sleep 1 & sleep 10").
* sleep_main() must not allocate anything as ^C in ash longjmp's.
  (currently, allocations are only on error paths, in message printing).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-10 10:53:23 +02:00
Denys Vlasenko 07a95cfcab ash: disable check for "good" function name, bash does not check this
function                                             old     new   delta
.rodata                                           105304  105261     -43
parse_command                                       1696    1633     -63
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-106)           Total: -106 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-07-04 14:38:25 +02:00
Denys Vlasenko 96769486e2 shell: move varcmp() to shell_common.h and use it in hush
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>
2023-06-17 21:13:13 +02:00
Denys Vlasenko d0441222db ash: code shrink
function                                             old     new   delta
setvar                                               166     164      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-06-17 20:45:02 +02:00
Karsten Sperling 3e83699ce2 ash: use-after-free in bash pattern substitution
Commit daa66ed6 fixed a number of use-after-free bugs in bash pattern
substitution, however one "unguarded" STPUTC remained, which is fixed here.

function                                             old     new   delta
subevalvar                                          1564    1576     +12

Signed-off-by: Karsten Sperling <ksperling@apple.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-05-18 16:49:54 +02:00
Ron Yorston acae889dd9 ash,hush: tab completion of functions and aliases
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>
2023-04-16 17:15:05 +02:00
Denys Vlasenko 46e92e1e56 ash: code shrink: do not take address of prefix(), allowing it to inline
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>
2023-04-03 17:30:03 +02:00
Denys Vlasenko a33d19eba8 ash: code shrink - reuse is_prefixed_with() from libbb
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>
2023-04-03 15:19:13 +02:00
Denys Vlasenko 94780e3e8e ash: get rid of separate mail_var_path_changed flag variable
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>
2023-04-03 15:01:00 +02:00
Denys Vlasenko 7ababc3e3c ash: fix still-broken new mail detection
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>
2023-04-03 14:41:01 +02:00
Denys Vlasenko 2860b2530e ash: fix broken new mail detection
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>
2023-04-03 14:01:36 +02:00
Denys Vlasenko 00fc136843 ash: code shrink
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>
2023-04-01 11:11:20 +02:00
Denys Vlasenko 262a845477 ash: exec: Stricter pathopt parsing - lost chunk
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-03-31 21:35:50 +02:00
Ron Yorston 098cd7ece4 ash: improve trap and jobs builtins in child shells
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>
2023-03-31 14:22:56 +02:00
Ron Yorston 470fa7b364 ash: make EPOCH variables work if RANDOM is disabled
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>
2023-03-29 16:45:13 +02:00
Denys Vlasenko 93e0898c66 shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256
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>
2023-01-26 12:56:33 +01:00
Denys Vlasenko d488a5218b ash: trivial code shrink
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 13:39:14 +01:00
Denys Vlasenko 27be0e8cfe shell: fix compile failures in some configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2023-01-03 08:28:16 +01:00
Shawn Landden 58598eb709 ash: optional sleep builtin
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>
2022-08-27 19:56:21 +02:00
Sören Tempel 7c2a3bdde0 ash: fix use-after-free in bash pattern substitution
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>
2022-08-02 18:27:41 +02:00
Denys Vlasenko daa66ed62c ash: fix use-after-free in pattern substituon code
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>
2022-08-02 12:41:18 +02:00
Denys Vlasenko 1c54552842 ash: fix ifs cleanup on error paths
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>
2022-08-02 11:18:11 +02:00
Ron Yorston 7d1c7d8337 ash,hush: use HOME for tab completion and prompts
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>
2022-06-26 18:05:50 +02:00
Denys Vlasenko 5fe20cf321 ash: do not truncate failed tilde expansion on unknown user names
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>
2022-03-01 10:10:22 +01:00
Denys Vlasenko 7750b5a25a ash: fix unsafe use of mempcpy
function                                             old     new   delta
subevalvar                                          1549    1557      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-03-01 09:56:54 +01:00
Sören Tempel fa52ac9781 ash: don't read past end of var in subvareval for bash substitutions
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>
2022-03-01 08:47:43 +01:00
Denys Vlasenko ca466f385a *: slap on a few ALIGN* where appropriate
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>
2022-02-06 19:53:10 +01:00
Denys Vlasenko 12566e7f9b ash,hush: fix handling of SIGINT while waiting for interactive input
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>
2022-01-17 11:46:23 +01:00
Denys Vlasenko a277506a64 shell: add comments about SIGINT-related problems
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-16 23:54:46 +01:00
Denys Vlasenko 931c55f9e2 libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> SETUP_ENV_CHDIR
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>
2022-01-13 12:50:48 +01:00
Denys Vlasenko 68b402ee51 ash: ^C with SIG_INGed SIGINT should not exit the shell
function                                             old     new   delta
__pgetc                                              501     522     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-13 01:15:10 +01:00
Denys Vlasenko 004cefa918 reset: better --help text
function                                             old     new   delta
packed_usage                                       34175   34233     +58

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2022-01-12 17:21:14 +01:00
Denys Vlasenko db5546ca10 libbb: code shrink: introduce and use [_]exit_SUCCESS()
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>
2022-01-05 22:16:06 +01:00
Denys Vlasenko aaf3d5ba74 shell: tweak --help
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>
2021-10-13 11:25:42 +02:00
Denys Vlasenko 62f1eed1e1 hush: in a comment, document what -i might be doing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-13 00:09:07 +02:00
YU Jincheng 5156b24553 Make const ptr assign as function call in clang
- 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>
2021-10-09 22:30:45 +02:00
Denys Vlasenko 5aaeb550b7 ash: speed up ${x//\*/|} too, make it independent of ASH_OPTIMIZE_FOR_SIZE
function                                             old     new   delta
subevalvar                                          1503    1545     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-10-09 03:33:22 +02:00
Alin Mr 21e8dbfd9d ash.c: speedup ${s:} substring (no quotes)
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>
2021-10-09 02:15:52 +02:00
YU Jincheng 1f925038ab *: generalize "const trick"
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>
2021-10-07 15:22:35 +02:00
Denys Vlasenko 5b026d1ecf ash: fix compile breakage in !ENABLE_ASH_ALIAS config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-09-28 17:41:56 +02:00