DASH Shell discussions
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Eric Blake <eblake@redhat.com>, Gerrit Pape <pape@smarden.org>,
	dash@vger.kernel.org, "Krzysztof A. Sobiecki" <sobkas@gmail.com>,
	Jari Aalto <jari.aalto@cante.net>
Subject: Re: [PATCH 2/3] Revert "Eliminated global exerrno."
Date: Thu, 7 Oct 2010 16:34:10 -0500	[thread overview]
Message-ID: <20101007213410.GA13464@burratino> (raw)
In-Reply-To: <20101007043715.GA15658@gondor.apana.org.au>

Herbert Xu wrote:

> 	sh -c 'trap "exec nosuchfile" EXIT; exit 3'; echo $?
> 
> This makes dash exit with 127 instead of 3 as it does now.
> 
> AFAIK the wording of POSIX is such that we should return 3, however,
> it does seem that every other shell exits with 127.

On 'exec':

 "If exec is specified with command, it shall replace the shell with
 command without creating a new process."		(1)

 "If command is specified, exec shall not return to the shell; rather,
 the exit status of the process shall be the exit status of the program
 implementing command, which overlaid the shell. If command is not
 found, the exit status shall be 127. If command is found, but it is
 not an executable utility, the exit status shall be 126. If a
 redirection error occurs (see Consequences of Shell Errors ), the
 shell shall exit with a value in the range 1-125. Otherwise, exec
 shall return a zero exit status."			(2)

On 'exit':

 "...
 A trap on EXIT shall be executed before the shell terminates, except
 when the exit utility is invoked in that trap itself, in which case
 the shell shall exit immediately."			(3)

 "The exit status [of the exit utility -jrn] shall be n, if specified.
 Otherwise, the value shall be the exit value of the last command
 executed, or zero if no command was executed. When exit is executed in
 a trap action, the last command is considered to be the command that
 executed immediately preceding the trap action."	(4)

The passage (3) seems to mean that "exit" triggers an EXIT trap
(except, to avoid having to deal with recursion, when the "exit"
occurs within an EXIT trap).  Then the exec builtin is invoked,
resulting (according to (2)) in an exit(127) without returning to the
shell.

So I think the proposed behavior fits the spec.

Regards,
Jonathan

  reply	other threads:[~2010-10-07 21:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-05 16:06 debian patches to exit with code 127 for nonexistent/directory scripts Jilles Tjoelker
2010-06-08 10:19 ` Herbert Xu
2010-06-08 10:36   ` Cristian Ionescu-Idbohrn
2010-06-11  8:39     ` Herbert Xu
2010-06-14  9:54 ` [PATCH] [INPUT] exit 127 if command_file is given but doesn't exist Gerrit Pape
2010-06-28  6:53   ` Herbert Xu
2010-10-06 10:04     ` [PATCH] [OPTIONS] Use exit status 127 when the script to run does not exist Jonathan Nieder
2010-10-06 10:08       ` [PATCH] [INPUT] Catch attempts to run a directory as a script Jonathan Nieder
2010-10-06 10:29         ` Herbert Xu
2010-10-06 10:55           ` Jonathan Nieder
2010-10-06 12:18             ` Eric Blake
2010-10-06 12:31               ` Herbert Xu
2010-10-07  1:02               ` [PATCH 0/3] Fix exit status for 'exec nonexistent' and 'exec .' Jonathan Nieder
2010-10-07  1:03                 ` [PATCH 1/3] [EXCEPTIONS] Stop documenting EXSHELLPROC Jonathan Nieder
2010-10-07  3:01                   ` Herbert Xu
2010-10-07  3:04                     ` Jonathan Nieder
2010-10-07  3:29                       ` Herbert Xu
2010-10-07  3:39                         ` [PATCH v2] " Jonathan Nieder
2010-11-28 12:47                           ` Herbert Xu
2010-10-07  1:04                 ` [PATCH 2/3] Revert "Eliminated global exerrno." Jonathan Nieder
2010-10-07  2:56                   ` Herbert Xu
2010-10-07  3:35                     ` Jonathan Nieder
2010-10-07  4:14                       ` Herbert Xu
2010-10-07  4:37                         ` Herbert Xu
2010-10-07 21:34                           ` Jonathan Nieder [this message]
2010-11-28 12:45                       ` Herbert Xu
2010-10-07  1:08                 ` [PATCH 3/3] [EXCEPTIONS] Eliminate global exerrno Jonathan Nieder
2010-10-07  3:00                   ` Herbert Xu
2010-11-28 12:06       ` [PATCH] [OPTIONS] Use exit status 127 when the script to run does not exist Herbert Xu
2010-11-28 12:24         ` Herbert Xu
2010-11-28 12:33           ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101007213410.GA13464@burratino \
    --to=jrnieder@gmail.com \
    --cc=dash@vger.kernel.org \
    --cc=eblake@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jari.aalto@cante.net \
    --cc=pape@smarden.org \
    --cc=sobkas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox