Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Jan 2012 23:32:27 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r230095 - in head: bin/sh tools/regression/bin/sh/builtins
Message-ID:  <201201132332.q0DNWRYw085215@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Fri Jan 13 23:32:27 2012
New Revision: 230095
URL: http://svn.freebsd.org/changeset/base/230095

Log:
  sh: Properly show "Not a directory" error in cd builtin.
  
  The errno message display added in r222292 did not take attempting to
  cd to a non-directory or something that cannot be stat()ed into account.
  
  PR:		bin/164070
  MFC after:	10 days

Added:
  head/tools/regression/bin/sh/builtins/cd8.0   (contents, props changed)
Modified:
  head/bin/sh/cd.c

Modified: head/bin/sh/cd.c
==============================================================================
--- head/bin/sh/cd.c	Fri Jan 13 23:31:36 2012	(r230094)
+++ head/bin/sh/cd.c	Fri Jan 13 23:32:27 2012	(r230095)
@@ -130,7 +130,12 @@ cdcmd(int argc, char **argv)
 	    (path = bltinlookup("CDPATH", 1)) == NULL)
 		path = nullstr;
 	while ((p = padvance(&path, dest)) != NULL) {
-		if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
+		if (stat(p, &statb) < 0) {
+			if (errno != ENOENT)
+				errno1 = errno;
+		} else if (!S_ISDIR(statb.st_mode))
+			errno1 = ENOTDIR;
+		else {
 			if (!print) {
 				/*
 				 * XXX - rethink

Added: head/tools/regression/bin/sh/builtins/cd8.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/cd8.0	Fri Jan 13 23:32:27 2012	(r230095)
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+# The exact wording of the error message is not standardized, but giving
+# a description of the errno is useful.
+
+LC_ALL=C
+export LC_ALL
+r=0
+
+t() {
+	exec 3>&1
+	errmsg=`cd "$1" 2>&1 >&3 3>&-`
+	exec 3>&-
+	case $errmsg in
+	*[Nn]ot\ a\ directory*)
+		;;
+	*)
+		printf "Wrong error message for %s: %s\n" "$1" "$errmsg"
+		r=3
+		;;
+	esac
+}
+
+t /dev/tty
+t /dev/tty/x
+exit $r



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201132332.q0DNWRYw085215>