NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/38584 (bin/sh: 'set -e' + pipe)



The following reply was made to PR bin/38584; it has been noted by GNATS.

From: Matthias Scheler <tron%NetBSD.org@localhost>
To: NetBSD GNATS <gnats-bugs%NetBSD.org@localhost>
Cc: 
Subject: Re: bin/38584 (bin/sh: 'set -e' + pipe)
Date: Sat, 24 May 2008 18:07:07 +0100

 On Sat, May 24, 2008 at 04:35:02PM +0000, Matthias Scheler wrote:
 >  The following change fixes the problem for me:
 
 This patch was wrong. It broke e.g. "if date | false; then". Here is
 a better one based on FreeBSD's patch:
 
 Index: eval.c
 ===================================================================
 RCS file: /cvsroot/src/bin/sh/eval.c,v
 retrieving revision 1.89
 diff -u -r1.89 eval.c
 --- eval.c     15 Feb 2008 17:26:06 -0000      1.89
 +++ eval.c     24 May 2008 16:59:58 -0000
 @@ -41,6 +41,7 @@
  #endif
  #endif /* not lint */
  
 +#include <stdbool.h>
  #include <stdlib.h>
  #include <signal.h>
  #include <stdio.h>
 @@ -216,6 +217,9 @@
  void
  evaltree(union node *n, int flags)
  {
 +      bool do_etest;
 +
 +      do_etest = false;
        if (n == NULL) {
                TRACE(("evaltree(NULL) called\n"));
                exitstatus = 0;
 @@ -253,6 +257,7 @@
                break;
        case NSUBSHELL:
                evalsubshell(n, flags);
 +              do_etest = !(flags & EV_TESTED);
                break;
        case NBACKGND:
                evalsubshell(n, flags);
 @@ -289,9 +294,11 @@
                break;
        case NPIPE:
                evalpipe(n);
 +              do_etest = !(flags & EV_TESTED);
                break;
        case NCMD:
                evalcommand(n, flags, (struct backcmd *)NULL);
 +              do_etest = !(flags & EV_TESTED);
                break;
        default:
                out1fmt("Node type = %d\n", n->type);
 @@ -301,7 +308,7 @@
  out:
        if (pendingsigs)
                dotrap();
 -      if ((flags & EV_EXIT) != 0)
 +      if ((flags & EV_EXIT) != 0 || (eflag && exitstatus != 0 && do_etest))
                exitshell(exitstatus);
  }
  
 @@ -1070,9 +1077,6 @@
                 */
                setvar("_", lastarg, 0);
        popstackmark(&smark);
 -
 -      if (eflag && exitstatus && !(flags & EV_TESTED))
 -              exitshell(exitstatus);
  }
  
  
        Kind regards
 
 -- 
 Matthias Scheler                                  http://zhadum.org.uk/
 


Home | Main Index | Thread Index | Old Index