[PATCH 1/2] [INPUT] exit 127 if command_file is given but does not exist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


This commit makes dash exit with return code 127 instead of 2 if
started as non-interactive shell with a non-existent command_file
specified as argument, as documented in
 http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html#tag_04_128_14

The wrong exit code was reported by Clint Adams through
 http://bugs.debian.org/548743

Signed-off-by: Gerrit Pape <pape@xxxxxxxxxxx>
---
 src/input.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/input.c b/src/input.c
index e57ad76..c1e3e54 100644
--- a/src/input.c
+++ b/src/input.c
@@ -101,6 +101,7 @@ MKINIT struct parsefile basepf;	/* top level input file */
 MKINIT char basebuf[IBUFSIZ];	/* buffer for top level input file */
 struct parsefile *parsefile = &basepf;	/* current input file */
 int whichprompt;		/* 1 == PS1, 2 == PS2 */
+extern int exitstatus;
 
 #ifndef SMALL
 EditLine *el;			/* cookie for editline package */
@@ -408,7 +409,9 @@ setinputfile(const char *fname, int flags)
 	if ((fd = open(fname, O_RDONLY)) < 0) {
 		if (flags & INPUT_NOFILE_OK)
 			goto out;
-		sh_error("Can't open %s", fname);
+		sh_warnx("Can't open %s", fname);
+		exitstatus = 127;
+		exraise(EXEXIT);
 	}
 	if (fd < 10)
 		fd = savefd(fd, fd);
-- 
1.6.0.3

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

Powered by Linux