Bringing in patches from cpasjuste
authorskeezix <skeezix@flotsam-vm.(none)>
Fri, 9 Oct 2009 18:49:04 +0000 (14:49 -0400)
committerskeezix <skeezix@flotsam-vm.(none)>
Fri, 9 Oct 2009 18:49:04 +0000 (14:49 -0400)
lib/pnd_notify.c
lib/pnd_pndfiles.c
lib/pnd_tinyxml.cpp
testdata/scripts/pnd_run.sh

index c9d16fd..a5b8c44 100644 (file)
@@ -102,6 +102,7 @@ void pnd_notify_watch_path ( pnd_notify_handle h, char *fullpath, unsigned int f
 static void pnd_notify_hookup ( int fd ) {
 
   inotify_add_watch ( fd, "./testdata", IN_CREATE | IN_DELETE | IN_UNMOUNT );
+  inotify_add_watch ( fd, "/media", IN_CREATE | IN_DELETE | IN_UNMOUNT );
 
   return;
 }
index 3e3f833..b18f23f 100644 (file)
@@ -3,6 +3,8 @@
 #include <stdlib.h> /* for malloc */
 #include <ctype.h> /* for isprint */
 #include <unistd.h> /* for fork/exec */
+#include <sys/types.h> /* for wait */
+#include <sys/wait.h> /* for wait */
 
 #define __USE_GNU
 #include <string.h> /* for making strcasestr happy */
@@ -194,6 +196,10 @@ static unsigned char pnd_pnd_mountie ( char *pndrun, char *fullpath, char *uniqu
     execv ( pndrun, argv );
   } 
 
+  // wait until mountscript actually completes
+  int status = 0;
+  wait ( &status );
+
   return ( 1 );
 }
 
index bb3a7a3..5e53ab9 100644 (file)
@@ -34,6 +34,8 @@ unsigned char pnd_pxml_load ( const char* pFilename, pnd_pxml_t *app ) {
 
   fread ( b, 1, len, f );
 
+  fclose ( f );
+
   return ( pnd_pxml_parse ( pFilename, b, len, app ) );
 }
 
index 3e46858..c78d3a9 100755 (executable)
-#!/bin/bash\r
- #needs some serious cleanup!\r
\r
-#Usage: pnd_run.sh -p your.pnd -e executeable [-a "(arguments)"] [ -s "cd to folder inside pnd"] [-u (skip union)] [-b override BASENAME (name of mountpoint/appdata)] [-x close x before launching(script needs to be started with nohup for this to work]\r
-# -n to skip union mount, should probably be removed before release\r
-# -s startdir\r
-# arguments can be inside -e, -a is optional\r
\r
-#/etc/sudoers needs to be adjusted if you touch any of the sudo lines in the wrong place.\r
\r
-# look at the comments in the nox part, adjust \r
\r
-#use "lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq > whitelist" with nothing running to generate the whitelist\r
\r
-#launch the script with nohup for -x to work!\r
\r
-#todo\r
-#make sure to only use free loop devices!\r
-#cleanup\r
\r
-# parse arguments\r
-TEMP=`getopt -o p:e:a:b:s:m::u::n::x:: -- "$@"`\r
\r
-if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi\r
\r
-# Note the quotes around `$TEMP': they are essential!\r
-eval set -- "$TEMP"\r
\r
-while true ; do\r
-       case "$1" in\r
-               -p) echo "pnd set to \`$2'" ;PND=$2;shift 2;;\r
-               -e) echo "exec set to \`$2'" ;EXENAME=$2;shift 2 ;;\r
-               -n) echo "n set, no union pls!";NOUNION=1;shift 2;;\r
-               -b) echo "BASENAME set to $2";BASENAME=$2;shift 2;;\r
-               -s) echo "startdir set to $2";STARTDIR=$2;shift 2;;\r
-               -m) echo "mount";mount=1;shift 2;;\r
-               -u) echo "umount";umount=1;shift 2;;\r
-               -x) echo "no x";nox=1;shift 2;;\r
-               -a) \r
-                       case "$2" in\r
-                               "") echo "no arguments"; shift 2 ;;\r
-                               *)  echo "args set to \`$2'" ;ARGUMENTS=$2;shift 2 ;;\r
-                       esac ;;\r
-               --) shift ; break ;;\r
-               *) echo "Error while parsing arguments!" ; exit 1 ;;\r
-       esac\r
-done\r
\r
-if [ ! $PND ] || [ ! $EXENAME ]; then\r
-       echo "Usage: pnd_run.sh -p your.pnd -e executeable [-a \"(arguments)\"] [ -s \"cd to folder inside pnd\"] [-u (skip union)] [-b override BASENAME (name of mountpoint/appdata)] [-x close x before launching(script needs to be started with nohup for this to work]"\r
-       exit 1\r
-fi\r
-if [ $nox ]; then\r
-       applist=$(lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq)\r
-       whitelist=$(cat ~/pndtest/whitelist) #adjust this to a fixed whitelist, maybe in the config dir\r
-       filteredlist=$(echo -e "$applist\n\n$whitelist\n\n$whitelist" | sort | uniq -u) #whitelist appended two times so those items are always removed\r
-       if [ ${#filteredlist} -ge 1 ]; then\r
-               message=$(echo -e "The following applications are still running, are you sure you want to close x? \n$filteredlist")\r
-               echo -e \93ae[34me[30m\94\r
-               xmessage -center "$message", -buttons yes,no\r
-               if [ $? = 102 ]; then\r
-               exit 1\r
-               fi\r
-               sudo /etc/init.d/gdm stop\r
-               sleep 5s\r
-       else\r
-               echo -e \93ae[34me[30m\94\r
-               xmessage -center "killing x, nothing of value will be lost", -buttons ok,cancel\r
-               if [ $? = 102 ]; then\r
-               exit 1\r
-               fi\r
-               # close x now, do we want to use gdm stop or just kill x?\r
-               sudo /etc/init.d/gdm stop\r
-               sleep 5s\r
-       fi\r
-fi\r
\r
-#vars\r
-DFS=$(file -b $PND | awk '{ print $1 }') #is -p a zip/iso or folder?\r
-MOUNTPOINT=$(df $PND | sed -ne 's/.*\% \(\S*\)/\1/p' | tail -n1)\r
-echo "mountpoint: $MOUNTPOINT"\r
-#MOUNTPOINT=$(df -h $PND | grep -E '[1-9]%' | awk '{ print $6  }') #find out which mountpoint the pnd/folder is on, there probably is a better way to do this\r
\r
\r
-#BASENAME really should be something sensible and somewhat unique\r
-#if -b is set use that as basename, else generate it from PND\r
-#get basename (strip extension if file) for union mountpoints etc, maybe  this should be changed to something specified inside the xml\r
-#this should probably be changed to .... something more sensible\r
-if [ ! $BASENAME ]; then BASENAME=$(basename "$PND" | cut -d'.' -f1) ; fi\r
\r
\r
\r
-oCWD=$(pwd)\r
\r
-#detect fs\r
-if [ $DFS = ISO ]; then\r
\r
-       usedminor=$( ls -l /dev/loop* | awk '{print $6}')\r
-       freeminor=$( echo -e "$(seq 0 64)\n$usedminor" | sort -rn | uniq -u | tail -n1)\r
-       sudo mknod -m777 /dev/loop$freeminor b 7 $freeminor\r
-       sudo losetup /dev/loop$freeminor $PND\r
\r
-       mntline="sudo mount /dev/loop$freeminor /mnt/pnd/$BASENAME/"\r
-#      mntline="sudo mount -o loop,mode=777 $PND /mnt/pnd/$BASENAME"\r
-       echo "Filetype is $DFS"\r
-elif [ $DFS = Zip ]; then\r
-       mntline="fuse-zip $PND /mnt/pnd/$BASENAME -o ro,fmask=000" #TOTALLY untested right now\r
-       echo "Filetype is $DFS"\r
-elif [ $DFS = directory ]; then\r
-       mntline="sudo mount --bind -o ro $PND /mnt/pnd/$BASENAME"\r
-#we bind the folder, now it can be treated in a unified way ATENTION: -o ro doesnt work for --bind at least on 25, on 26 its possible using remount, may have changed on 27\r
-       echo "Filetype is $DFS"\r
-else\r
-       echo "error"\r
-       exit 1;\r
-fi\r
\r
-#create mountpoints, check if they exist already first to avoid annoying error messages\r
-if [ ! -d /mnt/pnd/$BASENAME ]; then sudo mkdir -p /mnt/pnd/$BASENAME ; fi\r
-if [ ! -d $MOUNTPOINT/appdata/$BASENAME ]; then sudo mkdir -p $MOUNTPOINT/appdata/$BASENAME; fi\r
-if [ ! -d /mnt/utmp/$BASENAME ]; then sudo mkdir -p /mnt/utmp/$BASENAME; fi \r
\r
-#mount\r
\r
-if [ ! $NOUNION ] && [ ! $umount ]; then\r
-       #is the union already mounted? if not mount evrything, else launch the stuff\r
-       mount | grep "on /mnt/utmp/$BASENAME type" # > /dev/null\r
-       if [ ! $? -eq 0 ]; then \r
-               echo "$mntline"\r
-               $mntline #mount the pnd/folder\r
-               echo "mounting union!"\r
-               sudo mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw+nolwh:/mnt/pnd/$BASENAME=rr none /mnt/utmp/$BASENAME # put union on top\r
\r
-       else\r
-               echo "Union already mounted"\r
-       fi\r
\r
-       if [ $mount ]; then echo "mounted /mnt/utmp/$BASENAME"; exit 1; fi;\r
\r
-       #start app\r
-       cd /mnt/utmp/$BASENAME\r
-       if [ $STARTDIR ]; then cd $STARTDIR; fi #cd to folder specified by the optional arg -s\r
-       #echo "/lib/ld-linux.so.2 --library-path /mnt/utmp/$BASENAME/ $EXENAME $ARGUMENTS"\r
-       #/lib/ld-linux.so.2 --library-path /mnt/utmp/$BASENAME/ $EXENAME $ARGUMENTS\r
-       LD_LIBRARY_PATH=/mnt/utmp/$BASENAME ./$EXENAME $ARGUMENTS\r
-       #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!\r
-       PID=`pidof -o %PPID -x $EXENAME`\r
-       while [ "$PID" ]\r
-       do\r
-       sleep 10s\r
-       PID=`pidof -o %PPID -x $EXENAME`\r
-       done\r
-       echo end\r
\r
-       #app exited\r
-       cd $oCWD #cd out of the mountpoint so we can umount, doesnt really matter to where...\r
\r
-elif [ ! $umount ]; then\r
-       $mntline\r
-       if [ $mount ]; then echo "mounted /mnt/pnd/$BASENAME"; exit 1; fi;\r
-       cd /mnt/pnd/$BASENAME\r
-       if [ $STARTDIR ]; then cd $STARTDIR; fi\r
-       echo $(pwd)\r
-       #/lib/ld-linux.so.2 --library-path /mnt/pnd/$BASENAME/ $EXENAME $ARGUMENTS      \r
-       ./$EXENAME $ARGUMENTS \r
-       LD_LIBRARY_PATH=/mnt/pnd/$BASENAME ./$EXENAME $ARGUMENTS\r
-       #the app could have exited now, OR it went into bg, we still need to wait in that case till it really quits!\r
-       PID=`pidof -o %PPID -x $EXENAME`\r
-       while [ $PID ]\r
-       do\r
-       sleep 10s\r
-       PID=`pidof -o %PPID -x $EXENAME`\r
-       done\r
-       echo end\r
\r
-       cd $oCWD\r
-else\r
-echo "-u set, nothing to do here"\r
-fi\r
\r
\r
-#clean up\r
-if [ ! $NOUNION ] ; then sudo umount /mnt/utmp/$BASENAME; fi #umount union if -u wasnt set\r
-if [ $NOUNION ] ; then sudo umount /mnt/pnd/$BASENAME; fi #umount iso if -u WAS set\r
-if [ $? -eq 0 ]; then # check if the umount was successfull, if it wasnt it would mean that theres still something running so we skip this stuff, this WILL lead to clutter if it happens, so we should make damn sure it never happens\r
-       if [ ! $NOUNION ] ; then\r
-               sudo umount /mnt/pnd/$BASENAME\r
-               sudo rmdir $MOUNTPOINT/appdata/$BASENAME/.wh..wh.plink \r
-               sudo rmdir $MOUNTPOINT/appdata/$BASENAME/\r
-               sudo rmdir /mnt/utmp/$BASENAME;\r
-       fi\r
-       if [ $DFS = ISO ]; then\r
-               sudo losetup -d /dev/loop$freeminor\r
-               sudo rm /dev/loop$freeminor\r
-       fi\r
-       sudo rmdir /mnt/pnd/$BASENAME \r
-fi\r
-if [ $nox ]; then\r
-echo "starting x in 5s"\r
-sleep 5\r
-sudo /etc/init.d/gdm start\r
-fi\r
-\r
+#!/bin/bash
+ #needs some serious cleanup!
+#Usage: pnd_run.sh -p your.pnd -e executeable [-a "(arguments)"] [ -s "cd to folder inside pnd"] [-u (skip union)] [-b override BASENAME (name of mountpoint/appdata)] [-x close x before launching(script needs to be started with nohup for this to work]
+# -n to skip union mount, should probably be removed before release
+# -s startdir
+# arguments can be inside -e, -a is optional
+#/etc/sudoers needs to be adjusted if you touch any of the sudo lines in the wrong place.
+# look at the comments in the nox part, adjust 
+#use "lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq > whitelist" with nothing running to generate the whitelist
+#launch the script with nohup for -x to work!
+#todo
+#make sure to only use free loop devices!
+#cleanup
+# parse arguments
+TEMP=`getopt -o p:e:a:b:s:m::u::n::x:: -- "$@"`
+if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
+# Note the quotes around `$TEMP': they are essential!
+eval set -- "$TEMP"
+while true ; do
+       case "$1" in
+               -p) echo "pnd set to \`$2'" ;PND=$2;shift 2;;
+               -e) echo "exec set to \`$2'" ;EXENAME=$2;shift 2 ;;
+               -n) echo "n set, no union pls!";NOUNION=1;shift 2;;
+               -b) echo "BASENAME set to $2";BASENAME=$2;shift 2;;
+               -s) echo "startdir set to $2";STARTDIR=$2;shift 2;;
+               -m) echo "mount";mount=1;shift 2;;
+               -u) echo "umount";umount=1;shift 2;;
+               -x) echo "no x";nox=1;shift 2;;
+               -a) 
+                       case "$2" in
+                               "") echo "no arguments"; shift 2 ;;
+                               *)  echo "args set to \`$2'" ;ARGUMENTS=$2;shift 2 ;;
+                       esac ;;
+               --) shift ; break ;;
+               *) echo "Error while parsing arguments!" ; exit 1 ;;
+       esac
+done
+if [ ! $PND ]; then
+       echo "Usage: pnd_run.sh -p your.pnd -e executeable [-a \"(arguments)\"] [ -s \"cd to folder inside pnd\"] [-u (skip union)] [-b override BASENAME (name of mountpoint/appdata)] [-x close x before launching(script needs to be started with nohup for this to work]"
+       exit 1
+fi
+if [ $nox ]; then
+       applist=$(lsof /usr/lib/libX11.so.6 | awk '{print $1}'| sort | uniq)
+       whitelist=$(cat ~/pndtest/whitelist) #adjust this to a fixed whitelist, maybe in the config dir
+       filteredlist=$(echo -e "$applist\n\n$whitelist\n\n$whitelist" | sort | uniq -u) #whitelist appended two times so those items are always removed
+       if [ ${#filteredlist} -ge 1 ]; then
+               message=$(echo -e "The following applications are still running, are you sure you want to close x? \n$filteredlist")
+               echo -e “ae[34me[30m”
+               xmessage -center "$message", -buttons yes,no
+               if [ $? = 102 ]; then
+               exit 1
+               fi
+               sudo /etc/init.d/gdm stop
+               sleep 5s
+       else
+               echo -e “ae[34me[30m”
+               xmessage -center "killing x, nothing of value will be lost", -buttons ok,cancel
+               if [ $? = 102 ]; then
+               exit 1
+               fi
+               # close x now, do we want to use gdm stop or just kill x?
+               sudo /etc/init.d/gdm stop
+               sleep 5s
+       fi
+fi
+#vars
+DFS=$(file -b $PND | awk '{ print $1 }') #is -p a zip/iso or folder?
+MOUNTPOINT=$(df $PND | sed -ne 's/.*\% \(\S*\)/\1/p' | tail -n1)
+echo "mountpoint: $MOUNTPOINT"
+#MOUNTPOINT=$(df -h $PND | grep -E '[1-9]%' | awk '{ print $6  }') #find out which mountpoint the pnd/folder is on, there probably is a better way to do this
+#BASENAME really should be something sensible and somewhat unique
+#if -b is set use that as basename, else generate it from PND
+#get basename (strip extension if file) for union mountpoints etc, maybe  this should be changed to something specified inside the xml
+#this should probably be changed to .... something more sensible
+if [ ! $BASENAME ]; then BASENAME=$(basename "$PND" | cut -d'.' -f1) ; fi
+oCWD=$(pwd)
+#detect fs
+if [ $DFS = ISO ]; then
+       usedminor=$( ls -l /dev/loop* | awk '{print $6}')
+       freeminor=$( echo -e "$(seq 0 64)\n$usedminor" | sort -rn | uniq -u | tail -n1)
+       sudo mknod -m777 /dev/loop$freeminor b 7 $freeminor
+       sudo losetup /dev/loop$freeminor $PND
+       mntline="sudo mount /dev/loop$freeminor /mnt/pnd/$BASENAME/"
+#      mntline="sudo mount -o loop,mode=777 $PND /mnt/pnd/$BASENAME"
+       echo "Filetype is $DFS"
+elif [ $DFS = Zip ]; then
+       mntline="fuse-zip $PND /mnt/pnd/$BASENAME -o ro,fmask=000" #TOTALLY untested right now
+       echo "Filetype is $DFS"
+elif [ $DFS = directory ]; then
+       mntline="sudo mount --bind -o ro $PND /mnt/pnd/$BASENAME"
+#we bind the folder, now it can be treated in a unified way ATENTION: -o ro doesnt work for --bind at least on 25, on 26 its possible using remount, may have changed on 27
+       echo "Filetype is $DFS"
+else
+       echo "error"
+       exit 1;
+fi
+#create mountpoints, check if they exist already first to avoid annoying error messages
+if [ ! -d /mnt/pnd/$BASENAME ]; then sudo mkdir -p /mnt/pnd/$BASENAME ; fi
+if [ ! -d $MOUNTPOINT/appdata/$BASENAME ]; then sudo mkdir -p $MOUNTPOINT/appdata/$BASENAME; fi
+if [ ! -d /mnt/utmp/$BASENAME ]; then sudo mkdir -p /mnt/utmp/$BASENAME; fi 
+#mount
+if [ ! $NOUNION ] && [ ! $umount ]; then
+       #is the union already mounted? if not mount evrything, else launch the stuff
+       mount | grep "on /mnt/utmp/$BASENAME type" # > /dev/null
+       if [ ! $? -eq 0 ]; then 
+               echo "$mntline"
+               $mntline #mount the pnd/folder
+               echo "mounting union!"
+               sudo mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw+nolwh:/mnt/pnd/$BASENAME=rr none /mnt/utmp/$BASENAME # put union on top
+       else
+               echo "Union already mounted"
+       fi
+       if [ $mount ]; then echo "mounted /mnt/utmp/$BASENAME"; exit 1; fi;
+       #start app
+       cd /mnt/utmp/$BASENAME
+       if [ $STARTDIR ]; then cd $STARTDIR; fi #cd to folder specified by the optional arg -s
+       #echo "/lib/ld-linux.so.2 --library-path /mnt/utmp/$BASENAME/ $EXENAME $ARGUMENTS"
+       #/lib/ld-linux.so.2 --library-path /mnt/utmp/$BASENAME/ $EXENAME $ARGUMENTS
+       LD_LIBRARY_PATH=/mnt/utmp/$BASENAME ./$EXENAME $ARGUMENTS
+       #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`
+       while [ "$PID" ]
+       do
+       sleep 10s
+       PID=`pidof -o %PPID -x $EXENAME`
+       done
+       echo end
+       #app exited
+       cd $oCWD #cd out of the mountpoint so we can umount, doesnt really matter to where...
+elif [ ! $umount ]; then
+       $mntline
+       if [ $mount ]; then echo "mounted /mnt/pnd/$BASENAME"; exit 1; fi;
+       cd /mnt/pnd/$BASENAME
+       if [ $STARTDIR ]; then cd $STARTDIR; fi
+       echo $(pwd)
+       #/lib/ld-linux.so.2 --library-path /mnt/pnd/$BASENAME/ $EXENAME $ARGUMENTS      
+       ./$EXENAME $ARGUMENTS 
+       LD_LIBRARY_PATH=/mnt/pnd/$BASENAME ./$EXENAME $ARGUMENTS
+       #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`
+       while [ $PID ]
+       do
+       sleep 10s
+       PID=`pidof -o %PPID -x $EXENAME`
+       done
+       echo end
+       cd $oCWD
+else
+echo "-u set, nothing to do here"
+fi
+#clean up
+if [ ! $NOUNION ] ; then sudo umount /mnt/utmp/$BASENAME; fi #umount union if -u wasnt set
+if [ $NOUNION ] ; then sudo umount /mnt/pnd/$BASENAME; fi #umount iso if -u WAS set
+if [ $? -eq 0 ]; then # check if the umount was successfull, if it wasnt it would mean that theres still something running so we skip this stuff, this WILL lead to clutter if it happens, so we should make damn sure it never happens
+       if [ ! $NOUNION ] ; then
+               sudo umount /mnt/pnd/$BASENAME
+               sudo rmdir $MOUNTPOINT/appdata/$BASENAME/.wh..wh.plink 
+               sudo rmdir $MOUNTPOINT/appdata/$BASENAME/
+               sudo rmdir /mnt/utmp/$BASENAME;
+       fi
+       if [ $DFS = ISO ]; then
+               sudo losetup -d /dev/loop$freeminor
+               sudo rm /dev/loop$freeminor
+       fi
+       sudo rmdir /mnt/pnd/$BASENAME 
+fi
+if [ $nox ]; then
+echo "starting x in 5s"
+sleep 5
+sudo /etc/init.d/gdm start
+fi
+
+