diff --git a/CHANGES.txt b/CHANGES.txt index 7b86fd5c30..c714a58da0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -443,6 +443,8 @@ Release 0.22.0 - Unreleased HADOOP-7101. UserGroupInformation.getCurrentUser() fails when called from non-Hadoop JAAS context. (todd) + HADOOP-7089. Fix link resolution logic in hadoop-config.sh. (eli) + Release 0.21.1 - Unreleased IMPROVEMENTS diff --git a/bin/hadoop-config.sh b/bin/hadoop-config.sh index 4da14f8090..025dbc0a29 100644 --- a/bin/hadoop-config.sh +++ b/bin/hadoop-config.sh @@ -17,23 +17,12 @@ # should not be executable directly # also should not be passed any arguments, since we need original $* -# resolve links - $0 may be a softlink - +# Resolve links ($0 may be a softlink) and convert a relative path +# to an absolute path. NB: The -P option requires bash built-ins +# or POSIX:2001 compliant cd and pwd. this="${BASH_SOURCE-$0}" -while [ -h "$this" ]; do - ls=`ls -ld "$this"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '.*/.*' > /dev/null; then - this="$link" - else - this=`dirname "$this"`/"$link" - fi -done - -# convert relative path to absolute path -common_bin=`dirname "$this"` -script=`basename "$this"` -common_bin=`cd "$common_bin"; pwd` +common_bin=$(cd -P -- "$(dirname -- "$this")" && pwd -P) +script="$(basename -- "$this")" this="$common_bin/$script" # the root of the Hadoop installation