Date: Mon, 22 Nov 2010 23:49:06 +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: r215727 - head/bin/sh Message-ID: <201011222349.oAMNn6Ro010254@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Mon Nov 22 23:49:06 2010 New Revision: 215727 URL: http://svn.freebsd.org/changeset/base/215727 Log: sh: Fix confusing behaviour if chdir succeeded but getcwd failed in cd -P. If getcwd fails, do not treat this as an error, but print a warning and unset PWD. This is similar to the behaviour when starting the shell in a directory whose name cannot be determined. Modified: head/bin/sh/cd.c Modified: head/bin/sh/cd.c ============================================================================== --- head/bin/sh/cd.c Mon Nov 22 23:35:29 2010 (r215726) +++ head/bin/sh/cd.c Mon Nov 22 23:49:06 2010 (r215727) @@ -219,10 +219,13 @@ cdphysical(char *dest) char *p; INTOFF; - if (chdir(dest) < 0 || (p = findcwd(NULL)) == NULL) { + if (chdir(dest) < 0) { INTON; return (-1); } + p = findcwd(NULL); + if (p == NULL) + out2fmt_flush("cd: warning: failed to get name of current directory\n"); updatepwd(p); INTON; return (0); @@ -304,7 +307,7 @@ updatepwd(char *dir) if (prevdir) ckfree(prevdir); prevdir = curdir; - curdir = savestr(dir); + curdir = dir ? savestr(dir) : NULL; setvar("PWD", curdir, VEXPORT); setvar("OLDPWD", prevdir, VEXPORT); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011222349.oAMNn6Ro010254>