From 253568ed6557621f24337b775e54a03c7b4300e1 Mon Sep 17 00:00:00 2001 From: herbert Date: Fri, 25 Feb 2005 21:15:30 +1100 Subject: Catch set -e exits within built-in commands. --- ChangeLog | 1 + src/error.h | 1 + src/eval.c | 10 ++++++++-- src/main.c | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1734ecf..97598ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2005-02-25 Herbert Xu * Changed boolean rootshell into shlvl counter. + * Catch set -e exits within built-in commands. 2005-01-31 Gerrit Pape diff --git a/src/error.h b/src/error.h index c8e1a2e..2db9fe6 100644 --- a/src/error.h +++ b/src/error.h @@ -75,6 +75,7 @@ extern int exerrno; /* error for EXEXEC */ #define EXEXEC 3 /* command execution failed */ #define EXEXIT 4 /* exit the shell */ #define EXSIG 5 /* trapped signal in wait(1) */ +#define EXEVAL 6 /* exit the shell due to set -e */ /* diff --git a/src/eval.c b/src/eval.c index d1bf317..f7f0aeb 100644 --- a/src/eval.c +++ b/src/eval.c @@ -73,6 +73,7 @@ __RCSID("$NetBSD: eval.c,v 1.71 2003/01/23 03:33:16 rafal Exp $"); #include "error.h" #include "show.h" #include "mystring.h" +#include "main.h" #ifndef SMALL #include "myhistedit.h" #endif @@ -322,8 +323,10 @@ setstatus: out: if (pendingsigs) dotrap(); - if (flags & EV_EXIT || checkexit & exitstatus) + if (flags & EV_EXIT) exraise(EXEXIT); + if (checkexit & exitstatus) + exraise(EXEVAL); } @@ -708,12 +711,14 @@ evalcommand(union node *cmd, int flags) int spclbltin; int execcmd; int status; + int oldlvl; char **nargv; /* First expand the arguments. */ TRACE(("evalcommand(0x%lx, %d) called\n", (long)cmd, flags)); setstackmark(&smark); back_exitstatus = 0; + oldlvl = shlvl; cmdentry.cmdtype = CMDBUILTIN; cmdentry.u.cmd = &bltin; @@ -880,7 +885,8 @@ bail: status = j + 128; exitstatus = status; - if (i == EXINT || spclbltin > 0) { + if (i == EXINT || (i != EXEVAL && spclbltin > 0) || + oldlvl != shlvl) { raise: longjmp(handler->loc, 1); } diff --git a/src/main.c b/src/main.c index 0d69e4f..4902cfa 100644 --- a/src/main.c +++ b/src/main.c @@ -138,13 +138,17 @@ main(int argc, char **argv) status = 2; break; + case EXEXIT: + case EXEVAL: + state = 0; + /* fall through */ default: status = exitstatus; break; } exitstatus = status; - if (e == EXEXIT || state == 0 || iflag == 0 || ! rootshell) + if (state == 0 || iflag == 0 || shlvl) exitshell(); if (e == EXINT -- cgit 1.4.1 -11-15Request NAMES on sync by defaultJune McEnroe 2019-11-14Add concept of passive clientsJune McEnroe 2019-11-14Save and load full struct timevalJune McEnroe 2019-11-14Use struct timeval for sub-second precisionJune McEnroe 2019-11-14Remove server-time filter TODOJune McEnroe 2019-11-14Tweak filter regexesJune McEnroe 2019-11-14Filter multi-prefixJune McEnroe 2019-11-14Replace filters with regex replacesJune McEnroe 2019-11-13Refactor filterUserhostInNamesJune McEnroe 2019-11-13Factor out wordcpy for filtersJune McEnroe 2019-11-11Revert "Test getopt_config"June McEnroe 2019-11-11Test getopt_configJune McEnroe 2019-11-11Add userhost-in-names to manualJune McEnroe 2019-11-11Skip initial NAMES parametersJune McEnroe 2019-11-11Filter userhost-in-namesJune McEnroe 2019-11-10Compare words without copying in filtersJune McEnroe 2019-11-10Separate tags from all targetJune McEnroe 2019-11-10Filter invite-notifyJune McEnroe 2019-11-10Add capsicum note to READMEJune McEnroe 2019-11-10Filter extended-joinJune McEnroe 2019-11-10Expand client configuration documentation and list capabilitiesJune McEnroe 2019-11-10Request all supported caps from serverJune McEnroe 2019-11-10Filter ACCOUNT, AWAY, CHGHOST for incapable clientsJune McEnroe 2019-11-10Rename listen to localJune McEnroe 2019-11-09Remove extended-join and invite-notifyJune McEnroe 2019-11-09Maintain stateCaps and offer them to clientsJune McEnroe 2019-11-09Parse capabilitiesJune McEnroe 2019-11-09Avoid the reserved _A names with BIT macroJune McEnroe 2019-11-09Define macro for bit flag enumsJune McEnroe 2019-11-08Check that password is hashedJune McEnroe 2019-11-08Avoid calling getopt_long again after it returns -1June McEnroe 2019-11-08Only change AWAY status for registered clientsJune McEnroe 2019-11-07Just write the example normallyJune McEnroe 2019-11-07Include path in readlinkat errorJune McEnroe 2019-11-07Call clientConsume before clientRecvJune McEnroe 2019-11-06Use -l:filename in Linux.mkJune McEnroe 2019-11-06Fix compat.h for #defined strlcpyJune McEnroe 2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe 2019-11-06Document calico service configurationJune McEnroe 2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe