pndnotifyd: fix some crashes
[pandora-libraries.git] / testdata / scripts / pnd_run.sh
index abf1b1e..0ea23e8 100755 (executable)
@@ -101,13 +101,9 @@ PND_WaitFor() {
 }
 
 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
+       # this used to wait for $1 ($EXENAME), but that doesn't work well
+       # when multiple PNDs run as too many PNDs have run.sh as $EXENAME
+       wait
 }
 
 PND_Exec() {
@@ -561,6 +557,12 @@ runApp() {
        export XDG_DATA_HOME="$HOME"
        export XDG_CACHE_HOME="$HOME"
 
+       if [ -e "${APPDATADIR}/PND_pre_script.sh" ]; then
+               echo "Starting user configured pre-script ${APPDATADIR}/PND_pre_script.sh"
+               . ${APPDATADIR}/PND_pre_script.sh # Sourcing so it can shared vars with post-script ;)
+               echo "${APPDATADIR}/PND_pre_script.sh is done"
+       fi
+
        if [ "$DOTSLASH" = "true" ]; then
                "$EXENAME" $ARGUMENTS "$@"
        else
@@ -571,6 +573,12 @@ runApp() {
        #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!
        LD_LIBRARY_PATH= PATH="$REAL_PATH" PND_WaitForExit "$EXENAME"
 
+       if [ -e "${APPDATADIR}/PND_post_script.sh" ]; then
+               echo "Starting user configured post-script ${APPDATADIR}/PND_post_script.sh"
+               . ${APPDATADIR}/PND_post_script.sh
+               echo "${APPDATADIR}/PND_post_script.sh is done"
+       fi
+
        # clean up to avoid any effects of the .pnd on the remaining parts of this script
        unset LD_LIBRARY_PATH
        export HOME="$REAL_HOME"
@@ -611,21 +619,11 @@ main() {
                fi
                oPWD=$(pwd)
                old_fb0_geometry=$(fbset -fb /dev/fb0 -s | grep geometry | awk '{print $2, $3, $4, $5, $6}')
-               if [ -e "${APPDATADIR}/PND_pre_script.sh" ]; then
-                       PND_BeginTask "Starting user configured pre-script"
-                       . ${APPDATADIR}/PND_pre_script.sh # Sourcing so it can shared vars with post-script ;)
-                       PND_EndTask
-               fi
 
                PND_BeginTask "Starting the application ( $EXENAME $ARGUMENTS "$@")"
                runApp "$@"
                PND_EndTask
 
-               if [ -e "${APPDATADIR}/PND_post_script.sh" ]; then
-                       PND_BeginTask "Starting user configured post-script"
-                       . ${APPDATADIR}/PND_post_script.sh
-                       PND_EndTask
-               fi
                cd $oPWD
                if [ $CLOSE_X ]; then
                        PND_BeginTask "Restarting X"