From: skeezix Date: Wed, 25 Feb 2009 18:06:49 +0000 (-0500) Subject: Added a 'flags' arg to pnd_apps_exec X-Git-Tag: Release-2010-05/1~199 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e42b2f587e27c662c73731b1da99d86142cdbda9;p=pandora-libraries.git Added a 'flags' arg to pnd_apps_exec Added option PND_EXEC_OPTION_BLOCK to require libpnd to hang until child process completes. --- diff --git a/include/pnd_apps.h b/include/pnd_apps.h index 10f07a4..117e9fe 100644 --- a/include/pnd_apps.h +++ b/include/pnd_apps.h @@ -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" */ diff --git a/lib/pnd_apps.c b/lib/pnd_apps.c index cfa1d5b..8ed92f9 100644 --- a/lib/pnd_apps.c +++ b/lib/pnd_apps.c @@ -4,15 +4,22 @@ #include /* for memset */ #include /* for fork/exec */ +#include /* for wait */ +#include /* 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 ); } diff --git a/test/discotest.c b/test/discotest.c index 0d02104..5bc7030 100644 --- a/test/discotest.c +++ b/test/discotest.c @@ -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 ); } } diff --git a/testdata/pndsample/x86_echo.pnd b/testdata/pndsample/x86_echo.pnd index b645c49..671226e 100644 Binary files a/testdata/pndsample/x86_echo.pnd and b/testdata/pndsample/x86_echo.pnd differ diff --git a/testdata/pndsample/x86_ls.pnd b/testdata/pndsample/x86_ls.pnd index 6e308e0..be0369d 100644 Binary files a/testdata/pndsample/x86_ls.pnd and b/testdata/pndsample/x86_ls.pnd differ