From f485fe0f8d0d6296c79db98a1d56ed66128a8ca2 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 11 Aug 2020 14:12:48 +0100 Subject: [PATCH] rm redundant hardcoded default paths (re: aa4669ad) As of aa4669ad, astconf("PATH") is implemented as a hardcoded AST configuration variable that always has a value, instead of one that falls back on the OS. Its value is now obtained from the OS (with a fallback) at configure time and not at runtime. This means that any fallback for astconf("PATH") is now never used. src/cmd/ksh93/data/msg.c, src/cmd/ksh93/include/shell.h: - Remove e_defpath[]. (The path "/bin:/usr/bin:" made no sense as a default path anyway, as the final empty element is wrong: default utilities should never be sought in the current working dir.) src/cmd/ksh93/sh/path.c, src/lib/libast/path/pathbin.c: - abort() if astconf("PATH") returns null. src/lib/libast/comp/conf.tab: PATH: - If no 'getconf' utility can be found, use a fallback path that finds more utilities by also searching in 'sbin' directories. On some systems, this is needed to find chown(1). src/cmd/ksh93/sh.1: - Update doc re default path. --- src/cmd/ksh93/data/msg.c | 1 - src/cmd/ksh93/include/shell.h | 1 - src/cmd/ksh93/sh.1 | 12 +++--------- src/cmd/ksh93/sh/path.c | 2 +- src/lib/libast/comp/conf.tab | 2 +- src/lib/libast/path/pathbin.c | 2 +- 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/cmd/ksh93/data/msg.c b/src/cmd/ksh93/data/msg.c index a82377b42..d0721a9ba 100644 --- a/src/cmd/ksh93/data/msg.c +++ b/src/cmd/ksh93/data/msg.c @@ -170,7 +170,6 @@ const char e_heading[] = "Current option settings"; const char e_sptbnl[] = " \t\n"; const char e_tolower[] = "tolower"; const char e_toupper[] = "toupper"; -const char e_defpath[] = "/bin:/usr/bin:"; const char e_defedit[] = _pth_ed; const char e_unknown [] = ""; const char e_devnull[] = "/dev/null"; diff --git a/src/cmd/ksh93/include/shell.h b/src/cmd/ksh93/include/shell.h index 269ab363f..b0b8d7666 100644 --- a/src/cmd/ksh93/include/shell.h +++ b/src/cmd/ksh93/include/shell.h @@ -106,7 +106,6 @@ typedef union Shnode_u Shnode_t; /* The following type is used for error messages */ /* error messages */ -extern const char e_defpath[]; extern const char e_found[]; extern const char e_nospace[]; extern const char e_format[]; diff --git a/src/cmd/ksh93/sh.1 b/src/cmd/ksh93/sh.1 index 3e3c540ef..8477bcebc 100644 --- a/src/cmd/ksh93/sh.1 +++ b/src/cmd/ksh93/sh.1 @@ -4189,15 +4189,9 @@ search for the command name. Alternative directory names are separated by a colon .RB ( : ). -The default path is equal to the output of -.BI builtin\ getconf;\ getconf\ PATH -or, if the OS doesn't provide that value, -.B /bin:/usr/bin: -(specifying -.BR /bin , -.BR /usr/bin , -and the current directory -in that order). +The default path is the value that was output by +.BI getconf\ PATH +at the time ksh was compiled. The current directory can be specified by two or more adjacent colons, or by a colon at the beginning or end of the path list. diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index a3c642812..5447b0275 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -454,7 +454,7 @@ Pathcomp_t *path_nextcomp(Shell_t *shp,register Pathcomp_t *pp, const char *name static Pathcomp_t* defpath_init(Shell_t *shp) { if(!std_path && !(std_path=astconf("PATH",NIL(char*),NIL(char*)))) - std_path = e_defpath; + abort(); Pathcomp_t *pp = (void*)path_addpath(shp,(Pathcomp_t*)0,(std_path),PATH_PATH); return(pp); } diff --git a/src/lib/libast/comp/conf.tab b/src/lib/libast/comp/conf.tab index 36e29ce70..48c5647df 100644 --- a/src/lib/libast/comp/conf.tab +++ b/src/lib/libast/comp/conf.tab @@ -375,7 +375,7 @@ PATH AST CS 1 MU sh{ *) CONF_path=`"$CONF_getconf" PATH` ;; esac case $CONF_path in - '') echo '"/bin:/usr/bin"' ;; + '') echo '"/bin:/usr/bin:/sbin:/usr/sbin"' ;; *) echo "\\"$CONF_path\\"" ;; esac } diff --git a/src/lib/libast/path/pathbin.c b/src/lib/libast/path/pathbin.c index cc9cdfa4d..2b19b199e 100644 --- a/src/lib/libast/path/pathbin.c +++ b/src/lib/libast/path/pathbin.c @@ -39,7 +39,7 @@ pathbin(void) if ((!(bin = getenv("PATH")) || !*bin) && !(bin = val)) { if (!*(bin = astconf("PATH", NiL, NiL)) || !(bin = strdup(bin))) - bin = "/bin:/usr/bin:/usr/local/bin"; + abort(); val = bin; } return bin;