svn commit: trunk/busybox/shell

vda at busybox.net vda at busybox.net
Fri Feb 23 21:09:36 UTC 2007


Author: vda
Date: 2007-02-23 13:09:35 -0800 (Fri, 23 Feb 2007)
New Revision: 17964

Log:
ash: cleanup part 2.2


Modified:
   trunk/busybox/shell/ash.c


Changeset:
Modified: trunk/busybox/shell/ash.c
===================================================================
--- trunk/busybox/shell/ash.c	2007-02-23 21:08:58 UTC (rev 17963)
+++ trunk/busybox/shell/ash.c	2007-02-23 21:09:35 UTC (rev 17964)
@@ -2983,6 +2983,7 @@
 static int setcmd(int, char **);
 static int nextopt(const char *);
 
+
 /*      redir.h      */
 
 /* flags passed to redirect */
@@ -2995,13 +2996,6 @@
 static int copyfd(int, int);
 static int redirectsafe(union node *, int);
 
-/*      trap.h       */
-
-static void clear_traps(void);
-static void setsignal(int);
-static int dotrap(void);
-
-
 static int is_safe_applet(char *name)
 {
 	/* It isn't a bug to have non-existent applet here... */
@@ -3038,6 +3032,7 @@
 
 
 /* ============ Alias handling */
+
 #if ENABLE_ASH_ALIAS
 
 #define ALIASINUSE 1
@@ -3232,6 +3227,7 @@
 
 	return i;
 }
+
 #endif /* ASH_ALIAS */
 
 
@@ -5653,6 +5649,43 @@
 static int skipcount;           /* number of levels to skip */
 static int funcnest;            /* depth of function calls */
 
+/* forward decl way out to parsing code - dotrap needs it */
+static int evalstring(char *s, int mask);
+
+/*
+ * Called to execute a trap.  Perhaps we should avoid entering new trap
+ * handlers while we are executing a trap handler.
+ */
+static int
+dotrap(void)
+{
+	char *p;
+	char *q;
+	int i;
+	int savestatus;
+	int skip = 0;
+
+	savestatus = exitstatus;
+	pendingsigs = 0;
+	xbarrier();
+
+	for (i = 0, q = gotsig; i < NSIG - 1; i++, q++) {
+		if (!*q)
+			continue;
+		*q = '\0';
+
+		p = trap[i + 1];
+		if (!p)
+			continue;
+		skip = evalstring(p, SKIPEVAL);
+		exitstatus = savestatus;
+		if (skip)
+			break;
+	}
+
+	return skip;
+}
+
 /* forward declarations - evaluation is fairly recursive business... */
 static void evalloop(union node *, int);
 static void evalfor(union node *, int);
@@ -7319,6 +7352,93 @@
 
 /* ============ jobs.c */
 
+/*
+ * Set the signal handler for the specified signal.  The routine figures
+ * out what it should be set to.
+ */
+static void
+setsignal(int signo)
+{
+	int action;
+	char *t, tsig;
+	struct sigaction act;
+
+	t = trap[signo];
+	if (t == NULL)
+		action = S_DFL;
+	else if (*t != '\0')
+		action = S_CATCH;
+	else
+		action = S_IGN;
+	if (rootshell && action == S_DFL) {
+		switch (signo) {
+		case SIGINT:
+			if (iflag || minusc || sflag == 0)
+				action = S_CATCH;
+			break;
+		case SIGQUIT:
+#if DEBUG
+			if (debug)
+				break;
+#endif
+			/* FALLTHROUGH */
+		case SIGTERM:
+			if (iflag)
+				action = S_IGN;
+			break;
+#if JOBS
+		case SIGTSTP:
+		case SIGTTOU:
+			if (mflag)
+				action = S_IGN;
+			break;
+#endif
+		}
+	}
+
+	t = &sigmode[signo - 1];
+	tsig = *t;
+	if (tsig == 0) {
+		/*
+		 * current setting unknown
+		 */
+		if (sigaction(signo, 0, &act) == -1) {
+			/*
+			 * Pretend it worked; maybe we should give a warning
+			 * here, but other shells don't. We don't alter
+			 * sigmode, so that we retry every time.
+			 */
+			return;
+		}
+		if (act.sa_handler == SIG_IGN) {
+			if (mflag
+			 && (signo == SIGTSTP || signo == SIGTTIN || signo == SIGTTOU)
+			) {
+				tsig = S_IGN;   /* don't hard ignore these */
+			} else
+				tsig = S_HARD_IGN;
+		} else {
+			tsig = S_RESET; /* force to be set */
+		}
+	}
+	if (tsig == S_HARD_IGN || tsig == action)
+		return;
+	switch (action) {
+	case S_CATCH:
+		act.sa_handler = onsig;
+		break;
+	case S_IGN:
+		act.sa_handler = SIG_IGN;
+		break;
+	default:
+		act.sa_handler = SIG_DFL;
+	}
+	*t = action;
+	act.sa_flags = 0;
+	sigfillset(&act.sa_mask);
+	sigaction(signo, &act, 0);
+}
+
 /* mode flags for set_curjob */
 #define CUR_DELETE 2
 #define CUR_RUNNING 1
@@ -8497,7 +8617,26 @@
  *
  * Called with interrupts off.
  */
+/*
+ * Clear traps on a fork.
+ */
 static void
+clear_traps(void)
+{
+	char **tp;
+
+	for (tp = trap; tp < &trap[NSIG]; tp++) {
+		if (*tp && **tp) {      /* trap not NULL or SIG_IGN */
+			INT_OFF;
+			free(*tp);
+			*tp = NULL;
+			if (tp != &trap[0])
+				setsignal(tp - trap);
+			INT_ON;
+		}
+	}
+}
+static void
 forkchild(struct job *jp, union node *n, int mode)
 {
 	int oldlvl;
@@ -11264,148 +11403,7 @@
 	return 0;
 }
 
-/*
- * Clear traps on a fork.
- */
-static void
-clear_traps(void)
-{
-	char **tp;
 
-	for (tp = trap; tp < &trap[NSIG]; tp++) {
-		if (*tp && **tp) {      /* trap not NULL or SIG_IGN */
-			INT_OFF;
-			free(*tp);
-			*tp = NULL;
-			if (tp != &trap[0])
-				setsignal(tp - trap);
-			INT_ON;
-		}
-	}
-}
-
-/*
- * Set the signal handler for the specified signal.  The routine figures
- * out what it should be set to.
- */
-static void
-setsignal(int signo)
-{
-	int action;
-	char *t, tsig;
-	struct sigaction act;
-
-	t = trap[signo];
-	if (t == NULL)
-		action = S_DFL;
-	else if (*t != '\0')
-		action = S_CATCH;
-	else
-		action = S_IGN;
-	if (rootshell && action == S_DFL) {
-		switch (signo) {
-		case SIGINT:
-			if (iflag || minusc || sflag == 0)
-				action = S_CATCH;
-			break;
-		case SIGQUIT:
-#if DEBUG
-			if (debug)
-				break;
-#endif
-			/* FALLTHROUGH */
-		case SIGTERM:
-			if (iflag)
-				action = S_IGN;
-			break;
-#if JOBS
-		case SIGTSTP:
-		case SIGTTOU:
-			if (mflag)
-				action = S_IGN;
-			break;
-#endif
-		}
-	}
-
-	t = &sigmode[signo - 1];
-	tsig = *t;
-	if (tsig == 0) {
-		/*
-		 * current setting unknown
-		 */
-		if (sigaction(signo, 0, &act) == -1) {
-			/*
-			 * Pretend it worked; maybe we should give a warning
-			 * here, but other shells don't. We don't alter
-			 * sigmode, so that we retry every time.
-			 */
-			return;
-		}
-		if (act.sa_handler == SIG_IGN) {
-			if (mflag
-			 && (signo == SIGTSTP || signo == SIGTTIN || signo == SIGTTOU)
-			) {
-				tsig = S_IGN;   /* don't hard ignore these */
-			} else
-				tsig = S_HARD_IGN;
-		} else {
-			tsig = S_RESET; /* force to be set */
-		}
-	}
-	if (tsig == S_HARD_IGN || tsig == action)
-		return;
-	switch (action) {
-	case S_CATCH:
-		act.sa_handler = onsig;
-		break;
-	case S_IGN:
-		act.sa_handler = SIG_IGN;
-		break;
-	default:
-		act.sa_handler = SIG_DFL;
-	}
-	*t = action;
-	act.sa_flags = 0;
-	sigfillset(&act.sa_mask);
-	sigaction(signo, &act, 0);
-}
-
-/*
- * Called to execute a trap.  Perhaps we should avoid entering new trap
- * handlers while we are executing a trap handler.
- */
-static int
-dotrap(void)
-{
-	char *p;
-	char *q;
-	int i;
-	int savestatus;
-	int skip = 0;
-
-	savestatus = exitstatus;
-	pendingsigs = 0;
-	xbarrier();
-
-	for (i = 0, q = gotsig; i < NSIG - 1; i++, q++) {
-		if (!*q)
-			continue;
-		*q = '\0';
-
-		p = trap[i + 1];
-		if (!p)
-			continue;
-		skip = evalstring(p, SKIPEVAL);
-		exitstatus = savestatus;
-		if (skip)
-			break;
-	}
-
-	return skip;
-}
-
-
 /* ============ Builtins */
 
 #if !ENABLE_FEATURE_SH_EXTRA_QUIET




More information about the busybox-cvs mailing list