From f2347b7a598de401fa7544e02b261c27e5dd858d Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Date: Wed, 2 Feb 2022 12:08:35 +0100 Subject: [PATCH] Use absolute path when invoking run-helper.sh or Runner.Listener (#1645) --- src/Misc/layoutroot/run-helper.sh.template | 10 +++++++++- src/Misc/layoutroot/run.sh | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Misc/layoutroot/run-helper.sh.template b/src/Misc/layoutroot/run-helper.sh.template index ef54bd516..7334ec981 100755 --- a/src/Misc/layoutroot/run-helper.sh.template +++ b/src/Misc/layoutroot/run-helper.sh.template @@ -26,7 +26,15 @@ safe_sleep() { fi } -bin/Runner.Listener run $* +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +"$DIR"/bin/Runner.Listener run $* + returnCode=$? if [[ $returnCode == 0 ]]; then echo "Runner listener exit with 0 return code, stop the service, no retry needed." diff --git a/src/Misc/layoutroot/run.sh b/src/Misc/layoutroot/run.sh index 580ab934f..f53bae5f0 100755 --- a/src/Misc/layoutroot/run.sh +++ b/src/Misc/layoutroot/run.sh @@ -9,7 +9,7 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" -cp -f run-helper.sh.template run-helper.sh +cp -f "$DIR"/run-helper.sh.template "$DIR"/run-helper.sh # run the helper process which keep the listener alive while :; do