summary refs log tree commit diff
diff options
context:
space:
mode:
authorherbert <herbert@gondor.apana.org.au>2005-02-25 20:49:13 +1100
committerHerbert Xu <herbert@gondor.apana.org.au>2005-09-26 18:33:03 +1000
commite994ac70a4d85cd933e674e0df70301dd86637ee (patch)
tree0b61fe1663a448911aac3b3a775f0e433c73d024
parentRelease 0.5.2. (diff)
downloaddash-e994ac70a4d85cd933e674e0df70301dd86637ee.tar.gz
dash-e994ac70a4d85cd933e674e0df70301dd86637ee.zip
Changed boolean rootshell into shlvl counter.
-rw-r--r--ChangeLog4
-rw-r--r--src/jobs.c10
-rw-r--r--src/main.c3
-rw-r--r--src/main.h6
4 files changed, 14 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 8070b33..1734ecf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-02-25  Herbert Xu <herbert@gondor.apana.org.au>
+
+	* Changed boolean rootshell into shlvl counter.
+
 2005-01-31  Gerrit Pape <pape@smarden.org>
 
 	* Release 0.5.2.
diff --git a/src/jobs.c b/src/jobs.c
index 132c47a..b82bf50 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -838,19 +838,19 @@ growjobtab(void)
 STATIC inline void
 forkchild(struct job *jp, union node *n, int mode)
 {
-	int wasroot;
+	int oldlvl;
 	pid_t pgrp;
 
 	TRACE(("Child shell %d\n", getpid()));
-	wasroot = rootshell;
-	rootshell = 0;
+	oldlvl = shlvl;
+	shlvl++;
 
 	closescript();
 	clear_traps();
 #if JOBS
 	/* do job control only in root shell */
 	jobctl = 0;
-	if (mode != FORK_NOJOB && jp->jobctl && wasroot) {
+	if (mode != FORK_NOJOB && jp->jobctl && !oldlvl) {
 		if (jp->nprocs == 0)
 			pgrp = getpid();
 		else
@@ -872,7 +872,7 @@ forkchild(struct job *jp, union node *n, int mode)
 				error("Can't open %s", _PATH_DEVNULL);
 		}
 	}
-	if (wasroot && iflag) {
+	if (!oldlvl && iflag) {
 		setsignal(SIGINT);
 		setsignal(SIGQUIT);
 		setsignal(SIGTERM);
diff --git a/src/main.c b/src/main.c
index cbba6c4..0d69e4f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -85,7 +85,7 @@ __RCSID("$NetBSD: main.c,v 1.46 2002/12/11 19:12:18 christos Exp $");
 #define PROFILE 0
 
 int rootpid;
-int rootshell;
+int shlvl;
 #ifdef __GLIBC__
 int *dash_errno;
 #endif
@@ -174,7 +174,6 @@ main(int argc, char **argv)
 	trputs("Shell args:  ");  trargs(argv);
 #endif
 	rootpid = getpid();
-	rootshell = 1;
 	init();
 	setstackmark(&smark);
 	procargs(argc, argv);
diff --git a/src/main.h b/src/main.h
index c305ab7..6b8e71c 100644
--- a/src/main.h
+++ b/src/main.h
@@ -42,8 +42,10 @@
 
 /* pid of main shell */
 extern int rootpid;
-/* true if we aren't a child of the main shell */
-extern int rootshell;
+/* shell level: 0 for the main shell, 1 for its children, and so on */
+extern int shlvl;
+#define rootshell (!shlvl)
+
 #ifdef __GLIBC__
 /* glibc sucks */
 extern int *dash_errno;