From: Jonathan Nieder <jrnieder@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Gerrit Pape <pape@smarden.org>,
dash@vger.kernel.org, "Krzysztof A. Sobiecki" <sobkas@gmail.com>
Subject: [PATCH] [OPTIONS] Use exit status 127 when the script to run does not exist
Date: Wed, 6 Oct 2010 05:04:20 -0500 [thread overview]
Message-ID: <20101006100420.GA361@burratino> (raw)
In-Reply-To: <20100628065326.GA25667@gondor.apana.org.au>
Currently dash uses exit status 2 to report failure to run a
script named on the command line that does not exist:
$ sh nonexistent
sh: Can't open nonexistent
$ echo $?
2
According to SUSv3 and SUSv4[1], the exit code should be 127.
So check errno when opening a command_file during argument
processing and exit(127) when it is ENOENT. This check is in the
argument processing code to avoid collateral damage to code paths
that read scripts (such as the dot builtin). Other errors (such
as EACCESS) while opening the command_file will still result in
an exit code of 2.
[1] http://www.opengroup.org/onlinepubs/9699919799/utilities/sh.html#tag_20_117_14
Reported-by: Clint Adams <schizo@debian.org>
Fixes: http://bugs.debian.org/548743
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Herbert Xu wrote:
> This is wrong. You're creating exactly the problem that Jilles
> was talking about where dot(1) is returning 127. This code should
> be moved to procargs, which runs only for the "sh script" case.
Makes sense. How does this look?
It still ignores attempts to run "sh directory"; see the next
patch for that.
src/options.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/src/options.c b/src/options.c
index 6f381e6..5667b68 100644
--- a/src/options.c
+++ b/src/options.c
@@ -37,6 +37,7 @@
#include <stdlib.h>
#include "shell.h"
+#include "main.h"
#define DEFINE_OPTIONS
#include "options.h"
#undef DEFINE_OPTIONS
@@ -156,7 +157,13 @@ procargs(int argc, char **argv)
if (*xargv)
goto setarg0;
} else if (!sflag) {
- setinputfile(*xargv, 0);
+ if (setinputfile(*xargv, INPUT_NOFILE_OK) < 0) {
+ if (errno == ENOENT) {
+ exitstatus = 127;
+ exerror(EXEXIT, "Can't open %s", *xargv);
+ }
+ sh_error("Can't open %s", *xargv);
+ }
setarg0:
arg0 = *xargv++;
commandname = arg0;
--
1.7.2.3
next prev parent reply other threads:[~2010-10-06 10:07 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 ` Jonathan Nieder [this message]
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
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=20101006100420.GA361@burratino \
--to=jrnieder@gmail.com \
--cc=dash@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
--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