From owner-svn-src-head@freebsd.org Sun Jun 25 21:53:10 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 416CFD9B1B5; Sun, 25 Jun 2017 21:53:10 +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 mx1.freebsd.org (Postfix) with ESMTPS id 1B91C7F1B4; Sun, 25 Jun 2017 21:53:10 +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 v5PLr90d035799; Sun, 25 Jun 2017 21:53:09 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v5PLr80F035795; Sun, 25 Jun 2017 21:53:08 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201706252153.v5PLr80F035795@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sun, 25 Jun 2017 21:53:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r320340 - in head/bin/sh: . tests/builtins X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Sun, 25 Jun 2017 21:53:10 -0000 Author: jilles Date: Sun Jun 25 21:53:08 2017 New Revision: 320340 URL: https://svnweb.freebsd.org/changeset/base/320340 Log: sh: Ignore error when cd writes the directory actually switched to. If CDPATH is used non-trivially or the operand is "-", cd writes the directory actually switched to. (We currently do this only in interactive shells, but POSIX requires this in non-interactive shells as well.) As mentioned in Austin group bug #1045, cd shall not return an error while leaving the current directory changed. Therefore, ignore any write error. Added: head/bin/sh/tests/builtins/cd10.0 (contents, props changed) Modified: head/bin/sh/cd.c head/bin/sh/sh.1 head/bin/sh/tests/builtins/Makefile Modified: head/bin/sh/cd.c ============================================================================== --- head/bin/sh/cd.c Sun Jun 25 20:06:05 2017 (r320339) +++ head/bin/sh/cd.c Sun Jun 25 21:53:08 2017 (r320340) @@ -164,8 +164,17 @@ docd(char *dest, int print, int phys) if ((phys || (rc = cdlogical(dest)) < 0) && (rc = cdphysical(dest)) < 0) return (-1); - if (print && iflag && curdir) + if (print && iflag && curdir) { out1fmt("%s\n", curdir); + /* + * Ignore write errors to preserve the invariant that the + * current directory is changed iff the exit status is 0 + * (or 1 if -e was given and the full pathname could not be + * determined). + */ + flushout(out1); + outclearerror(out1); + } return (rc); } Modified: head/bin/sh/sh.1 ============================================================================== --- head/bin/sh/sh.1 Sun Jun 25 20:06:05 2017 (r320339) +++ head/bin/sh/sh.1 Sun Jun 25 21:53:08 2017 (r320340) @@ -2018,6 +2018,11 @@ to return exit status 1 if the full pathname of the ne cannot be determined reliably or at all. Normally this is not considered an error, although a warning is printed. +.Pp +If changing the directory fails, the exit status is greater than 1. +If the directory is changed, the exit status is 0, or also 1 if +.Fl e +was given. .It Ic chdir A synonym for the .Ic cd Modified: head/bin/sh/tests/builtins/Makefile ============================================================================== --- head/bin/sh/tests/builtins/Makefile Sun Jun 25 20:06:05 2017 (r320339) +++ head/bin/sh/tests/builtins/Makefile Sun Jun 25 21:53:08 2017 (r320340) @@ -51,6 +51,7 @@ ${PACKAGE}FILES+= cd6.0 ${PACKAGE}FILES+= cd7.0 ${PACKAGE}FILES+= cd8.0 ${PACKAGE}FILES+= cd9.0 cd9.0.stdout +${PACKAGE}FILES+= cd10.0 ${PACKAGE}FILES+= command1.0 ${PACKAGE}FILES+= command2.0 ${PACKAGE}FILES+= command3.0 Added: head/bin/sh/tests/builtins/cd10.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/builtins/cd10.0 Sun Jun 25 21:53:08 2017 (r320340) @@ -0,0 +1,6 @@ +# $FreeBSD$ + +# Precondition +(cd /bin) || exit +# Verify write error is ignored. +$SH +m -ic 'CDPATH=/:; cd bin 1