From de7d9a8a89970d8803a6824bd7d68bf7b1525379 Mon Sep 17 00:00:00 2001 From: Grazvydas Ignotas Date: Sun, 13 Sep 2015 19:41:17 +0300 Subject: [PATCH] pnd_run.sh: clean up paths after pnd exit Vars like PATH and LD_LIBRARY_PATH may cause tools used by pnd_run.sh to misbehave or not start at all (like with GINGE as it carries ancient GP2X libs), so make sure things from PND are not used. --- testdata/scripts/pnd_run.sh | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/testdata/scripts/pnd_run.sh b/testdata/scripts/pnd_run.sh index 06198aa..abf1b1e 100755 --- a/testdata/scripts/pnd_run.sh +++ b/testdata/scripts/pnd_run.sh @@ -100,6 +100,16 @@ PND_WaitFor() { PND_EndTask } +PND_WaitForExit() { + local l_sleep=1 + PID=$(pidof -o %PPID -x "$1") # get pid of app + while [ -n "$PID" ]; do + sleep $l_sleep + test $l_sleep -lt 10 && l_sleep=$(($l_sleep + 1)) + PID=$(pidof -o %PPID -x "$1") + done +} + PND_Exec() { local CMD="$*" { @@ -525,12 +535,18 @@ runApp() { cd "$STARTDIR"; # cd to folder specified by the optional arg -s fi + echo "$EXENAME" | grep -q "^\.\/" && DOTSLASH="true" + + # now set up the env for the PND, don't run any tools after this point + # because PATH and LD_LIBRARY_PATH may be different and incompatible + if [ -d "$UNION_MOUNT_DIR/$PND_NAME/lib" ];then export LD_LIBRARY_PATH="$UNION_MOUNT_DIR/$PND_NAME/lib:${LD_LIBRARY_PATH:-"/usr/lib:/lib"}" else export LD_LIBRARY_PATH="$UNION_MOUNT_DIR/$PND_NAME:${LD_LIBRARY_PATH:-"/usr/lib:/lib"}" fi + REAL_PATH="$PATH" if [ -d "$UNION_MOUNT_DIR/$PND_NAME/bin" ];then export PATH="$UNION_MOUNT_DIR/$PND_NAME/bin:${PATH:-"/usr/bin:/bin:/usr/local/bin"}" fi @@ -545,7 +561,7 @@ runApp() { export XDG_DATA_HOME="$HOME" export XDG_CACHE_HOME="$HOME" - if echo "$EXENAME"|grep -q ^\.\/;then + if [ "$DOTSLASH" = "true" ]; then "$EXENAME" $ARGUMENTS "$@" else "./$EXENAME" $ARGUMENTS "$@" @@ -553,12 +569,16 @@ runApp() { RC=$? #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits! - PID=$(pidof -o %PPID -x \"$EXENAME\") # get pid of app - while [ "$PID" ];do # wait till we get no pid back for tha app, again a bit ugly, but it works - sleep 10s - PID=`pidof -o %PPID -x \"$EXENAME\"` - done + LD_LIBRARY_PATH= PATH="$REAL_PATH" PND_WaitForExit "$EXENAME" + + # clean up to avoid any effects of the .pnd on the remaining parts of this script + unset LD_LIBRARY_PATH export HOME="$REAL_HOME" + unset REAL_HOME + export PATH="$REAL_PATH" + unset REAL_PATH + # ... the rest should not matter + return $RC } -- 2.39.2