All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero
@ 2010-06-14  9:56 Gerrit Pape
  2010-06-28  7:02 ` Herbert Xu
  2010-07-06  9:51 ` Herbert Xu
  0 siblings, 2 replies; 6+ messages in thread
From: Gerrit Pape @ 2010-06-14  9:56 UTC (permalink / raw)
  To: dash; +Cc: Herbert Xu

Example:

$ dash -c 'set -e; (false); echo here'
here

With this commit, dash exits 1 before echo.

The bug was reported by Stefan Fritsch through
 http://bugs.debian.org/514863

Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 src/eval.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/eval.c b/src/eval.c
index 439f881..a0d0f3b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -251,6 +251,8 @@ checkexit:
 	case NSUBSHELL:
 	case NBACKGND:
 		evalfn = evalsubshell;
+		if (eflag && !(flags & EV_TESTED))
+			checkexit = ~0;
 		goto calleval;
 	case NPIPE:
 		evalfn = evalpipe;
-- 
1.6.0.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero
  2010-06-14  9:56 [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero Gerrit Pape
@ 2010-06-28  7:02 ` Herbert Xu
  2010-06-28  7:22   ` Cristian Ionescu-Idbohrn
  2010-07-06  9:51 ` Herbert Xu
  1 sibling, 1 reply; 6+ messages in thread
From: Herbert Xu @ 2010-06-28  7:02 UTC (permalink / raw)
  To: dash

On Mon, Jun 14, 2010 at 09:56:03AM +0000, Gerrit Pape wrote:
> Example:
> 
> $ dash -c 'set -e; (false); echo here'
> here
> 
> With this commit, dash exits 1 before echo.
> 
> The bug was reported by Stefan Fritsch through
>  http://bugs.debian.org/514863
> 
> Signed-off-by: Gerrit Pape <pape@smarden.org>

I'm not convinced that this change is necessary.  I've run some
tests and bash/pdksh both behave like dash, while ksh93 behaves
in the way you suggest.

Has bash's behaviour changed recently (I'm using an ancient
version)?

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero
  2010-06-28  7:02 ` Herbert Xu
@ 2010-06-28  7:22   ` Cristian Ionescu-Idbohrn
  2010-06-28 13:16     ` Eric Blake
  0 siblings, 1 reply; 6+ messages in thread
From: Cristian Ionescu-Idbohrn @ 2010-06-28  7:22 UTC (permalink / raw)
  To: dash

On Mon, 28 Jun 2010, Herbert Xu wrote:

> On Mon, Jun 14, 2010 at 09:56:03AM +0000, Gerrit Pape wrote:
> > Example:
> >
> > $ dash -c 'set -e; (false); echo here'
> > here
> >
> > With this commit, dash exits 1 before echo.
> >
> > The bug was reported by Stefan Fritsch through
> >  http://bugs.debian.org/514863
> >
> > Signed-off-by: Gerrit Pape <pape@smarden.org>
>
> I'm not convinced that this change is necessary.  I've run some
> tests and bash/pdksh both behave like dash, while ksh93 behaves
> in the way you suggest.
>
> Has bash's behaviour changed recently (I'm using an ancient
> version)?

bash 3.2.39 and 4.0.37 are behaving as dash without the suggested
patch.  Still.  What is the correct behaviour?  That should be the
essential matter IMO, not what others do.  So, why should this fail:

	$ dash -c 'set -e; false; echo here'

and this succeed?

	$ dash -c 'set -e; (false); echo here'

The subshell returns exit code 1, and errexit is set.  Why does dash
ignore that exit code in the later case?


Cheers,

-- 
Cristian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero
  2010-06-28  7:22   ` Cristian Ionescu-Idbohrn
@ 2010-06-28 13:16     ` Eric Blake
  2010-07-05  8:26       ` Herbert Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Blake @ 2010-06-28 13:16 UTC (permalink / raw)
  To: dash; +Cc: Cristian Ionescu-Idbohrn

[-- Attachment #1: Type: text/plain, Size: 2357 bytes --]

On 06/28/2010 01:22 AM, Cristian Ionescu-Idbohrn wrote:
>> Has bash's behaviour changed recently (I'm using an ancient
>> version)?

Yes - bash 4.1 tries harder to be compliant with the recent Austin Group
interpretations (and more like ksh).

> 
> bash 3.2.39 and 4.0.37 are behaving as dash without the suggested
> patch.  Still.  What is the correct behaviour?  That should be the
> essential matter IMO, not what others do.  So, why should this fail:
> 
> 	$ dash -c 'set -e; false; echo here'
> 
> and this succeed?
> 
> 	$ dash -c 'set -e; (false); echo here'

According to the Austin Group:
http://austingroupbugs.net/view.php?id=52

the desired behavior is:

Replace the description of -e with:

  -e When this option is on, when any command fails (for any of the
      reasons listed in [xref to 2.8.1] or by returning an exit status
      greater than zero) the shell immediately shall exit with the
      following exceptions:

      1) The failure of any individual command in a multi-command
          pipeline shall not cause the shell to exit. Only the
          failure of the pipeline itself shall be considered.

      2) The -e setting shall be ignored when executing the compound
          list following the while, until, if, or elif reserved word,
          a pipeline beginning with the ! reserved word, or any
          command of an AND-OR list other than the last.

      3) If the exit status of a compound command other than a
          subshell command was the result of a failure while -e was
          being ignored, then -e shall not apply to this command.

      This requirement applies to the shell environment and each
      subshell environment separately. For example, in

          set -e; (false; echo one) | cat; echo two

      the false command causes the subshell to exit without executing
      echo one; however, echo two is executed because the exit status
      of the pipeline (false; echo one) | cat is zero.

Per these rules, both 'set -e; false; echo here' and 'set -e; (false);
echo here' are silent in bash 4.1.  The fact that dash is not silent
when a subshell exits with non-zero status is at odds with the above
Austin Group ruling.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero
  2010-06-28 13:16     ` Eric Blake
@ 2010-07-05  8:26       ` Herbert Xu
  0 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2010-07-05  8:26 UTC (permalink / raw)
  To: Eric Blake; +Cc: dash, cristian.ionescu-idbohrn

Eric Blake <eblake@redhat.com> wrote:
> [-- text/plain, encoding quoted-printable, charset: ISO-8859-1, 62 lines --]
> 
> On 06/28/2010 01:22 AM, Cristian Ionescu-Idbohrn wrote:
>>> Has bash's behaviour changed recently (I'm using an ancient
>>> version)?
> 
> Yes - bash 4.1 tries harder to be compliant with the recent Austin Group
> interpretations (and more like ksh).

OK I'll apply the patch.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero
  2010-06-14  9:56 [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero Gerrit Pape
  2010-06-28  7:02 ` Herbert Xu
@ 2010-07-06  9:51 ` Herbert Xu
  1 sibling, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2010-07-06  9:51 UTC (permalink / raw)
  To: dash

On Mon, Jun 14, 2010 at 09:56:03AM +0000, Gerrit Pape wrote:
> Example:
> 
> $ dash -c 'set -e; (false); echo here'
> here
> 
> With this commit, dash exits 1 before echo.
> 
> The bug was reported by Stefan Fritsch through
>  http://bugs.debian.org/514863
> 
> Signed-off-by: Gerrit Pape <pape@smarden.org>

Applied with slight change:

commit a92255d6fa8b8efb0f9fb093b77ac601fe3e9ede
Author: Gerrit Pape <pape@smarden.org>
Date:   Tue Jul 6 17:50:37 2010 +0800

    [EVAL] Check exit for eval NSUBSHELL
    
    Example:
    
    $ dash -c 'set -e; (false); echo here'
    here
    
    With this commit, dash exits 1 before echo.
    
    The bug was reported by Stefan Fritsch through
     http://bugs.debian.org/514863
    
    Signed-off-by: Gerrit Pape <pape@smarden.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/ChangeLog b/ChangeLog
index 3f5e24c..0e367a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-07-06  Gerrit Pape <pape@smarden.org>
+
+	* Check exit for eval NSUBSHELL.
+
 2010-07-06  Herbert Xu <herbert@gondor.apana.org.au>
 
 	* Fix loss of variables when hash collides.
diff --git a/src/eval.c b/src/eval.c
index 58739f5..5b8d36b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -251,7 +251,7 @@ checkexit:
 	case NSUBSHELL:
 	case NBACKGND:
 		evalfn = evalsubshell;
-		goto calleval;
+		goto checkexit;
 	case NPIPE:
 		evalfn = evalpipe;
 		goto checkexit;
 
Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-07-06  9:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-14  9:56 [PATCH] [EVAL] with set -e exit the shell if a subshell exits non-zero Gerrit Pape
2010-06-28  7:02 ` Herbert Xu
2010-06-28  7:22   ` Cristian Ionescu-Idbohrn
2010-06-28 13:16     ` Eric Blake
2010-07-05  8:26       ` Herbert Xu
2010-07-06  9:51 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.