1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

package: Fix unspecified behavior after "unset PWD" (#176)

POSIX warns about "unset PWD" leading to unspecified behavior from
the pwd util, which we then use.

bin/package, src/cmd/INIT/package.sh:
- Determine if the shell has $PWD with a feature test. Only unset
  PWD if it does not (the old Bourne shell).
- Clean up 'case' flow.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
sterlingjensen 2021-02-20 07:58:52 -06:00 committed by GitHub
parent bdb997415d
commit e1690f61ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 64 deletions

View file

@ -29,49 +29,44 @@ case $PATH in
Bad*) echo "Cannot be run by zsh in native mode; use a sh symlink to zsh" >&2
exit 1 ;;
esac
unset path
unset CDPATH PWD
# Sanitize 'cd'
unset CDPATH
case `cd / && v=$PWD && cd /dev && v=$v,$PWD && echo "$v"` in
/,/dev) ;;
*) # old Bourne shell does not have $PWD; avoid inheriting it from
# the environment, which would kill our ${PWD:-`pwd`} fallback
unset PWD ;;
esac
# Make the package root the current working directory
case $0 in
-*)
echo "dodgy \$0: $0" >&2
exit 1 ;;
*/package)
mydir=`echo "$0" | sed 's,/package$,,'`
cd "$mydir" || exit
case ${PWD:-`pwd`} in
*/bin) ;;
*) echo "this script must live in bin/" >&2
exit 1 ;;
esac
case $mydir in
*/arch/*/*/bin)
cd .. ;;
*/arch/*/bin)
cd ../../.. ;;
*) cd .. ;;
esac || exit
unset mydir ;;
pwd=$0 ;;
package)
me=`command -v package` || me=`which package` || exit
mydir=`echo "$me" | sed 's,/package$,,'`
cd "$mydir" || exit
case ${PWD:-`pwd`} in
*/bin) ;;
*) echo "this script must live in bin/" >&2
exit 1 ;;
esac
case $mydir in
*/arch/*/*/bin)
cd .. ;;
*/arch/*/bin)
cd ../../.. ;;
*) cd .. ;;
esac || exit
unset me mydir ;;
pwd=`command -v package || which package` || exit ;;
*)
echo "this script must be named 'package'" >&2
exit 1 ;;
esac
pwd=`dirname "$pwd"`
cd "$pwd" || exit
case ${PWD:-`pwd`} in
*/arch/*/*/bin)
cd .. ;;
*/arch/*/bin)
cd ../../.. ;;
*/bin)
cd .. ;;
*)
echo "this script must live in bin/" >&2
exit 1 ;;
esac || exit
unset pwd
# shell checks
checksh()

View file

@ -29,49 +29,44 @@ case $PATH in
Bad*) echo "Cannot be run by zsh in native mode; use a sh symlink to zsh" >&2
exit 1 ;;
esac
unset path
unset CDPATH PWD
# Sanitize 'cd'
unset CDPATH
case `cd / && v=$PWD && cd /dev && v=$v,$PWD && echo "$v"` in
/,/dev) ;;
*) # old Bourne shell does not have $PWD; avoid inheriting it from
# the environment, which would kill our ${PWD:-`pwd`} fallback
unset PWD ;;
esac
# Make the package root the current working directory
case $0 in
-*)
echo "dodgy \$0: $0" >&2
exit 1 ;;
*/package)
mydir=`echo "$0" | sed 's,/package$,,'`
cd "$mydir" || exit
case ${PWD:-`pwd`} in
*/bin) ;;
*) echo "this script must live in bin/" >&2
exit 1 ;;
esac
case $mydir in
*/arch/*/*/bin)
cd .. ;;
*/arch/*/bin)
cd ../../.. ;;
*) cd .. ;;
esac || exit
unset mydir ;;
pwd=$0 ;;
package)
me=`command -v package` || me=`which package` || exit
mydir=`echo "$me" | sed 's,/package$,,'`
cd "$mydir" || exit
case ${PWD:-`pwd`} in
*/bin) ;;
*) echo "this script must live in bin/" >&2
exit 1 ;;
esac
case $mydir in
*/arch/*/*/bin)
cd .. ;;
*/arch/*/bin)
cd ../../.. ;;
*) cd .. ;;
esac || exit
unset me mydir ;;
pwd=`command -v package || which package` || exit ;;
*)
echo "this script must be named 'package'" >&2
exit 1 ;;
esac
pwd=`dirname "$pwd"`
cd "$pwd" || exit
case ${PWD:-`pwd`} in
*/arch/*/*/bin)
cd .. ;;
*/arch/*/bin)
cd ../../.. ;;
*/bin)
cd .. ;;
*)
echo "this script must live in bin/" >&2
exit 1 ;;
esac || exit
unset pwd
# shell checks
checksh()