about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Src/builtin.c6
-rw-r--r--Src/exec.c7
-rw-r--r--Src/glob.c2
-rw-r--r--Src/subst.c2
4 files changed, 13 insertions, 4 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 6db40006a..4ccc26314 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3429,12 +3429,16 @@ bin_break(char *name, char **argv, char *ops, int func)
 	}
 	/*FALLTHROUGH*/
     case BIN_EXIT:
-	if (locallevel) {
+	if (locallevel > forklevel) {
 	    /*
 	     * We don't exit directly from functions to allow tidying
 	     * up, in particular EXIT traps.  We still need to perform
 	     * the usual interactive tests to see if we can exit at
 	     * all, however.
+	     *
+	     * The forklevel test means we *do* exit from a subshell
+	     * inside a function when we reach the level of the
+	     * function itself.
 	     */
 	    if (stopmsg || (zexit(0,2), !stopmsg)) {
 		retflag = 1;
diff --git a/Src/exec.c b/Src/exec.c
index c55494b96..7bc341116 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1757,7 +1757,7 @@ execcmd(Estate state, int input, int output, int how, int last1)
 	    if (!(cflags & BINF_NOGLOB))
 		while (!checked && !errflag && args && nonempty(args) &&
 		       has_token((char *) peekfirst(args)))
-		    glob(args, firstnode(args), 0);
+		    zglob(args, firstnode(args), 0);
 	    else if (!unglobbed) {
 		for (node = firstnode(args); node; incnode(node))
 		    untokenize((char *) getdata(node));
@@ -2490,6 +2490,10 @@ fixfds(int *save)
 }
 
 /**/
+int
+forklevel;
+
+/**/
 static void
 entersubsh(int how, int cl, int fake)
 {
@@ -2557,6 +2561,7 @@ entersubsh(int how, int cl, int fake)
     if (cl)
 	clearjobtab();
     times(&shtms);
+    forklevel = locallevel;
 }
 
 /* close internal shell fds */
diff --git a/Src/glob.c b/Src/glob.c
index 1f6bde3ab..91b71dc77 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -920,7 +920,7 @@ gmatchcmp(Gmatch a, Gmatch b)
 
 /**/
 void
-glob(LinkList list, LinkNode np, int nountok)
+zglob(LinkList list, LinkNode np, int nountok)
 {
     struct qual *qo, *qn, *ql;
     LinkNode node = prevnode(np);
diff --git a/Src/subst.c b/Src/subst.c
index 4ed6e5e45..885799534 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -233,7 +233,7 @@ globlist(LinkList list, int nountok)
     badcshglob = 0;
     for (node = firstnode(list); !errflag && node; node = next) {
 	next = nextnode(node);
-	glob(list, node, nountok);
+	zglob(list, node, nountok);
     }
     if (badcshglob == 1)
 	zerr("no match", NULL, 0);