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/jobs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/jobs.c') diff --git a/src/jobs.c b/src/jobs.c index 26a6248..f377d8c 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -55,6 +55,7 @@ #endif #include "exec.h" #include "eval.h" +#include "init.h" #include "redir.h" #include "show.h" #include "main.h" @@ -857,8 +858,7 @@ static void forkchild(struct job *jp, union node *n, int mode) if (!lvforked) { shlvl++; - closescript(); - clear_traps(); + forkreset(); #if JOBS /* do job control only in root shell */ -- cgit 1.4.1