summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-08-17 17:39:04 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-08-17 17:39:04 +0200
commit84d4ac375408f44d282aa49a21a2451eb41638e2 (patch)
tree7d9ebdff17f7e421ec391d4a4d7a77d0700447f8
parent96466951bf6401e9c6230ed82e449464e961f168 (diff)
hush: with --login, errors /etc/profile in must not exit shell
function old new delta die_if_script 28 34 +6 hush_main 1146 1150 +4 run_list 1031 1028 -3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 10/-3) Total: 7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 0806935b3..6bc86fcd0 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -943,6 +943,7 @@ struct globals {
#endif
/* set by signal handler if SIGINT is received _and_ its trap is not set */
smallint flag_SIGINT;
+ smallint flag_startup_done;
#if ENABLE_HUSH_LOOPS
smallint flag_break_continue;
#endif
@@ -1479,7 +1480,9 @@ static void xxfree(void *ptr)
static void die_if_script(void)
{
- if (!G_interactive_fd) {
+ if (G.flag_startup_done /* when not yet set, allows "hush -l" to not die on errors in /etc/profile */
+ && !G_interactive_fd
+ ) {
if (G.last_exitcode) /* sometines it's 2, not 1 (bash compat) */
xfunc_error_retval = G.last_exitcode;
xfunc_die();
@@ -10970,11 +10973,9 @@ int hush_main(int argc, char **argv)
# endif
G.pre_trap_exitcode = -1;
#endif
-
#if ENABLE_HUSH_FAST
G.count_SIGCHLD++; /* ensure it is != G.handled_SIGCHLD */
#endif
-
G.root_pid = getpid(); /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */
G.root_ppid = getppid(); /* for $PPID (NOMMU can override) */
@@ -11250,6 +11251,10 @@ int hush_main(int argc, char **argv)
}
}
}
+ /* "hush -l" doesn't die in startup scripts, but after -l is processed,
+ * it can die if scripts. Set the flag to achieve this behavior.
+ */
+ G.flag_startup_done = 1;
/* -c takes effect *after* -l */
if (G.opt_c) {