Commit graph

2629 commits

Author SHA1 Message Date
Denys Vlasenko
438b92efdd hush: optimize decoding of $'str' - avoid extra function call if we can
function                                             old     new   delta
parse_stream                                        2565    2572      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 23:20:10 +02:00
Denys Vlasenko
f29ab91763 hush: shrink i_getch, rename two functions
Final link with: <none>
function                                             old     new   delta
i_getch_interactive                                    -     308    +308
i_getch                                              102      85     -17
fgetc_interactive                                    309       -    -309
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 308/-326)          Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 17:30:48 +02:00
Denys Vlasenko
187f24b490 hush: ~5% faster parsing of typical shell scripts
0-9,A-Z,a-z are never special and just go into the current word.

function                                             old     new   delta
parse_stream                                        2476    2565     +89

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 10:01:16 +02:00
Denys Vlasenko
a5cf673c9c hush: create a macro IS_NULL_WORD to test for null shell word
No logic changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 02:30:09 +02:00
Denys Vlasenko
1847fee2d4 hush: fix a corner case in "case" stmt, ctx_dsemicolon is in fact unused
function                                             old     new   delta
parse_stream                                        2446    2476     +30
done_word                                            797     800      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 33/0)               Total: 33 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-13 00:51:44 +02:00
Denys Vlasenko
f161bc628f hush: allow nested negation "! ! ! CMD" - bash 5.2.15 allows it
Also, deindent "ch == EOF" code branch in parse_stream()

function                                             old     new   delta
done_word                                            799     797      -2
parse_stream                                        2453    2446      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-9)               Total: -9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-12 20:29:26 +02:00
Denys Vlasenko
2b0b74e8b4 hush: drop ctx_inverted, use pipe->pi_inverted
function                                             old     new   delta
done_word                                            776     799     +23
parse_stream                                        2456    2453      -3
done_pipe                                            252     242     -10
.rodata                                           105837  105825     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 23/-25)             Total: -2 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-12 20:29:26 +02:00
Denys Vlasenko
5ecbed0e26 hush: do not segfault on "for </dev/null v in..."
This is not accepted by bash, we may also disallow this,
but for now, at least do not crash

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-12 17:56:58 +02:00
Denys Vlasenko
ab1de7df99 hush: test for, and disallow several invalid syntaxes
function                                             old     new   delta
parse_stream                                        2292    2456    +164
done_pipe                                            231     252     +21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 185/0)             Total: 185 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 23:18:01 +02:00
Denys Vlasenko
1cd53c15a2 ash: parser: Invalid redirections are run-time, not syntax errors
Upstream commit

    Date: Wed, 14 Dec 2022 02:06:05 +0100
    parser: Invalid redirections are run-time, not syntax errors

    This fixes a long-standing bug where
      echo 'echo >&a' | sh
    errors out with
      sh: 2: Syntax error: Bad fd number
    despite the error being on line 1

    This patch makes the error
      sh: 1: Bad fd number: a
    as expected

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 18:43:02 +02:00
Denys Vlasenko
0da6c813e1 hush: fix var_backslash1.tests
function                                             old     new   delta
o_addqblock                                            -     131    +131
append_str_maybe_ifs_split                            53     100     +47
expand_one_var                                      1872    1897     +25
encode_then_expand_vararg                            380     399     +19
sig_unblock                                           41      43      +2
sig_block                                             41      40      -1
sigprocmask_allsigs                                   33      31      -2
expand_vars_to_list                                 1080    1077      -3
wait_for_child_or_signal                             202     193      -9
o_addQstr                                            175      42    -133
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/5 up/down: 224/-148)           Total: 76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 17:36:02 +02:00
Denys Vlasenko
d18c9eadf0 shells: testcase: add another test for EINTR on fifo open
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 14:10:17 +02:00
Denys Vlasenko
e660eab458 *: code shrink using sigprocmask2() where appropriate
function                                             old     new   delta
sig_unblock                                           41      43      +2
sig_block                                             41      40      -1
sigprocmask_allsigs                                   33      31      -2
wait_for_child_or_signal                             202     193      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 2/-12)             Total: -10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-11 01:17:02 +02:00
Denys Vlasenko
ea2022efb3 ash: converge waiting code to dash in its form, add comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-10 23:39:44 +02:00
Denys Vlasenko
f6fb3c603a ash: move 100 bytes off global .data / .bss, no logic changes
text	   data	    bss	    dec	    hex	filename
1067871	    559	   5184	1073614	 1061ce	busybox_old
1068067	    555	   5088	1073710	 10622e	busybox_unstripped
            ^^^^^^^^^^^
function                                             old     new   delta
pgetc                                                580     623     +43
parse_command                                       1633    1651     +18
ash_main                                            1226    1239     +13
popstring                                            115     126     +11
redirect                                             951     961     +10
popfile                                              105     115     +10
expandstr                                            252     262     +10
evalbltin                                            306     314      +8
pushstring                                           155     162      +7
pushfile                                              31      38      +7
freestrings                                           90      97      +7
setinputstring                                        68      74      +6
readtoken1                                          3095    3101      +6
pungetc                                                9      15      +6
nlprompt                                              39      45      +6
nlnoprompt                                            33      39      +6
unwindfiles                                           20      25      +5
dotcmd                                               309     314      +5
setinputfile                                         190     194      +4
init                                                 429     432      +3
forkchild                                            617     620      +3
evalcommand                                         1616    1617      +1
ash_vmsg                                             141     142      +1
g_parsefile                                            4       -      -4
commandname                                            4       -      -4
basepf                                                84       -     -84
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 23/0 up/down: 196/-92)          Total: 104 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-10 20:18:10 +02:00
Denys Vlasenko
9b67dde8cd ash: redir: Retry open on EINTR
Upstream commit:

    Date: Thu, 28 May 2020 21:31:45 +1000
    redir: Retry open64 on EINTR

    It is possible for open64 to block on named pipes, and therefore
    it can be interrupted by signals and return EINTR.  We should only
    let it fail with EINTR if real signals are pending (i.e., it should
    not fail on SIGCHLD if SIGCHLD has not been trapped).

    This patch adds a new helper sh_open to retry the open64 call if
    necessary.  It also calls sh_error when appropriate.

    Fixes: 3800d4934391 ("[JOBS] Fix dowait signal race")

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 20:17:31 +02:00
Denys Vlasenko
81274d8b30 ash: eval: Reset handler when entering a subshell
Upstream commit:

    Date: Sun, 3 Mar 2019 21:57:50 +0800
    eval: Reset handler when entering a subshell

    As it is a subshell can execute code that is only meant for the
    parent shell when it executes a longjmp that is caught by something
    like evalcommand.  This patch fixes it by resetting the handler
    when entering a subshell.

function                                             old     new   delta
evalsubshell                                         169     183     +14
evalpipe                                             342     356     +14
argstr                                              1406    1416     +10
ash_main                                            1236    1226     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 65/-10)             Total: 28 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:52:09 +02:00
Denys Vlasenko
4ce8afe6b2 ahs: jobs: Block signals during tcsetpgrp
Upstream commit:

    Date: Wed, 6 Jan 2021 15:45:12 +1100
    jobs: Block signals during tcsetpgrp

    Harald van Dijk <harald@gigawatt.nl> wrote:
    > On 19/12/2020 22:21, Steffen Nurpmeso wrote:
    >> Steffen Nurpmeso wrote in
    >>   <20201219172838.1B-WB%steffen@sdaoden.eu>:
    >>   |Long story short, after falsely accusing BSD make of not working
    >>
    >> After dinner i shortened it a bit more, and attach it again, ok?
    >> It is terrible, but now less redundant than before.
    >> Sorry for being so terse, that problem crosses my head for about
    >> a week, and i was totally mislead and if you bang your head
    >> against the wall so many hours bugs or misbehaviours in a handful
    >> of other programs is not the expected outcome.
    >
    > I think a minimal test case is simply
    >
    > all:
    >         $(SHELL) -c 'trap "echo TTOU" TTOU; set -m; echo all good'
    >
    > unless I accidentally oversimplified.
    >
    > The SIGTTOU is caused by setjobctl's xtcsetpgrp(fd, pgrp) call to make
    > its newly started process group the foreground process group when job
    > control is enabled, where xtcsetpgrp is a wrapper for tcsetpgrp. (That's
    > in dash, the other variants may have some small differences.) tcsetpgrp
    > has this little bit in its specification:
    >
    >        Attempts to use tcsetpgrp() from a process which is a member of
    >        a background process group on a fildes associated with its con‐
    >        trolling  terminal  shall  cause the process group to be sent a
    >        SIGTTOU signal. If the calling thread is blocking SIGTTOU  sig‐
    >        nals  or  the  process is ignoring SIGTTOU signals, the process
    >        shall be allowed to perform the operation,  and  no  signal  is
    >        sent.
    >
    > Ordinarily, when job control is enabled, SIGTTOU is ignored. However,
    > when a trap action is specified for SIGTTOU, the signal is not ignored,
    > and there is no blocking in place either, so the tcsetpgrp() call is not
    > allowed.
    >
    > The lowest impact change to make here, the one that otherwise preserves
    > the existing shell behaviour, is to block signals before calling
    > tcsetpgrp and unblocking them afterwards. This ensures SIGTTOU does not
    > get raised here, but also ensures that if SIGTTOU is sent to the shell
    > for another reason, there is no window where it gets silently ignored.
    >
    > Another way to fix this is by not trying to make the shell start a new
    > process group, or at least not make it the foreground process group.
    > Most other shells appear to not try to do this.

    This patch implements the blocking of SIGTTOU (and everything else)
    while we call tcsetpgrp.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:39:44 +02:00
Denys Vlasenko
df154028dc ash: eval: Add vfork support
Upstream commit:

    Date: Sat, 19 May 2018 02:39:56 +0800
    eval: Add vfork support

    This patch adds basic vfork support for the case of a simple command.

Upstream commit:

    Date: Tue, 12 Jan 2021 17:11:19 +1100
    jobs: Always reset SIGINT/SIGQUIT handlers

    On Fri, Jan 08, 2021 at 08:55:41PM +0000, Harald van Dijk wrote:
    > On 18/05/2018 19:39, Herbert Xu wrote:
    > > This patch adds basic vfork support for the case of a simple command.
    > > ...  @@ -879,17 +892,30 @@ forkchild(struct job *jp, union node *n, int
    > > mode)
    > >   		}
    > >   	}
    > >   	if (!oldlvl && iflag) {
    > > -		setsignal(SIGINT);
    > > -		setsignal(SIGQUIT);
    > > +		if (mode != FORK_BG) {
    > > +			setsignal(SIGINT);
    > > +			setsignal(SIGQUIT);
    > > +		}
    > >   		setsignal(SIGTERM);
    > >   	}
    > > +
    > > +	if (lvforked)
    > > +		return;
    > > +
    > >   	for (jp = curjob; jp; jp = jp->prev_job)
    > >   		freejob(jp);
    > >   }
    >
    > This leaves SIGQUIT ignored in background jobs in interactive shells.
    >
    >   ENV= dash -ic 'dash -c "kill -QUIT \$\$; echo huh" & wait'
    >
    > As of dash 0.5.11, this prints "huh". Before, the subprocess process killed
    > itself before it could print anything. Other shells do not leave SIGQUIT
    > ignored.
    >
    > (In a few other shells, this also prints "huh", but in those other shells,
    > that is because the inner shell chooses to ignore SIGQUIT, not because the
    > outer shell leaves it ignored.)

    Thanks for catching this.  I have no idea how that got in there
    and it makes no sense whatsoever.  This patch removes the if
    conditional.

    Fixes: e94a964e7dd0 ("eval: Add vfork support")

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:36:18 +02:00
Denys Vlasenko
9f490785e0 ash: rename got_sigchld, doing_jobctl, and INT_ON/OFF to match dash
Comparing code with dash is more difficult with these differences.
(We didn't know back then that dash will be revived...)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:17:48 +02:00
Denys Vlasenko
53b3854e81 ash: fix fallout of no-more-set commandname
Testsuite reports lots of message mismatches, fix that

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 17:04:16 +02:00
Denys Vlasenko
c92755133b shells: fix a typo in var_backslash1.tests, expand it while at it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 13:00:55 +02:00
Denys Vlasenko
4eb4141b22 ash: eval: Always set exitstatus in evaltree
Upstream commit:

    Date: Tue, 6 Dec 2022 16:49:14 +0800
    eval: Always set exitstatus in evaltree

    There is no harm in setting exitstatus unconditionally in evaltree.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 12:23:21 +02:00
Denys Vlasenko
6d44762589 ash: options: Do not set commandname in procargs
Upstream commit:

    Date:   Mon Feb 25 12:49:20 2019 +0800
    options: Do not set commandname in procargs

    We set commandname in procargs when we don't have to.  This results
    in a duplicated output of arg0 when an error occurs.

function                                             old     new   delta
ash_main                                            1256    1236     -20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 02:26:51 +02:00
Denys Vlasenko
98b1a000c9 ash: jobs: drop unused node parameter in makejob()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 02:02:04 +02:00
Denys Vlasenko
fa82ef1a2e shells: add testsuite item
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-09 01:48:12 +02:00
Denys Vlasenko
5b3405594a ash: reuse vstype_suffix[] in debug code, shrink it
function                                             old     new   delta
vstype_suffix                                          -      39     +39
static.vstype                                         42       -     -42
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/0 up/down: 39/-42)             Total: -3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-08 12:40:44 +02:00
Denys Vlasenko
422f4ede6f ash: fix cmdputs - was showing some variable forms incorrectly
function                                             old     new   delta
cmdputs                                              402     418     +16
static.vstype                                         48      42      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-6)              Total: 10 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 23:42:45 +02:00
Denys Vlasenko
34948f1858 hush: smarter optimization for not-globbing [ and [[
function                                             old     new   delta
o_save_ptr                                           176     167      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 02:46:04 +02:00
Denys Vlasenko
abab146b82 ash: fix heredoc.tests broken by last commit
function                                             old     new   delta
readtoken1                                          3053    3095     +42
xxreadtoken                                          215     212      -3
expandstr                                            255     252      -3
parseheredoc                                         148     127     -21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 42/-27)             Total: 15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 02:26:25 +02:00
Denys Vlasenko
7648dc721e ash,hush: fix corner cases with backslash-newlines in heredocs
function                                             old     new   delta
fetch_heredocs                                       477     485      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 01:30:57 +02:00
Denys Vlasenko
558ef4962d hush: optimization: do not glob words "[" and "[["
function                                             old     new   delta
glob_needed                                           71      86     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-07 00:20:56 +02:00
Denys Vlasenko
d7d8ffed87 shell: typo and whitespace fixes, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 23:29:35 +02:00
Denys Vlasenko
02b518db1c hush: fix memory leak caused by compiler optimizing out a store
function                                             old     new   delta
generate_stream_from_string                          222     232     +10
setup_heredoc                                        329     330      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 11/0)               Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 20:42:52 +02:00
Denys Vlasenko
58a54fbd5a hush: disentangle interactiveness/job_control setup code
...and discover that we can do away with 1-3 initialization syscalls.

function                                             old     new   delta
hush_main                                           1152    1146      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 17:37:32 +02:00
Denys Vlasenko
778fce3e70 hush: fix build failure if !CONFIG_HUSH_JOB
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 16:22:21 +02:00
Denys Vlasenko
dba57344b5 hush: make NORETURN declarations lees verbose, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 16:14:19 +02:00
Denys Vlasenko
4539262b6a hush: do not save history on xfunc error, it's unsafe
Also, make second calls to install_special_sighandlers() less haphazard.
It's not a fix for anything, but looking more organized now.

function                                             old     new   delta
fflush_restore_ttypgrp_and__exit                       -      20     +20
restore_ttypgrp_and__exit                             21       -     -21
hush_main                                           1181    1152     -29
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/1 up/down: 20/-50)            Total: -30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 16:12:00 +02:00
Denys Vlasenko
c2ef7c6dad hush: if !JOBS, skip tests which wouldn't work
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 09:32:36 +02:00
Denys Vlasenko
cdbb6957f1 hush: don't save history in subshells; on NOMMU, don't be interactive on reexec
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 01:26:25 +02:00
Denys Vlasenko
e591316e02 hush: rename hush_exit to save_history_run_exit_trap_and_exit, sigexit to restore_ttypgrp_and_killsig_or__exit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-08-03 00:44:32 +02:00
Denys Vlasenko
e9c21c5c3a hush: fix SEGV on "echo << >" and such
function                                             old     new   delta
.rodata                                           105787  105823     +36
fetch_heredocs                                       461     477     +16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0)               Total: 52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-08 10:36:12 +02:00
Denys Vlasenko
8d3d078917 shell: empty HISTFILE disables history saving, just as unset one did
The rationale here is that unsetting HISTFILE in /etc/profile
does not "stick": if it's unset, the default one is set later
(after /etc/profile is executed) by the shell.
But setting (and exporting, so it is inherited by all
(grand)child shells) an empty one works.

