On Tue, Jan 10, 2006 at 10:56:23AM +0000, Gerrit Pape wrote:
> 
> 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 <space>s.
> 
> Hi Herbert, please see http://bugs.debian.org/347232

Thanks, I agree with your assessment.

> Index: src/eval.c
> ===================================================================
> RCS file: /cvs/dash/src/eval.c,v
> retrieving revision 1.3
> diff -u -r1.3 eval.c
> --- src/eval.c        28 Nov 2005 11:05:29 -0000      1.3
> +++ src/eval.c        10 Jan 2006 10:13:58 -0000
> @@ -140,19 +140,21 @@
>                  p = argv[1];
>                  if (argc > 2) {
>                          STARTSTACKSTR(concat);
> -                        ap = argv + 2;
> -                        for (;;) {
> +                        for (ap = argv + 1; (p = *ap); ++ap) {
> +                                if (!*p) continue;
>                               concat = stputs(p, concat);
> -                                if ((p = *ap++) == NULL)
> +                                if (*(ap + 1) == NULL)
>                                          break;
>                                  STPUTC(' ', concat);
>                          }
>                          STPUTC('\0', concat);
>                          p = grabstackstr(concat);
>                  }
> +                if (!*p) return 0;
>                  evalstring(p, ~SKIPEVAL);
>                  
>          }
> +        else return 0;
>          return exitstatus;
>  }

I think this is insufficient in that something like eval ' ' will
still leave the exit status unchanged.

So I've applied something like this.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
diff --git a/src/eval.c b/src/eval.c
--- 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
--- 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;
 }
 
 

Reply via email to