[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: shell 'trap' woodoo :)
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2010-09-25 15:16:16
Message-ID: 201009251716.16913.vda.linux () googlemail ! com
[Download RAW message or body]

On Tuesday 14 September 2010 20:43, Cristian Ionescu-Idbohrn wrote:
> On Tue, 14 Sep 2010, Denys Vlasenko wrote:
> 
> > On Mon, Sep 13, 2010 at 11:52 PM, Cristian Ionescu-Idbohrn
> > <cristian.ionescu-idbohrn@axis.com> wrote:
> > > On Mon, 13 Sep 2010, Denys Vlasenko wrote:
> > >
> > >> On Sun, Sep 12, 2010 at 10:31 PM, Cristian Ionescu-Idbohrn
> > >> <cristian.ionescu-idbohrn@axis.com> wrote:
> > >> >> # Automatically generated make config: don't edit
> > >> >> # Busybox version: 1.18.0.git
> > >> >> # Sun Sep 12 18:25:22 2010
> > >>
> > >> No, I need the ENTIRE .config, not its header.
> > >
> > > Attached.
> >
> > It's
> >
> > CONFIG_FEATURE_SH_STANDALONE=y
> > CONFIG_FEATURE_SH_NOFORK=y
> >
> > sleep is a nofork applet. It should not be. I am fixing this.
> > Try attached patch.
> 
> Alright.  Ash is "working" almost as expected.  The 'trap' is still run
> twice on SIGINT, but behaves.  Hush, on the other side, seems to work as
> expected, WRT skipping the second run (does only one run through the
> signals).

Please try attached patch.
-- 
vda

["4.patch" (text/x-diff)]

diff -ad -urpN busybox.3/shell/ash.c busybox.4/shell/ash.c
--- busybox.3/shell/ash.c	2010-09-17 01:05:35.000000000 +0200
+++ busybox.4/shell/ash.c	2010-09-25 17:14:54.000000000 +0200
@@ -8214,7 +8214,7 @@ static int evalstring(char *s, int mask)
 
 /* Called to execute a trap.
  * Single callsite - at the end of evaltree().
- * If we return non-zero, exaltree raises EXEXIT exception.
+ * If we return non-zero, evaltree raises EXEXIT exception.
  *
  * Perhaps we should avoid entering new trap handlers
  * while we are executing a trap handler. [is it a TODO?]
@@ -8404,11 +8404,15 @@ evaltree(union node *n, int flags)
 
  out:
 	exception_handler = savehandler;
+
  out1:
+	/* Order of checks below is important:
+	 * signal handlers trigger before exit caused by "set -e".
+	 */
+	if (pending_sig && dotrap())
+		goto exexit;
 	if (checkexit & exitstatus)
 		evalskip |= SKIPEVAL;
-	else if (pending_sig && dotrap())
-		goto exexit;
 
 	if (flags & EV_EXIT) {
  exexit:
@@ -8740,7 +8744,7 @@ poplocalvars(void)
 	while ((lvp = localvars) != NULL) {
 		localvars = lvp->next;
 		vp = lvp->vp;
-		TRACE(("poplocalvar %s\n", vp ? vp->text : "-"));
+		TRACE(("poplocalvar %s\n", vp ? vp->var_text : "-"));
 		if (vp == NULL) {       /* $- saved */
 			memcpy(optlist, lvp->text, sizeof(optlist));
 			free((char*)lvp->text);
@@ -13009,10 +13013,12 @@ int ash_main(int argc UNUSED_PARAM, char
 		if (e == EXERROR)
 			exitstatus = 2;
 		s = state;
-		if (e == EXEXIT || s == 0 || iflag == 0 || shlvl)
+		if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) {
 			exitshell();
-		if (e == EXINT)
+		}
+		if (e == EXINT) {
 			outcslow('\n', stderr);
+		}
 
 		popstackmark(&smark);
 		FORCE_INT_ON; /* enable interrupts */
@@ -13105,6 +13111,7 @@ int ash_main(int argc UNUSED_PARAM, char
 		_mcleanup();
 	}
 #endif
+	TRACE(("End of main reached\n"));
 	exitshell();
 	/* NOTREACHED */
 }


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic