NetBSD Problem Report #38736

From cheusov@tut.by  Sat May 24 19:15:15 2008
Return-Path: <cheusov@tut.by>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id E26F963BA68
	for <gnats-bugs@gnats.netbsd.org>; Sat, 24 May 2008 19:15:14 +0000 (UTC)
Message-Id: <s934p8n1plc.fsf@chen.chizhovka.net>
Date: Sat, 24 May 2008 22:14:55 +0300
From: cheusov@tut.by
Reply-To:
To: gnats-bugs@gnats.NetBSD.org
Subject: /bin/sh: several problems with 'set -e'
X-Send-Pr-Version: 3.95

>Number:         38736
>Category:       bin
>Synopsis:       /bin/sh: several problems with 'set -e'
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat May 24 19:20:00 +0000 2008
>Closed-Date:    Tue Apr 05 08:51:37 +0000 2016
>Last-Modified:  Tue Apr 05 08:51:37 +0000 2016
>Originator:     cheusov@tut.by
>Release:        NetBSD 4.0_STABLE
>Organization:
>Environment:
System: NetBSD chen.chizhovka.net 4.0_STABLE NetBSD 4.0_STABLE (GENERIC) #3: Wed Apr 23 00:58:08 EEST 2008 cheusov@chen.chizhovka.net:/srv/obj/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
There are several problems with NetBSD-4 version of /bin/sh and 'set -e'.
>How-To-Repeat:
Run the following code one-by-one. And PLEASE create regression tests
for each case. Also note that "white box" testing whould be good.

case1 (tracked in bin/38584):
    set -e

    echo | false

    echo 'This should not happen!'

case2:
    set -e

    ! true

    echo 'This should not happen'

case3:
   set -e

   true | false &
   job=$!

   wait $job
   echo $?

   echo 'This should not happen'

case4:
   set -e

   false && false

   echo 'This should not happen'

>Fix:

Unknown
>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: bin-bug-people->tron
Responsible-Changed-By: tron@NetBSD.org
Responsible-Changed-When: Sun, 25 May 2008 09:37:29 +0000
Responsible-Changed-Why:
I'll handle this PR.


State-Changed-From-To: open->closed
State-Changed-By: tron@NetBSD.org
State-Changed-When: Mon, 26 May 2008 14:58:25 +0000
State-Changed-Why:
At least one of your examples ("! true") is explicitly listed as an
exception of the "set -e" behaviour in the POSIX spec:

http://www.opengroup.org/onlinepubs/000095399/utilities/set.html

Please compose a new list of test cases and compare them *carefully*
with the spec and submit a new PR.


From: Aleksey Cheusov <cheusov@tut.by>
To: gnats-bugs@NetBSD.org
Cc: tron@NetBSD.org,  netbsd-bugs@netbsd.org,  gnats-admin@netbsd.org
Subject: Re: bin/38736 (/bin/sh: several problems with 'set -e')
Date: Mon, 26 May 2008 22:51:33 +0300

 > Synopsis: /bin/sh: several problems with 'set -e'

 > State-Changed-From-To: open->closed
 > State-Changed-By: tron@NetBSD.org
 > State-Changed-When: Mon, 26 May 2008 14:58:25 +0000
 > State-Changed-Why:
 > At least one of your examples ("! true") is explicitly listed as an
 > exception of the "set -e" behaviour in the POSIX spec:

 > http://www.opengroup.org/onlinepubs/000095399/utilities/set.html
 No. You read this spec incorrectly. Reread it.

 Subsentence that describes `!' case:

   "-e When this option is on, if a simple command fails for any of the
   reasons listed in Consequences of Shell Errors or returns an exit
   status value >0, and is not a pipeline preceded by the ! reserved
   word, then the shell shall immediately exit.

 "simple command" here means 'true' WITHOUT leading '!' (see below).
 Therefore, this sentence is about '! false' which should not exit from
 shell script.  This is obviously because the exit status of whole
 command if TRUE.

    http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_09_01
    "A "simple command" is a sequence of optional variable assignments
    and redirections, in any sequence, optionally followed by words and
    redirections, terminated by a control operator."

 Another definitions:

    "2.9.2 Pipelines
    A pipeline is a sequence of one or more commands
    separated by the control operator '|'." (ONE OR MORE!)

    "A command is one of the following: Simple command (see Simple
    Commands) Pipeline (see Pipelines) List compound-list (see Lists)
    Compound command (see Compound Commands) Function definition (see
    Function Definition Command)"

 > Please compose a new list of test cases and compare them *carefully*
 > with the spec and submit a new PR.
 Do not close bugs if they are not fixed.

 -- 
 Best regards, Aleksey Cheusov.

Responsible-Changed-From-To: tron->bin-bug-people
Responsible-Changed-By: tron@NetBSD.org
Responsible-Changed-When: Mon, 26 May 2008 22:02:53 +0000
Responsible-Changed-Why:
I'll leave this PR to someone who knows the standards by heart.


State-Changed-From-To: closed->suspended
State-Changed-By: tron@NetBSD.org
State-Changed-When: Mon, 26 May 2008 22:02:53 +0000
State-Changed-Why:
There is an ongoing discussion whether any of the cases mentioned in this
PR are actually bugs or correct according to the standard.


From: David Holland <dholland-bugs@netbsd.org>
To: Aleksey Cheusov <cheusov@tut.by>
Cc: gnats-bugs@NetBSD.org, tron@NetBSD.org, netbsd-bugs@netbsd.org,
	gnats-admin@netbsd.org
Subject: Re: bin/38736 (/bin/sh: several problems with 'set -e')
Date: Mon, 26 May 2008 22:14:22 +0000

 On Mon, May 26, 2008 at 10:51:33PM +0300, Aleksey Cheusov wrote:
  > > http://www.opengroup.org/onlinepubs/000095399/utilities/set.html
  > No. You read this spec incorrectly. Reread it.

 Can you look at src/tests/util/sh/t_set_e.sh and submit any needed
 corrections (or additions) in one or more new PRs?

 If we do this all with respect to the specific behavior of specific
 examples (creating more when necessary) there might be some chance of
 getting all the details right. Otherwise, there are too many
 exceptions and combinations and confounding factors.

 (To run the thing, "compile" it, then cd obj && ./t_set_e. Note that
 you can also do env TEST_SH=ksh ./t_set_e to see what ksh does, or
 similarly for other shells.)

 -- 
 David A. Holland
 dholland@netbsd.org

From: Aleksey Cheusov <cheusov@tut.by>
To: gnats-bugs@NetBSD.org
Cc: tron@NetBSD.org,  netbsd-bugs@netbsd.org,  gnats-admin@netbsd.org
Subject: Re: bin/38736 (/bin/sh: several problems with 'set -e')
Date: Sun, 01 Jun 2008 20:29:08 +0300

  >> At least one of your examples ("! true") is explicitly listed as an
  >> exception of the "set -e" behaviour in the POSIX spec:

  >> http://www.opengroup.org/onlinepubs/000095399/utilities/set.html
 > No. You read this spec incorrectly.

 You was right. The example with '!' was bad but not because
 it is listed as an exception. Anyway, forget about it.

 As was discussed in tech-userlevel@, another example 'false && false'
 was also bad. /bin/sh currently works just like most other shells.
 Spec says only about failures of 'Simple commands'.

 'set -e' + pipe is fixed in revision 1.93.

 Another example, background pipe + 'wait <pid>',
 still needs to be fixed.

 P.S.
 Three repetitions of 'do_etest = !(flags & EV_TESTED);' look
 ugly. Why not to treat 'do_etest variable as boolean,
 checking '!(flags & EV_TESTED)' once and write do_etest=0|1 instead?

 -- 
 Best regards, Aleksey Cheusov.

State-Changed-From-To: suspended->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Tue, 05 Apr 2016 08:51:37 +0000
State-Changed-Why:
This seems to be resolved.
Please file a new bug report if there are open issues. Thanks!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.