[
https://issues.apache.org/jira/browse/HADOOP-7089?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eli Collins updated HADOOP-7089:
--------------------------------
Issue Type: Bug (was: Improvement)
Yea, looks like readlink isn't going to work portably. I think Allen's
suggestion of using pwd -P is most portable, should work on Linux, BSD, OSX and
Solaris, and is much cleaner than the current code. I'll update the patch.
The motivation is that there's a bug in the manual symlink resolution code, it
fails when the script is called using a symlink from /, which is how Debian
runs init scripts.
{noformat}
/ $ ls -al /home/eli/test2
total 56
drwxr-xr-x 2 eli eli 4096 2011-01-07 10:07 .
drwxr-xr-x 136 eli eli 49152 2011-01-07 10:07 ..
lrwxrwxrwx 1 eli eli 17 2011-01-07 09:58 testl1.sh -> ../test1/test1.sh
lrwxrwxrwx 1 eli eli 17 2011-01-07 10:00 testl2.sh -> ../test1/test2.sh
/ $ cat /home/eli/test1/test1.sh
#!/bin/bash
set -e
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
bin=`dirname "$this"`
script=`basename "$this"`
bin=`cd "$bin"; pwd`
this="$bin/$script"
echo $this
{noformat}
Called w/o a symlink:
{noformat}
/ $ /home/eli/test1/test1.sh
/home/eli/test1/test1.sh
{noformat}
Called via a symlink:
{noformat}
/ $ /home/eli/test2/testl1.sh
/home/eli/test2/testl1.sh: line 15: cd: ../test1: No such file or directory
//test1.sh
{noformat}
Re-written to use pwd -P
{noformat}
/ $ cat /home/eli/test2/testl2.sh
#!/bin/bash
bin=$(cd -P -- "$(dirname -- "${BASH_SOURCE-$0}")" && pwd -P)
script="$(basename -- "${BASH_SOURCE-$0}")"
this="$bin/$script"
echo $this
{noformat}
Called via a symlink:
{noformat}
/ $ /home/eli/test2/testl2.sh
/home/eli/test2/testl2.sh
{noformat}
> Use readlink to get absolute paths in the scripts
> --------------------------------------------------
>
> Key: HADOOP-7089
> URL: https://issues.apache.org/jira/browse/HADOOP-7089
> Project: Hadoop Common
> Issue Type: Bug
> Components: scripts
> Reporter: Eli Collins
> Assignee: Eli Collins
> Priority: Minor
> Fix For: 0.22.0, 0.23.0
>
> Attachments: hadoop-7089-1.patch, hadoop-7089-1.patch
>
>
> The manual link resolution logic in bin/hadoop-config.sh can be replaced with
> readlink -m -n. Ditto with other uses of cd + pwd to get an absolute path,
> which can be fragile.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.