From owner-svn-src-head@freebsd.org Tue Nov 27 21:50:01 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ED138113BC51; Tue, 27 Nov 2018 21:50:00 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8B0EB70605; Tue, 27 Nov 2018 21:50:00 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 428A221268; Tue, 27 Nov 2018 21:50:00 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wARLo0ci000867; Tue, 27 Nov 2018 21:50:00 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wARLnx87000829; Tue, 27 Nov 2018 21:49:59 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201811272149.wARLnx87000829@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Tue, 27 Nov 2018 21:49:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r341097 - in head/bin/sh: . tests/errors X-SVN-Group: head X-SVN-Commit-Author: jilles X-SVN-Commit-Paths: in head/bin/sh: . tests/errors X-SVN-Commit-Revision: 341097 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8B0EB70605 X-Spamd-Result: default: False [1.39 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_SPAM_SHORT(0.51)[0.514,0]; NEURAL_SPAM_MEDIUM(0.36)[0.364,0]; NEURAL_SPAM_LONG(0.51)[0.511,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Nov 2018 21:50:01 -0000 Author: jilles Date: Tue Nov 27 21:49:59 2018 New Revision: 341097 URL: https://svnweb.freebsd.org/changeset/base/341097 Log: sh: Use 126 and 127 exit status for failures opening a script This affects scripts named on the command line, named with a '.' special builtin and found via the PATH %func autoloading mechanism. PR: 231986 Added: head/bin/sh/tests/errors/script-error1.0 (contents, props changed) Modified: head/bin/sh/input.c head/bin/sh/sh.1 head/bin/sh/tests/errors/Makefile Modified: head/bin/sh/input.c ============================================================================== --- head/bin/sh/input.c Tue Nov 27 21:40:51 2018 (r341096) +++ head/bin/sh/input.c Tue Nov 27 21:49:59 2018 (r341097) @@ -359,12 +359,16 @@ popstring(void) void setinputfile(const char *fname, int push) { + int e; int fd; int fd2; INTOFF; - if ((fd = open(fname, O_RDONLY | O_CLOEXEC)) < 0) - error("cannot open %s: %s", fname, strerror(errno)); + if ((fd = open(fname, O_RDONLY | O_CLOEXEC)) < 0) { + e = errno; + errorwithstatus(e == ENOENT || e == ENOTDIR ? 127 : 126, + "cannot open %s: %s", fname, strerror(e)); + } if (fd < 10) { fd2 = fcntl(fd, F_DUPFD_CLOEXEC, 10); close(fd); Modified: head/bin/sh/sh.1 ============================================================================== --- head/bin/sh/sh.1 Tue Nov 27 21:40:51 2018 (r341096) +++ head/bin/sh/sh.1 Tue Nov 27 21:49:59 2018 (r341097) @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd July 19, 2018 +.Dd November 27, 2018 .Dt SH 1 .Os .Sh NAME @@ -2819,7 +2819,11 @@ Shell database. Privileged shell profile. .El .Sh EXIT STATUS -Errors that are detected by the shell, such as a syntax error, will +If the +.Ar script +cannot be found, the exit status will be 127; +if it cannot be opened for another reason, the exit status will be 126. +Other errors that are detected by the shell, such as a syntax error, will cause the shell to exit with a non-zero exit status. If the shell is not an interactive shell, the execution of the shell file will be aborted. Modified: head/bin/sh/tests/errors/Makefile ============================================================================== --- head/bin/sh/tests/errors/Makefile Tue Nov 27 21:40:51 2018 (r341096) +++ head/bin/sh/tests/errors/Makefile Tue Nov 27 21:49:59 2018 (r341097) @@ -30,6 +30,7 @@ ${PACKAGE}FILES+= redirection-error5.0 ${PACKAGE}FILES+= redirection-error6.0 ${PACKAGE}FILES+= redirection-error7.0 ${PACKAGE}FILES+= redirection-error8.0 +${PACKAGE}FILES+= script-error1.0 ${PACKAGE}FILES+= write-error1.0 .include Added: head/bin/sh/tests/errors/script-error1.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/errors/script-error1.0 Tue Nov 27 21:49:59 2018 (r341097) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +{ stderr=$(${SH} /var/empty/nosuchscript 2>&1 >&3); } 3>&1 +r=$? +[ -n "$stderr" ] && [ "$r" = 127 ]