function                                             old     new   delta
save_history                                         296     316     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-04 12:51:38 +02:00
Denys Vlasenko
9c46a06885 shell: update HISTFILESIZE code to be actually useful
"HISTFILESIZE=0" in profile wasn't working as intended,
"unset HISTFILE" wasn't preventing creation of history files
Now:
HISTSIZE=n      allows to reduce in-memory history buffer
HISTFILESIZE=n  allows to reduce history file size (0: truncate it)
unset HISTFILE  allows to not save history file at all

function                                             old     new   delta
exitshell                                            138     194     +56
hush_exit                                             97     143     +46
save_history                                         266     296     +30
hush_main                                           1170    1186     +16
.rodata                                           105762  105771      +9
load_history                                         246     254      +8
size_from_HISTFILESIZE                                44      41      -3
read_line_input                                     2746    2712     -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/2 up/down: 165/-37)           Total: 128 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-03 19:10:42 +02:00
Denys Vlasenko
36ac283682 shell: fix race between signal handlers setting bb_got_signal and poll()
function                                             old     new   delta
__ppoll_time64                                         -     211    +211
check_got_signal_and_poll                              -     164    +164
read_key                                             607     601      -6
shell_builtin_read                                  1328    1318     -10
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 0/2 up/down: 375/-16)           Total: 359 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-02 22:42:47 +02:00
Denys Vlasenko
bbaa56f737 use pollfd[1] array for poll() argument
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-02 21:55:42 +02:00
Ron Yorston
dcd8df258a shell: improve bash compatibility of read built-in
Make the read built-in more compatible with bash:

