From e5f903b9451c6e6a79eee939fcf6558a0b93cf8e Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Thu, 12 Jan 2006 21:02:26 +1100 Subject: [EVAL] Make eval with empty arguments return 0 On Tue, Jan 10, 2006 at 10:56:23AM +0000, Gerrit Pape wrote: > tags 347232 + patch > quit > > On Mon, Jan 09, 2006 at 04:29:19PM +0100, Marco Nenciarini wrote: > > The problem is here: > > > > # Set the kernel 2.6 option only for fresh install > > test -z "$(GetMenuOpt "kopt" "")" && kopt_2_6="root=$root_device_2_6 ro" > > > > # Extract options for specific kernels > > eval $(ExtractMenuOpts "\(kopt_[a-zA-Z0-9_]\+\)") > > > > If the first test fails and the eval argument is empty then dash > > terminate with exitcode 1. > > > This is a simple testcase: > > tm:~# bash -c "set -e ;/bin/false && : ; eval ''; echo 'END'"; echo $? > > END > > 0 > > tm:~# dash -c "set -e ;/bin/false && : ; eval ''; echo 'END'"; echo $? > > 1 > > > > if you insert any command with successfull exit status before the > > empty eval, all work ok: > > tm:~# bash -c "set -e ;/bin/false && : ; : ; eval ''; echo 'END'"; echo $? > > END > > 0 > > tm:~# dash -c "set -e ;/bin/false && : ; : ; eval ''; echo 'END'"; echo $? > > END > > 0 > > Yes, I can confirm this is a bug in dash. The standard says > > EXIT STATUS > > If there are no arguments, or only null arguments, eval shall > return a zero exit status; otherwise, it shall return the exit > status of the command defined by the string of concatenated > arguments separated by s. > > Hi Herbert, please see http://bugs.debian.org/347232 Changed evalstring to return the exit status instead of evalskip. This allows us to return zero if the string is empty. --- src/eval.c | 18 ++++++++---------- src/trap.c | 9 ++++----- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/eval.c b/src/eval.c index f8f6f0a..07e7ee2 100644 --- a/src/eval.c +++ b/src/eval.c @@ -150,10 +150,9 @@ evalcmd(int argc, char **argv) STPUTC('\0', concat); p = grabstackstr(concat); } - evalstring(p, ~SKIPEVAL); - + return evalstring(p, ~SKIPEVAL); } - return exitstatus; + return 0; } @@ -166,24 +165,23 @@ evalstring(char *s, int mask) { union node *n; struct stackmark smark; - int skip; + int status; setinputstring(s); setstackmark(&smark); - skip = 0; + status = 0; while ((n = parsecmd(0)) != NEOF) { evaltree(n, 0); + status = exitstatus; popstackmark(&smark); - skip = evalskip; - if (skip) + if (evalskip) break; } popfile(); - skip &= mask; - evalskip = skip; - return skip; + evalskip &= mask; + return status; } diff --git a/src/trap.c b/src/trap.c index bbff81a..eae6186 100644 --- a/src/trap.c +++ b/src/trap.c @@ -295,7 +295,6 @@ dotrap(void) char *q; int i; int savestatus; - int skip = 0; savestatus = exitstatus; pendingsigs = 0; @@ -309,13 +308,13 @@ dotrap(void) p = trap[i + 1]; if (!p) continue; - skip = evalstring(p, SKIPEVAL); + evalstring(p, SKIPEVAL); exitstatus = savestatus; - if (skip) - break; + if (evalskip) + return evalskip; } - return skip; + return 0; } -- cgit 1.4.1 d=e4118a0a5a67eb61966326cbdf9875bdd266d14c&follow=1'>Add boot commands for serial consoleJune McEnroe 2021-09-26Publish "Installing OpenBSD on Linode"June McEnroe 2021-09-26Use tiny UTF-8-aware col -b replacementJune McEnroe 2021-09-25Install up to cgi-binJune McEnroe 2021-09-25Clean up up (ugh) somewhat againJune McEnroe 2021-09-25Update root path in up.shJune McEnroe 2021-09-25Disable HashKnownHostsJune McEnroe 2021-09-25Add scout to ssh configJune McEnroe 2021-09-25Sandbox up on both FreeBSD and OpenBSDJune McEnroe 2021-09-25Set SO_REUSEADDR in quickJune McEnroe 2021-09-25Revert "Add cat alias using less"June McEnroe 2021-09-24Pledge downgradeJune McEnroe 2021-09-24Set original socket CLOEXECJune McEnroe 2021-09-24Consume request headers using MSG_PEEKJune McEnroe 2021-09-24Set only HTTP_HOSTJune McEnroe 2021-09-23Scroll by single lines in xtermJune McEnroe 2021-09-23Hide htop "function bar"June McEnroe 2021-09-23Allow FocusEvents in xtermJune McEnroe 2021-09-23Use NI_NUMERICSERVJune McEnroe 2021-09-23Make up build away from FreeBSDJune McEnroe 2021-09-23Add quickJune McEnroe 2021-09-23Add The HobbitJune McEnroe 2021-09-22Remove PSF fontsJune McEnroe 2021-09-22Remove Linux-specific utilitiesJune McEnroe 2021-09-22Call sandbox in CGI modeJune McEnroe 2021-09-22Support HTTP PUT in upJune McEnroe 2021-09-22Remove default faviconJune McEnroe 2021-09-21Use Z_FILTERED strategyJune McEnroe 2021-09-21Recalculate various lengths only as neededJune McEnroe 2021-09-21Rewrite pngo, add explicit optionsJune McEnroe 2021-09-16Fix /* **/ comment matchingJune McEnroe 2021-09-15Remove typer, add downgrade to READMEJune McEnroe 2021-09-15Set bot mode on downgradeJune McEnroe 2021-09-15Enter capsicum in downgradeJune McEnroe 2021-09-15Factor out common parts of downgrade messagesJune McEnroe 2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe 2021-09-13Swap-remove tags as they're foundJune McEnroe 2021-09-12Replace htagml regex with strncmpJune McEnroe 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe