From: Jonathan Nieder <jrnieder@gmail.com>
To: Eric Blake <eblake@redhat.com>
Cc: Herbert Xu <herbert@gondor.hengli.com.au>,
Gerrit Pape <pape@smarden.org>,
dash@vger.kernel.org, "Krzysztof A. Sobiecki" <sobkas@gmail.com>,
Jari Aalto <jari.aalto@cante.net>
Subject: [PATCH 0/3] Fix exit status for 'exec nonexistent' and 'exec .'
Date: Wed, 6 Oct 2010 20:02:41 -0500 [thread overview]
Message-ID: <20101007010241.GB1276@burratino> (raw)
In-Reply-To: <4CAC68FD.4040602@redhat.com>
Eric Blake wrote:
> Additionally, the standard REQUIRES that 'sh -c "exec /"' shall fail
> with status 126:
>
> http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#exec
> "If command is found, but it is not an executable utility, the exit
> status shall be 126."
>
> Right now, dash gets this wrong:
>
> dash -c 'exec .'; echo $?
> exec: 1: /: Permission denied
> 2
>
> And since you already have the code in dash to detect failure to
> 'exec' a directory, you should be able to reuse that code when
> detecting failure to run a directory as a script, as in 'dash .'.
Summary:
Command Status Expected status
1) exec . 2 126
2) exec nonexistent 2 127
3) sh . 0 126
4) sh nonexistent 2 127
(1) and (2) seem to be regressions from about 5 years ago.
Reverting the problematic patch fixes it for me; see below.
(3) is not clearly documented in the standard, and there is
some disagreement between shells on how to handle it[1]. The
current behavior seems fine to me.
(4) is a clear bug, well documented in the EXIT STATUS section
of the description of sh in the "Utilities" chapter. See
http://thread.gmane.org/gmane.comp.shells.dash/291/focus=390
for a patch[2].
Thoughts?
Jonathan Nieder (3):
[EXCEPTIONS] Stop documenting EXSHELLPROC
Revert "Eliminated global exerrno."
[EXCEPTIONS] Eliminate global exerrno
src/TOUR | 11 +----------
src/error.h | 5 ++---
src/eval.c | 8 ++++----
3 files changed, 7 insertions(+), 17 deletions(-)
[1]
$ bash .; echo $?
.: .: is a directory
126
$ ksh93 .; echo $?
ksh93: .: cannot open [Is a directory]
126
$ pdksh .; echo $?
0
[2] Unfortunately this does not share code with the fix to (1)
and (2) as Eric hoped. Why? The system calls involved are
different: the exec builtin uses execve(), while 'sh <script>'
uses open() and read().
next prev parent reply other threads:[~2010-10-07 1:06 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 ` Jonathan Nieder [this message]
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
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=20101007010241.GB1276@burratino \
--to=jrnieder@gmail.com \
--cc=dash@vger.kernel.org \
--cc=eblake@redhat.com \
--cc=herbert@gondor.hengli.com.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