-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All that ${STDCP} instead of cp, etc. is annoying. These are hardcoded paths determined by mamprobe, so they point to known-good standard utilities on the default system PATH. But it makes the Mamfiles harder to read. They also weren't even being used for all of them, e.g., there is no ${STDMKDIR}. This commit uses another strategy: bin/package ensures setting a sane system PATH with: - the /opt/ast/bin virtual directory first (for ksh) - $(getconf PATH) directories next - all other user PATH directories follow these - duplicate directories removed - nonexistent directories removed This applies to 'bin/package use' environments as well. This is then preceded by two bin directories in $INSTALLROOT, but this build system controls those, so that's OK. The Mamfiles can now use standard command names without worrying about invoking potentially dodgy versions on the user's PATH. The code to set the ${STD...} variables is kept in mamprobe for backward compatibility with old Mamfiles.
- Loading branch information
Showing
9 changed files
with
296 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ if (eval "$min_posix") 2>/dev/null | |
then : good shell | ||
else "$SHELL" -c "$min_posix" 2>/dev/null && exec "$SHELL" -- "$0" ${1+"$@"} | ||
sh -c "$min_posix" 2>/dev/null && exec sh -- "$0" ${1+"$@"} | ||
DEFPATH=`getconf PATH` 2>/dev/null || DEFPATH=/usr/xpg4/bin:/bin:/usr/bin:/sbin:/usr/sbin | ||
DEFPATH=`getconf PATH 2>/dev/null` || DEFPATH=/usr/xpg4/bin:/bin:/usr/bin:/sbin:/usr/sbin | ||
PATH=$DEFPATH:$PATH | ||
export PATH | ||
sh -c "$min_posix" 2>/dev/null && exec sh -- "$0" ${1+"$@"} | ||
|
@@ -82,6 +82,42 @@ case $PWD in | |
exit 1 ;; | ||
esac || exit | ||
|
||
# Outputs sanitized system $PATH, eliminating duplicate and nonexistent dirs, '..', etc. | ||
sanitize_PATH() ( | ||
set -fu +e | ||
IFS=':' | ||
unset -v CDPATH | ||
sPATH='' | ||
for dir in $1; do | ||
# Sanitize this path, resolving symlinks, | ||
# with special-casing of ksh's virtual built-ins directory | ||
case $dir in | ||
/opt/ast/bin) | ||
test ! -d "$dir" && sdir=$dir ;; | ||
*/* | [!+-]* | [+-]*[!0123456789]*) | ||
sdir=$(cd -- $dir 2>/dev/null && pwd -P && echo X) ;; | ||
*) sdir=$(cd ./$dir 2>/dev/null && pwd -P && echo X) ;; | ||
esac || continue | ||
sdir=${sdir%?X} | ||
# Skip duplicates | ||
case :$sPATH: in | ||
*:"$sdir":*) | ||
continue ;; | ||
esac | ||
# Found one, add it | ||
sPATH=${sPATH:+$sPATH:}$sdir | ||
done | ||
printf '%s\n' "${sPATH#:}" | ||
) | ||
|
||
# Ensure a sane $PATH beginning with standard utilities. | ||
# Find preferred 'getconf' on NixOS and Solaris/illumos. | ||
DEFPATH=$( | ||
PATH=/run/current-system/sw/bin:/usr/xpg7/bin:/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin:$PATH | ||
getconf PATH 2>/dev/null | ||
) || DEFPATH=/bin:/usr/bin:/sbin:/usr/sbin | ||
PATH=$(sanitize_PATH "/opt/ast/bin:$DEFPATH:$PATH") | ||
|
||
# shell checks | ||
checksh() | ||
{ | ||
|
@@ -115,7 +151,7 @@ command=${0##*/} | |
case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in | ||
0123) USAGE=$' | ||
[-? | ||
@(#)$Id: '$command$' (ksh 93u+m) 2024-02-11 $ | ||
@(#)$Id: '$command$' (ksh 93u+m) 2024-02-12 $ | ||
] | ||
[-author?Glenn Fowler <[email protected]>] | ||
[-author?Contributors to https://github.com/ksh93/ksh] | ||
|
@@ -543,7 +579,7 @@ SEE ALSO | |
pkgadd(1), pkgmk(1), rpm(1), sh(1), tar(1), optget(3) | ||
|
||
IMPLEMENTATION | ||
version package (ksh 93u+m) 2024-02-11 | ||
version package (ksh 93u+m) 2024-02-12 | ||
author Glenn Fowler <[email protected]> | ||
author Contributors to https://github.com/ksh93/ksh | ||
copyright (c) 1994-2012 AT&T Intellectual Property | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.