Split disco_t -> path_to_object into object_path and object_filename so it is more...
authorskeezix <skeezix@flotsam-vm.(none)>
Tue, 24 Feb 2009 03:58:45 +0000 (22:58 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Tue, 24 Feb 2009 03:58:45 +0000 (22:58 -0500)
updated pnd_run which now uses sudo (needs edit to /etc/sudoers to work), now works nicely even as non-root!

Makefile
include/pnd_apps.h
include/pnd_discovery.h
lib/pnd_apps.c
lib/pnd_discovery.c
test/discotest.c
testdata/pndsample/x86_echo.pnd
testdata/pndsample/x86_ls.pnd
testdata/scripts/pnd_run.sh

index e883136..1d8d689 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -25,7 +25,7 @@ ALLOBJ = pnd_conf.o pnd_container.o pnd_discovery.o pnd_pxml.o pnd_notify.o pnd_
 all: ${SOLIB} ${LIB} conftest discotest notifytest locatetest pndnotifyd
 
 clean:
-       ${RM} -f ${ALLOBJ} ${XMLOBJ} ${LIB} ${SOLIB1} locatetest.o bin/locatetest conftest.o bin/conftest discotest.o bin/discotest bin/notifytest notifytest.o bin/pndnotifyd pndnotifyd.o ${SOLIB} testdata/dotdesktop/*.desktop testdata/apps/*.pnd
+       ${RM} -f ${ALLOBJ} ${XMLOBJ} ${LIB} ${SOLIB1} locatetest.o bin/locatetest conftest.o bin/conftest discotest.o bin/discotest bin/notifytest notifytest.o bin/pndnotifyd pndnotifyd.o ${SOLIB} testdata/dotdesktop/*.desktop testdata/apps/*.pnd testdata/dotdesktop/*.png
        find . -name "*~*" -exec rm {} \; -print
 
 # component targets
index 3f2065a..ff2bb06 100644 (file)
@@ -33,6 +33,7 @@ extern "C" {
  * NOTE: clock speed will be set prior to invoking the script, and set back on exit
  * NOTE: No values can be except clockspeed; a 0 clockspeed means 'leave alone'. Set startdoir to "." instead of NULL.
  * fork() is implied; calling this function does not kill this process :)
+ * NOTE: PAss in the full path to the awesomeapp.pnd or to the directory containing PXML.xml (not the PXML.xml itself.)
  */
 unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, char *rel_exec, char *rel_startdir, unsigned int clockspeed );
 
