Added a 'flags' arg to pnd_apps_exec
authorskeezix <skeezix@flotsam-vm.(none)>
Wed, 25 Feb 2009 18:06:49 +0000 (13:06 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Wed, 25 Feb 2009 18:06:49 +0000 (13:06 -0500)
Added option PND_EXEC_OPTION_BLOCK to require libpnd to hang until child process completes.

include/pnd_apps.h
lib/pnd_apps.c
test/discotest.c
testdata/pndsample/x86_echo.pnd
testdata/pndsample/x86_ls.pnd

index 10f07a4..117e9fe 100644 (file)
@@ -30,12 +30,22 @@ extern "C" {
  * (shell, bin, whatever.) pndrun specifies the full path to the pnd_run sh script, which should be
  * found using searchpaths and locates.. see locatetest.c for a sample
  * NOTE: Use pnd_locate function to locate the pnd_run, for example
- * NOTE: clock speed will be set prior to invoking the script, and set back on exit
+ * NOTE: if specified, 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.)
+ * Options is a set of boolean flags, derived from the #define's below; OR them together.
+ *   option-block, when set, suggests the launch should wait until the invoked application exits (disregarding why app exits)
+ *   example: options = PND_EXEC_OPTION_BLOCK | PND_EXEC_OPTION_2;
  */
-unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, char *rel_exec, char *rel_startdir, unsigned int clockspeed );
+#define PND_EXEC_OPTION_NIL        0
+#define PND_EXEC_OPTION_BLOCK      1
+#define PND_EXEC_OPTION_FUTURE     2
+#define PND_EXEC_OPTION_FUTURE2    4
+
+unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id,
+                             char *rel_exec, char *rel_startdir,
+                             unsigned int clockspeed, unsigned int options );
 
 #ifdef __cplusplus
 } /* "C" */
index cfa1d5b..8ed92f9 100644 (file)
@@ -4,15 +4,22 @@
 #include <string.h> /* for memset */
 #include <unistd.h> /* for fork/exec */
 
+#include <sys/types.h> /* for wait */
+#include <sys/wait.h> /* for wait */
+
 #include "pnd_container.h"
 #include "pnd_pxml.h"
 #include "pnd_apps.h"
 
-unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, char *rel_exec, char *rel_startdir, unsigned int clockspeed ) {
+unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id,
+                             char *rel_exec, char *rel_startdir,
+                             unsigned int clockspeed, unsigned int options )
+{
   char *argv [ 20 ];
   int f;
 
-  printf ( "Entering pnd_apps_exec\n" );
+  //printf ( "Entering pnd_apps_exec\n" );
+
 #if 0
   printf ( "  runscript: %s\n", pndrun );
   printf ( "  path: %s\n", fullpath );
@@ -59,7 +66,17 @@ unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, cha
     execv ( pndrun, argv );
   } 
 
-  printf ( "Exiting pnd_apps_exec\n" );
+  // by definition, either error occurred or we are the original application.
+
+  // do we wish to wait until the child process completes? (we don't
+  // care if it crashed, was killed, was suspended, whatever.)
+  if ( options & PND_EXEC_OPTION_BLOCK ) {
+    int status = 0;
+    //waitpid ( f, &status. 0 /* no options */ );
+    wait ( &status );
+  }
+
+  // printf ( "Exiting pnd_apps_exec\n" );
 
   return ( 1 );
 }
index 0d02104..5bc7030 100644 (file)
@@ -199,7 +199,7 @@ int main ( int argc, char *argv[] ) {
            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 ) );
+         pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, atoi ( d -> clockspeed ), PND_EXEC_OPTION_BLOCK );
        }
       }
 
index b645c49..671226e 100644 (file)
Binary files a/testdata/pndsample/x86_echo.pnd and b/testdata/pndsample/x86_echo.pnd differ
index 6e308e0..be0369d 100644 (file)
Binary files a/testdata/pndsample/x86_ls.pnd and b/testdata/pndsample/x86_ls.pnd differ