summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-11-22 23:49:06 +0000
committerjilles <jilles@FreeBSD.org>2010-11-22 23:49:06 +0000
commit31d53d7f2272d4c12ee7ca17a27d7979828843c4 (patch)
tree65f1f6aaa8349d54bc54cf5226500c3944f3bc88
parent163ca01105dd047c9f3d794b45bbb97881fbabf8 (diff)
downloadFreeBSD-src-31d53d7f2272d4c12ee7ca17a27d7979828843c4.zip
FreeBSD-src-31d53d7f2272d4c12ee7ca17a27d7979828843c4.tar.gz
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.
-rw-r--r--bin/sh/cd.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index cec7496..2ac4b10 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -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);
}
OpenPOWER on IntegriCloud