From e42b2f587e27c662c73731b1da99d86142cdbda9 Mon Sep 17 00:00:00 2001 From: skeezix Date: Wed, 25 Feb 2009 13:06:49 -0500 Subject: [PATCH] Added a 'flags' arg to pnd_apps_exec Added option PND_EXEC_OPTION_BLOCK to require libpnd to hang until child process completes. --- include/pnd_apps.h | 14 ++++++++++++-- lib/pnd_apps.c | 23 ++++++++++++++++++++--- test/discotest.c | 2 +- testdata/pndsample/x86_echo.pnd | Bin 387551 -> 387551 bytes testdata/pndsample/x86_ls.pnd | Bin 489775 -> 489775 bytes 5 files changed, 33 insertions(+), 6 deletions(-) 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 b645c491efad6817c098b748a16a74b3a6d4d741..671226e2d6288729ee1102d66fd08157e30369c0 100644 GIT binary patch delta 104 zcmcbAS^WNG@eL-;5~hYmCWa=)1_p183=Av{jEtZHlYN?{*`e&sdChvJERsB$+LIUT juo40>-sCbNQO$35w7=QG2*gZ4%nZaV+u!V9{cHdL#VsVM delta 104 zcmcbAS^WNG@eL-;5+())29`!Z;ti0nG%zxP3QYECmS%^tH|I6$nX*VQaEeS`u)|6S g#CVg-ghVyJ+0p)H2O|(O0WmWWvuuB}gY~lk0GNCuiU0rr diff --git a/testdata/pndsample/x86_ls.pnd b/testdata/pndsample/x86_ls.pnd index 6e308e0fdeebc8ec3f9d1193448d74e2b934c20c..be0369d02e6961321cb73898de27f8f552c12210 100644 GIT binary patch delta 108 zcmZ4gNp}4w*$pPm5~hYmCWaf{ANe{n;ncm%ml>DK+FQftlQu0U~@hI08w=&od5s; delta 108 zcmZ4gNp}4w*$pPm5+())29`!Z;ti0nG%zxP3QYECmS%^tH|I6$nX*VQaEeS`u)|6S j#CVg-ghVyJ+0p)H2O|(O0WmWWvj8#c_BT7&oDTp1A<`v< -- 2.39.5