diff --git a/NEWS b/NEWS index 41464aa3b..96a108f4b 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,13 @@ For full details, see the git log at: https://github.com/ksh93/ksh Any uppercase BUG_* names are modernish shell bug IDs. +2020-06-18: + +- A two decade old bug that caused 'whence -a' to base the path of + tracked aliases on the user's current working directory has been + fixed. Now the real path to the tracked aliases is shown when '-a' + is passed to the whence command. + 2020-06-17: - A bug in 'unset -f' was fixed that prevented shell functions from diff --git a/src/cmd/ksh93/bltins/whence.c b/src/cmd/ksh93/bltins/whence.c index 7843ca762..e84dc63b3 100644 --- a/src/cmd/ksh93/bltins/whence.c +++ b/src/cmd/ksh93/bltins/whence.c @@ -249,7 +249,10 @@ static int whence(Shell_t *shp,char **argv, register int flags) if(*cp!= '/') { if(!np && (np=nv_search(name,shp->track_tree,0))) - sfprintf(sfstdout,"%s %s %s/%s\n",name,sh_translate(is_talias),path_pwd(shp,0),cp); + { + const char *command_path = np->nvalue.pathcomp->name; + sfprintf(sfstdout,"%s %s %s/%s\n",name,sh_translate(is_talias),command_path,cp); + } else if(!np || nv_isnull(np)) sfprintf(sfstdout,"%s%s\n",name,sh_translate(is_ufunction)); continue; diff --git a/src/cmd/ksh93/include/name.h b/src/cmd/ksh93/include/name.h index 5398ff657..697809488 100644 --- a/src/cmd/ksh93/include/name.h +++ b/src/cmd/ksh93/include/name.h @@ -32,6 +32,7 @@ #include typedef int (*Nambfp_f)(int, char**, void*); +struct pathcomp; /* Nodes can have all kinds of values */ union Value @@ -54,6 +55,7 @@ union Value struct Namfun *funp; /* discipline pointer */ struct Namref *nrp; /* name reference */ Nambfp_f bfp; /* builtin entry point function pointer */ + struct pathcomp *pathcomp; }; #include "nval.h" diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 69bca002a..57d6ef8a3 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -17,4 +17,4 @@ * David Korn * * * ***********************************************************************/ -#define SH_RELEASE "93u+m 2020-06-17" +#define SH_RELEASE "93u+m 2020-06-18" diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index 262270994..213a2a6c7 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -1793,8 +1793,10 @@ void path_alias(register Namval_t *np,register Pathcomp_t *pp) { struct stat statb; char *sp; + Pathcomp_t *old; nv_offattr(np,NV_NOPRINT); nv_stack(np,&talias_init); + old = np->nvalue.pathcomp; np->nvalue.cp = (char*)pp; pp->refcount++; nv_setattr(np,NV_TAGGED|NV_NOFREE); diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index d1c730bc8..24c583452 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -702,5 +702,19 @@ printf '\\\000' | read -r -d '' foo=BUG command eval ':' [[ $foo == BUG ]] && err_exit '`command` fails to disable the special properties of special builtins' +# ====== +# `whence -a` should not base the path of tracked aliases on the current directory +run_whence() +{ + whence -a chmod >> /dev/null + builtin chmod + whence -a chmod +} +actual="$(run_whence)" +expected="chmod is a shell builtin +chmod is $(whence -p chmod) +chmod is a tracked alias for $(whence -p chmod)" +[[ $actual == $expected ]] || err_exit '`whence -a` does not work correctly with tracked aliases' + # ====== exit $((Errors<125?Errors:125))