diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2009-12-25 20:21:35 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2009-12-25 20:21:35 +0000 |
commit | 29d401c22d22df7a3c5247ef9a1d49ba1889053d (patch) | |
tree | 70cc7efa48eb3f1089f61e3030e19359262db521 /bin/sh | |
parent | b1625b09d98ad8e337fdfeb4d3680a3c90750f18 (diff) | |
download | src-29d401c22d22df7a3c5247ef9a1d49ba1889053d.tar.gz src-29d401c22d22df7a3c5247ef9a1d49ba1889053d.zip |
sh: Do not run callers' exception handlers in subshells.
Reset the exception handler in the child to main's.
This avoids inappropriate double cleanups or shell duplication when the
exception is caught, such as 'fc' and future 'command eval' and 'command .'.
Notes
Notes:
svn path=/head/; revision=200998
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/jobs.c | 1 | ||||
-rw-r--r-- | bin/sh/main.c | 6 | ||||
-rw-r--r-- | bin/sh/main.h | 1 |
3 files changed, 5 insertions, 3 deletions
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index 1ebf72285225..95ec6e2922ea 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -757,6 +757,7 @@ forkshell(struct job *jp, union node *n, int mode) TRACE(("Child shell %d\n", (int)getpid())); wasroot = rootshell; rootshell = 0; + handler = &main_handler; closescript(); INTON; clear_traps(); diff --git a/bin/sh/main.c b/bin/sh/main.c index 547aad9624cb..c21e8df06617 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -75,6 +75,7 @@ __FBSDID("$FreeBSD$"); int rootpid; int rootshell; +struct jmploc main_handler; STATIC void read_profile(char *); STATIC char *find_dot_file(char *); @@ -90,14 +91,13 @@ STATIC char *find_dot_file(char *); int main(int argc, char *argv[]) { - struct jmploc jmploc; struct stackmark smark; volatile int state; char *shinit; (void) setlocale(LC_ALL, ""); state = 0; - if (setjmp(jmploc.loc)) { + if (setjmp(main_handler.loc)) { /* * When a shell procedure is executed, we raise the * exception EXSHELLPROC to clean up before executing @@ -143,7 +143,7 @@ main(int argc, char *argv[]) else goto state4; } - handler = &jmploc; + handler = &main_handler; #ifdef DEBUG opentrace(); trputs("Shell args: "); trargs(argv); diff --git a/bin/sh/main.h b/bin/sh/main.h index b6dadc3e7d83..c5e8bfd38405 100644 --- a/bin/sh/main.h +++ b/bin/sh/main.h @@ -35,6 +35,7 @@ extern int rootpid; /* pid of main shell */ extern int rootshell; /* true if we aren't a child of the main shell */ +extern struct jmploc main_handler; /* top level exception handler */ void readcmdfile(const char *); void cmdloop(int); |