- Return an exit code of 142 on timeout.

- When the timeout expires before a newline is detected in the
  input bash captures the partial input.  This behaviour is new
  since bash version 4.4.  BusyBox shells had the pre-4.4 behaviour
  where the input was lost.

Update the tests to suit and fix a couple of compiler errors in
the testsuite.

function                                             old     new   delta
builtin_read                                         154     174     +20
readcmd                                              213     228     +15
shell_builtin_read                                  1364    1370      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 41/0)               Total: 41 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2025-07-01 20:21:37 +02:00
Hajime Tazaki
23db689683 hush: fix G.argv0_for_re_execing to avoid endless loop
When the busybox is used as /sbin/init and the inittab file contains
below:

::respawn:-/bin/sh

/sbin/init spawns hush for the first time with the argv[0] contains '-',
and hush treats it as login shell.  Then it reads /etc/profile and if
the file contains the command execution like below, it invokes hush as
login shell because the argv[0] argument is still '-/bin/sh' and reads
/etc/profile again.  This will last until some failure (e.g., memory
failure) happens.

  [ "$(id -u)" -eq 0 ] && PS1="${PS1}# " || PS1="${PS1}\$ "

This commit fixes this issues by adding an offset (+1) to the
G.argv0_for_re_execing variable.

This issue happens on our out-of-tree UML (use mode linux) with nommu
configuration.

Link: https://lore.kernel.org/all/cover.1731290567.git.thehajime@gmail.com/
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-12-09 01:58:45 +01:00
Denys Vlasenko
49d9e06fba libbb: modify find_executable() to not temporarily write to PATH
This allows to simplify "which" applet code

function                                             old     new   delta
find_executable                                       93     111     +18
which_main                                           191     177     -14
builtin_source                                       316     294     -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 18/-36)            Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-08 04:03:17 +02:00
Denys Vlasenko
8c4bccb83e hush: fix "type ./cat" and "command -v ./cat" to not scan PATH
function                                             old     new   delta
find_executable_in_PATH                                -      67     +67
if_command_vV_print_and_exit                         114     116      +2
.rodata                                           105712  105710      -2
builtin_type                                         137     128      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 69/-11)             Total: 58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2024-10-07 22:00:16 +02:00