From f613f9573f044220453069ee81ed8706c6e18225 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Sun, 19 Jan 2020 18:21:59 +0800 Subject: redir: Clear saved redirections in subshell When we enter a subshell we need to drop the saved redirections as otherwise a subsequent unwindredir could produce incorrect results. This patch does this by simply clearing redirlist. While we could actually free the memory underneath for subshells it isn't really worth the trouble for now. In order to ensure that this is done in every place where we enter a subshell, this patch adds a new mkinit hook called forkreset. The calls closescript, clear_traps and reset_handler are also added to the forkreset hook. This fixes a bug where the first two functions weren't called if we enter a subshell without forking. Reported-by: Harald van Dijk Signed-off-by: Herbert Xu --- src/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index b2712cb..36431fc 100644 --- a/src/main.c +++ b/src/main.c @@ -71,7 +71,7 @@ int *dash_errno; short profile_buf[16384]; extern int etext(); #endif -static struct jmploc main_handler; +MKINIT struct jmploc main_handler; STATIC void read_profile(const char *); STATIC char *find_dot_file(char *); @@ -354,7 +354,10 @@ exitcmd(int argc, char **argv) /* NOTREACHED */ } -void reset_handler(void) -{ +#ifdef mkinit +INCLUDE "error.h" + +FORKRESET { handler = &main_handler; } +#endif -- cgit 1.4.1