index b92215e..4019e73 100644 (file)
@@ -44,7 +44,8 @@ typedef enum {
 typedef struct {
   // base
   unsigned char object_type;   // see enum above
-  char *path_to_object;        // full path to the PXML.xml or awesomeapp.pnd file
+  char *object_path;           // directory containing pnd or PXML.xml (does not include filename)
+  char *object_filename;       // filename within object_path of the app: the PXML.xml or awesomeapp.pnd file itself
   unsigned int pnd_icon_pos;   // offset to the byte after end of PXML in a pnd file (should be icon if present)
   // strdup'd from PXML
   char *title_en;
index 35b1565..cfa1d5b 100644 (file)
@@ -30,6 +30,8 @@ unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, cha
   argv [ f++ ] = fullpath;
   argv [ f++ ] = "-e";
   argv [ f++ ] = rel_exec;
+  argv [ f++ ] = "-s";
+  argv [ f++ ] = rel_startdir;
   // skip -a (arguments) for now
 
   //argv [ f++ ] = "-b";
index 3ddecb4..137b8bc 100644 (file)
@@ -1,6 +1,7 @@
 
 #include <stdio.h> /* for FILE etc */
 #include <stdlib.h> /* for malloc */
+#include <unistd.h> /* for unlink */
 
 #define __USE_GNU /* for strcasestr */
 #include <string.h> /* for making ftw.h happy */
@@ -151,10 +152,17 @@ static int pnd_disco_callback ( const char *fpath, const struct stat *sb,
 
       p = pnd_box_allocinsert ( disco_box, (char*) fpath, sizeof(pnd_disco_t) );
 
-      // base path
-      p -> path_to_object = strdup ( fpath );
-      if ( ( fixpxml = strcasestr ( p -> path_to_object, PXML_FILENAME ) ) ) {
+      // base paths
+      p -> object_path = strdup ( fpath );
+
+      if ( ( fixpxml = strcasestr ( p -> object_path, PXML_FILENAME ) ) ) {
        *fixpxml = '\0'; // if this is not a .pnd, lop off the PXML.xml at the end
+      } else if ( ( fixpxml = strrchr ( p -> object_path, '/' ) ) ) {
+       *(fixpxml+1) = '\0'; // for pnd, lop off to last /
+      }
+
+      if ( ( fixpxml = strrchr ( fpath, '/' ) ) ) {
+       p -> object_filename = strdup ( fixpxml + 1 );
       }
 
       // png icon path
@@ -292,7 +300,11 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
 #endif
 
   if ( p -> exec ) {
-    snprintf ( buffer, 1020, "Exec=%s -p %s -e %s -u\n", pndrun, p -> path_to_object, p -> exec );
+    if ( p -> object_type == pnd_object_type_directory ) {
+      snprintf ( buffer, 1020, "Exec=%s -p %s -e %s -u\n", pndrun, p -> object_path, p -> exec );
+    } else if ( p -> object_type == pnd_object_type_pnd ) {
+      snprintf ( buffer, 1020, "Exec=%s -p %s/%s -e %s -u\n", pndrun, p -> object_path, p -> object_filename, p -> exec );
+    }
     fprintf ( f, "%s", buffer );
   }
 
@@ -304,12 +316,21 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
 }
 
 unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
-  char buffer [ FILENAME_MAX ];
+  char buffer [ FILENAME_MAX ]; // target filename
+  char from [ FILENAME_MAX ];   // source filename
   char bits [ 8 * 1024 ];
   unsigned int bitlen;
+  FILE *pnd, *target;
+
+  // prelim
+  if ( ( p -> object_type == pnd_object_type_pnd ) &&
+       ( ! p -> pnd_icon_pos ) )
+  {
+    return ( 0 ); // discover code didn't find it, so FAIL
+  }
 
-  // filename
-  sprintf ( buffer, "%s/%u.png", targetpath, p -> unique_id );
+  // filenames
+  sprintf ( buffer, "%s/%s.png", targetpath, p -> unique_id ); // target
 
   // first.. are we looking through a pnd file or a dir?
   if ( p -> object_type == pnd_object_type_directory ) {
@@ -318,14 +339,11 @@ unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
   } else if ( p -> object_type == pnd_object_type_pnd ) {
     // if we can get it from pnd file, copy it into destination
 
-    if ( ! p -> pnd_icon_pos ) {
-      return ( 0 ); // discover code didn't find it, so FAIL
-    }
-
-    FILE *pnd, *target;
     unsigned int len;
 
-    pnd = fopen ( p -> path_to_object, "r" );
+    sprintf ( from, "%s/%s", p -> object_path, p -> object_filename ); // target
+
+    pnd = fopen ( from, "r" );
 
     if ( ! pnd ) {
       return ( 0 );
index b374f36..6254539 100644 (file)
@@ -32,8 +32,8 @@ int main ( int argc, char *argv[] ) {
     } else {
       printf ( "%s [-e] [-i] [-d]\n", argv [ 0 ] );
       printf ( "-e\tOptional. Attempt to exec a random app.\n" );
-      printf ( "-i\tOptional. Attempt to dump icon files from the end of pnd's to /tmp.\n" );
-      printf ( "-d\tOptional. Attempt to dump dotdesktop files from the end of pnd's to /tmp.\n" );
+      printf ( "-i\tOptional. Attempt to dump icon files from the end of pnd's to ./testdata/dotdesktop.\n" );
+      printf ( "-d\tOptional. Attempt to dump dotdesktop files from the end of pnd's to ./testdata/dotdesktop.\n" );
       exit ( 0 );
     }
 
@@ -119,7 +119,7 @@ int main ( int argc, char *argv[] ) {
 
       printf ( "App: %s (type %u)\n", pnd_box_get_key ( d ), d -> object_type );
 
-      printf ( "  Base path: %s\n", d -> path_to_object );
+      printf ( "  Base path: %s filename: %s\n", d -> object_path, d -> object_filename );
 
       if ( d -> title_en ) {
        printf ( "  Name: %s\n", d -> title_en );
@@ -147,11 +147,11 @@ int main ( int argc, char *argv[] ) {
       }
 
       if ( do_dotdesktop ) {
-       pnd_emit_dotdesktop ( "/tmp", pndrun, d );
+       pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d );
       }
 
       if ( do_icon ) {
-       pnd_emit_icon ( "/tmp", d );
+       pnd_emit_icon ( "./testdata/dotdesktop", d );
       }
 
       // next!
@@ -176,7 +176,14 @@ int main ( int argc, char *argv[] ) {
        d = pnd_box_get_next ( d );
 
        if ( d ) {
-         pnd_apps_exec ( pndrun, d -> path_to_object, d -> unique_id, d -> exec, d -> startdir, atoi ( d -> clockspeed ) );
+         char fullpath [ FILENAME_MAX ];
+         if ( d -> object_type == pnd_object_type_directory ) {
+           sprintf ( fullpath, "%s", d -> object_path );
+         } else if ( d -> object_type == pnd_object_type_pnd ) {
+           sprintf ( fullpath, "%s/%s", d -> object_path, d -> object_filename );
+         }
+         printf ( "Trying to exec '%s'\n", fullpath );
+         pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, atoi ( d -> clockspeed ) );
        }
       }
 
index 00d9ead..255db68 100644 (file)
Binary files a/testdata/pndsample/x86_echo.pnd and b/testdata/pndsample/x86_echo.pnd differ
index 9e36a1d..4dfaf7d 100644 (file)
Binary files a/testdata/pndsample/x86_ls.pnd and b/testdata/pndsample/x86_ls.pnd differ
index b26ccf2..de8760c 100755 (executable)
@@ -5,10 +5,9 @@
 # -s startdir
 # arguments can be inside -e, -a is optional
  
-############################# dont forget to remove the echos! ############################
  
 # parse arguments
-TEMP=`getopt -o p:e:a:b:u::s: --long p-long,e-long:,a-long: -- "$@"`
+TEMP=`getopt -o p:e:a:b:s:u:: --long p-long,e-long:,a-long: -- "$@"`
  
 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  
@@ -47,13 +46,13 @@ oCWD=$(pwd)
  
 #detect fs
 if [ $DFS = ISO ]; then
-        mntline="mount -o loop,fmask=000 $PND /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"
         echo "Filetype is $DFS"
 elif [ $DFS = directory ]; then
-        mntline="mount --bind -o ro,fmask=000 $PND /mnt/pnd/$BASENAME"
+        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
@@ -63,47 +62,47 @@ fi
  
 #create mountpoints
  
-if [ ! -d /mnt/pnd/$BASENAME ]; then echo "mkdir -p /mnt/pnd/$BASENAME "; fi
-if [ ! -d $MOUNTPOINT/appdata/$BASENAME ]; then echo "mkdir -p $MOUNTPOINT/appdata/$BASENAME "; fi
-if [ ! -d /mnt/utmp/$BASENAME ]; then echo "mkdir -p /mnt/utmp/$BASENAME "; fi 
+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 [ ! $UNION ] ; then
         #is the union already mounted? if not mount evrything, else launch the stuff
-        mount | grep "on /mnt/utmp/$BASENAME type" > /dev/null
+        mount | grep "on /mnt/utmp/$BASENAME type" > /dev/null
         if [ ! $? -eq 0 ]; then 
+                echo "mounting union!"
                 $mntline #mount the pnd/folder
-                #mount -t unionfs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro unionfs /mnt/utmp/$BASENAME #union mount
-                #aufs, one of those should work, bit unsure.
-                mount -t aufs -o exec,fmask=000,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro none /mnt/utmp/$BASENAME #aufs?
-                #mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro aufs /mnt/utmp/$BASENAME #aufs?
+                sudo mount -t aufs -o exec,dirs\=$MOUNTPOINT/appdata/$BASENAME=rw:/mnt/pnd/$BASENAME=ro none /mnt/utmp/$BASENAME # put union on top
  
         else
-                echo "doh!"
+                echo "Union already mounted"
         fi
  
  
         #start app
         cd /mnt/utmp/$BASENAME
         if [ $STARTDIR ]; then cd $STARTDIR; fi
-        $EXENAME $ARGUMENTS 
+        ./$EXENAME $ARGUMENTS 
         #app exited
+        cd $oCWD
  
 else
  
         $mntline
         cd /mnt/pnd/$BASENAME
         if [ $STARTDIR ]; then cd $STARTDIR; fi
-        $EXENAME $ARGUMENTS 
+        echo $(pwd)
+        ./$EXENAME $ARGUMENTS 
+        cd $oCWD
 fi
  
 #clean up
-umount /mnt/utmp/$BASENAME
+if [ ! $UNION ] ; then sudo umount /mnt/utmp/$BASENAME; fi
+if [ $UNION ] ; then sudo umount /mnt/pnd/$BASENAME; fi
 if [ $? -eq 0 ]; then 
-        umount /mnt/pnd/$BASENAME
-        rmdir /mnt/pnd/$BASENAME
-        rmdir /mnt/utmp/$BASENAME
+        sudo umount /mnt/pnd/$BASENAME
+        sudo rmdir /mnt/pnd/$BASENAME
+        if [ ! $UNION ] ; then  sudo rmdir /mnt/utmp/$BASENAME; fi
 fi