ash: tentatively fix bug 189.

This commit is contained in:
Denis Vlasenko 2009-03-19 03:36:18 +00:00
parent 5981ba5843
commit 7f88e34e1a

View File

@ -165,7 +165,7 @@ struct globals_misc {
volatile /*sig_atomic_t*/ smallint intpending; /* 1 = got SIGINT */ volatile /*sig_atomic_t*/ smallint intpending; /* 1 = got SIGINT */
/* last pending signal */ /* last pending signal */
volatile /*sig_atomic_t*/ smallint pendingsig; volatile /*sig_atomic_t*/ smallint pendingsig;
smallint exception; /* kind of exception (0..5) */ smallint exception_type; /* kind of exception (0..5) */
/* exceptions */ /* exceptions */
#define EXINT 0 /* SIGINT received */ #define EXINT 0 /* SIGINT received */
#define EXERROR 1 /* a generic error */ #define EXERROR 1 /* a generic error */
@ -231,7 +231,7 @@ extern struct globals_misc *const ash_ptr_to_globals_misc;
#define physdir (G_misc.physdir ) #define physdir (G_misc.physdir )
#define arg0 (G_misc.arg0 ) #define arg0 (G_misc.arg0 )
#define exception_handler (G_misc.exception_handler) #define exception_handler (G_misc.exception_handler)
#define exception (G_misc.exception ) #define exception_type (G_misc.exception_type )
#define suppressint (G_misc.suppressint ) #define suppressint (G_misc.suppressint )
#define intpending (G_misc.intpending ) #define intpending (G_misc.intpending )
//#define exsig (G_misc.exsig ) //#define exsig (G_misc.exsig )
@ -290,7 +290,7 @@ raise_exception(int e)
abort(); abort();
#endif #endif
INT_OFF; INT_OFF;
exception = e; exception_type = e;
longjmp(exception_handler->loc, 1); longjmp(exception_handler->loc, 1);
} }
@ -385,7 +385,6 @@ static void
onsig(int signo) onsig(int signo)
{ {
gotsig[signo - 1] = 1; gotsig[signo - 1] = 1;
pendingsig = signo;
if (/* exsig || */ (signo == SIGINT && !trap[SIGINT])) { if (/* exsig || */ (signo == SIGINT && !trap[SIGINT])) {
if (!suppressint) { if (!suppressint) {
@ -393,6 +392,8 @@ onsig(int signo)
raise_interrupt(); /* does not return */ raise_interrupt(); /* does not return */
} }
intpending = 1; intpending = 1;
} else {
pendingsig = signo;
} }
} }
@ -5199,7 +5200,7 @@ redirectsafe(union node *redir, int flags)
redirect(redir, flags); redirect(redir, flags);
} }
exception_handler = savehandler; exception_handler = savehandler;
if (err && exception != EXERROR) if (err && exception_type != EXERROR)
longjmp(exception_handler->loc, 1); longjmp(exception_handler->loc, 1);
RESTORE_INT(saveint); RESTORE_INT(saveint);
return err; return err;
@ -7979,7 +7980,6 @@ static void prehash(union node *);
static void static void
evaltree(union node *n, int flags) evaltree(union node *n, int flags)
{ {
struct jmploc *volatile savehandler = exception_handler; struct jmploc *volatile savehandler = exception_handler;
struct jmploc jmploc; struct jmploc jmploc;
int checkexit = 0; int checkexit = 0;
@ -7998,7 +7998,7 @@ evaltree(union node *n, int flags)
int err = setjmp(jmploc.loc); int err = setjmp(jmploc.loc);
if (err) { if (err) {
/* if it was a signal, check for trap handlers */ /* if it was a signal, check for trap handlers */
if (exception == EXSIG) if (exception_type == EXSIG)
goto out; goto out;
/* continue on the way out */ /* continue on the way out */
exception_handler = savehandler; exception_handler = savehandler;
@ -9014,7 +9014,7 @@ evalcommand(union node *cmd, int flags)
if (evalbltin(cmdentry.u.cmd, argc, argv)) { if (evalbltin(cmdentry.u.cmd, argc, argv)) {
int exit_status; int exit_status;
int i = exception; int i = exception_type;
if (i == EXEXIT) if (i == EXEXIT)
goto raise; goto raise;
exit_status = 2; exit_status = 2;
@ -13529,7 +13529,7 @@ exitshell(void)
status = exitstatus; status = exitstatus;
TRACE(("pid %d, exitshell(%d)\n", getpid(), status)); TRACE(("pid %d, exitshell(%d)\n", getpid(), status));
if (setjmp(loc.loc)) { if (setjmp(loc.loc)) {
if (exception == EXEXIT) if (exception_type == EXEXIT)
/* dash bug: it just does _exit(exitstatus) here /* dash bug: it just does _exit(exitstatus) here
* but we have to do setjobctl(0) first! * but we have to do setjobctl(0) first!
* (bug is still not fixed in dash-0.5.3 - if you run dash * (bug is still not fixed in dash-0.5.3 - if you run dash
@ -13723,21 +13723,20 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
state = 0; state = 0;
if (setjmp(jmploc.loc)) { if (setjmp(jmploc.loc)) {
int e; smallint e;
smallint s; smallint s;
reset(); reset();
e = exception; e = exception_type;
if (e == EXERROR) if (e == EXERROR)
exitstatus = 2; exitstatus = 2;
s = state; s = state;
if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) if (e == EXEXIT || s == 0 || iflag == 0 || shlvl)
exitshell(); exitshell();
if (e == EXINT)
if (e == EXINT) {
outcslow('\n', stderr); outcslow('\n', stderr);
}
popstackmark(&smark); popstackmark(&smark);
FORCE_INT_ON; /* enable interrupts */ FORCE_INT_ON; /* enable interrupts */
if (s == 1) if (s == 1)