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.
This commit is contained in:
parent
ccf7ba972c
commit
ae7f47355d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=215727
@ -219,10 +219,13 @@ cdphysical(char *dest)
|
|||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
INTOFF;
|
INTOFF;
|
||||||
if (chdir(dest) < 0 || (p = findcwd(NULL)) == NULL) {
|
if (chdir(dest) < 0) {
|
||||||
INTON;
|
INTON;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
p = findcwd(NULL);
|
||||||
|
if (p == NULL)
|
||||||
|
out2fmt_flush("cd: warning: failed to get name of current directory\n");
|
||||||
updatepwd(p);
|
updatepwd(p);
|
||||||
INTON;
|
INTON;
|
||||||
return (0);
|
return (0);
|
||||||
@ -304,7 +307,7 @@ updatepwd(char *dir)
|
|||||||
if (prevdir)
|
if (prevdir)
|
||||||
ckfree(prevdir);
|
ckfree(prevdir);
|
||||||
prevdir = curdir;
|
prevdir = curdir;
|
||||||
curdir = savestr(dir);
|
curdir = dir ? savestr(dir) : NULL;
|
||||||
setvar("PWD", curdir, VEXPORT);
|
setvar("PWD", curdir, VEXPORT);
|
||||||
setvar("OLDPWD", prevdir, VEXPORT);
|
setvar("OLDPWD", prevdir, VEXPORT);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user