mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 11:42:21 +00:00
Fix 'command -p' by fixing initialisation of default PATH variable
'command -p' was broken for non-interactive shells as the variable used to store the default system PATH, std_path, was not initialised correctly. For instance: $ ksh -c 'command -p ls' ksh: ls: not found This fix by Siteshwar Vashisht is backported from ksh2020. Ref.: https://github.com/att/ast/issues/426 https://github.com/att/ast/pull/448 src/cmd/ksh93/sh/path.c: - Correctly initialise std_path (the default PATH) when ksh is started as a non-interactive shell. src/cmd/ksh93/sh.1: - Fix vague explanation of 'command -p'. src/cmd/ksh93/tests/path.sh: - Add regression test. (cherry picked from commit a76439d60b70c18cf44d84c1962fcd8df84c947c)
This commit is contained in:
parent
f35e7ecd1d
commit
c9ccee86bb
5 changed files with 24 additions and 7 deletions
7
NEWS
7
NEWS
|
@ -4,6 +4,13 @@ For full details, see the git log at:
|
||||||
|
|
||||||
Any uppercase BUG_* names are modernish shell bug IDs.
|
Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
|
|
||||||
|
2020-05-19:
|
||||||
|
|
||||||
|
- Fix 'command -p'. The -p option causes the operating system's standard
|
||||||
|
utilities path (as output by 'getconf PATH') to be searched instead of $PATH.
|
||||||
|
Before this fix, this was broken on non-interactive shells as the internal
|
||||||
|
variable holding the default PATH value was not correctly initialised.
|
||||||
|
|
||||||
2020-05-16:
|
2020-05-16:
|
||||||
|
|
||||||
- Fix 'test -t 1', '[ -t 1 ]', '[[ -t 1 ]]' in command substitutions.
|
- Fix 'test -t 1', '[ -t 1 ]', '[[ -t 1 ]]' in command substitutions.
|
||||||
|
|
|
@ -17,4 +17,4 @@
|
||||||
* David Korn <dgk@research.att.com> *
|
* David Korn <dgk@research.att.com> *
|
||||||
* *
|
* *
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
#define SH_RELEASE "93u+m 2020-05-16"
|
#define SH_RELEASE "93u+m 2020-05-19"
|
||||||
|
|
|
@ -5806,7 +5806,8 @@ with the arguments given by
|
||||||
The
|
The
|
||||||
.B \-p
|
.B \-p
|
||||||
option causes
|
option causes
|
||||||
a default path to be searched
|
the operating system's standard utilities path
|
||||||
|
(as output by \f3getconf PATH\fP) to be searched
|
||||||
rather than the one defined by the value of
|
rather than the one defined by the value of
|
||||||
.SM
|
.SM
|
||||||
.BR PATH .
|
.BR PATH .
|
||||||
|
|
|
@ -56,11 +56,14 @@ static void funload(Shell_t*,int,const char*);
|
||||||
static void exscript(Shell_t*,char*, char*[], char**);
|
static void exscript(Shell_t*,char*, char*[], char**);
|
||||||
static int path_chkpaths(Shell_t*,Pathcomp_t*,Pathcomp_t*,Pathcomp_t*,int);
|
static int path_chkpaths(Shell_t*,Pathcomp_t*,Pathcomp_t*,Pathcomp_t*,int);
|
||||||
static void path_checkdup(Shell_t *shp,register Pathcomp_t*);
|
static void path_checkdup(Shell_t *shp,register Pathcomp_t*);
|
||||||
|
static Pathcomp_t *defpath_init(Shell_t *shp);
|
||||||
|
|
||||||
static const char *std_path;
|
static const char *std_path = NULL;
|
||||||
|
|
||||||
static int onstdpath(const char *name)
|
static int onstdpath(Shell_t *shp, const char *name)
|
||||||
{
|
{
|
||||||
|
if(!std_path)
|
||||||
|
defpath_init(shp);
|
||||||
register const char *cp = std_path, *sp;
|
register const char *cp = std_path, *sp;
|
||||||
if(cp)
|
if(cp)
|
||||||
while(*cp)
|
while(*cp)
|
||||||
|
@ -379,7 +382,7 @@ static void path_checkdup(Shell_t *shp,register Pathcomp_t *pp)
|
||||||
pp->mtime = statb.st_mtime;
|
pp->mtime = statb.st_mtime;
|
||||||
pp->ino = statb.st_ino;
|
pp->ino = statb.st_ino;
|
||||||
pp->dev = statb.st_dev;
|
pp->dev = statb.st_dev;
|
||||||
if(*name=='/' && onstdpath(name))
|
if(*name=='/' && onstdpath(shp, name))
|
||||||
flag = PATH_STD_DIR;
|
flag = PATH_STD_DIR;
|
||||||
first = (pp->flags&PATH_CDPATH)?(Pathcomp_t*)shp->cdpathlist:path_get(shp,"");
|
first = (pp->flags&PATH_CDPATH)?(Pathcomp_t*)shp->cdpathlist:path_get(shp,"");
|
||||||
for(oldpp=first; oldpp && oldpp!=pp; oldpp=oldpp->next)
|
for(oldpp=first; oldpp && oldpp!=pp; oldpp=oldpp->next)
|
||||||
|
@ -450,6 +453,8 @@ Pathcomp_t *path_nextcomp(Shell_t *shp,register Pathcomp_t *pp, const char *name
|
||||||
|
|
||||||
static Pathcomp_t* defpath_init(Shell_t *shp)
|
static Pathcomp_t* defpath_init(Shell_t *shp)
|
||||||
{
|
{
|
||||||
|
if(!std_path && !(std_path=astconf("PATH",NIL(char*),NIL(char*))))
|
||||||
|
std_path = e_defpath;
|
||||||
Pathcomp_t *pp = (void*)path_addpath(shp,(Pathcomp_t*)0,(std_path),PATH_PATH);
|
Pathcomp_t *pp = (void*)path_addpath(shp,(Pathcomp_t*)0,(std_path),PATH_PATH);
|
||||||
return(pp);
|
return(pp);
|
||||||
}
|
}
|
||||||
|
@ -458,8 +463,6 @@ static void path_init(Shell_t *shp)
|
||||||
{
|
{
|
||||||
const char *val;
|
const char *val;
|
||||||
Pathcomp_t *pp;
|
Pathcomp_t *pp;
|
||||||
if(!std_path && !(std_path=astconf("PATH",NIL(char*),NIL(char*))))
|
|
||||||
std_path = e_defpath;
|
|
||||||
if(val=sh_scoped(shp,(PATHNOD))->nvalue.cp)
|
if(val=sh_scoped(shp,(PATHNOD))->nvalue.cp)
|
||||||
{
|
{
|
||||||
shp->pathlist = pp = (void*)path_addpath(shp,(Pathcomp_t*)shp->pathlist,val,PATH_PATH);
|
shp->pathlist = pp = (void*)path_addpath(shp,(Pathcomp_t*)shp->pathlist,val,PATH_PATH);
|
||||||
|
|
|
@ -397,5 +397,11 @@ ${.sh.version}
|
||||||
END
|
END
|
||||||
) || err_exit '${.sh.xxx} variables causes cat not be found'
|
) || err_exit '${.sh.xxx} variables causes cat not be found'
|
||||||
|
|
||||||
|
# ======
|
||||||
|
# Check that 'command -p' searches the default OS utility PATH.
|
||||||
|
v=$(PATH=/dev/null "$SHELL" -c 'command -p ls /dev/null')
|
||||||
|
[[ $v == /dev/null ]] || err_exit 'command -p fails to find standard utility'
|
||||||
|
|
||||||
|
# ======
|
||||||
exit $((Errors<125?Errors:125))
|
exit $((Errors<125?Errors:125))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue