From ce4cbee8190489a75506a67934c149633bab7182 Mon Sep 17 00:00:00 2001 From: skeezix Date: Sat, 7 Mar 2009 01:09:00 -0500 Subject: [PATCH] Added support for a hup script; if the pnd.hupscript key is within the 'apps' config, then after emitting .desktop files pndnotifyd will attempt to invoke the hupscript, which could in turn hup the launcher application (to let it know to rescan) Fiddled with re-setting-up-notifiers after autodiscovery (to handle newly mounted directories, in case user downloads an app on-device, or uses the shell, etc), but led to some odd situations. (ie: shutting down and reopening the inotify fd seemed to cause it to immediately need a rescan, so could repeat 2 or 3 times..) --- apps/pndnotifyd.c | 52 +++++++++++++++++++++++++++++--- deployment/etc/pandora/conf/apps | 1 + include/pnd_apps.h | 3 ++ include/pnd_utility.h | 3 ++ lib/pnd_utility.c | 26 ++++++++++++++++ testdata/conf/apps | 1 + 6 files changed, 82 insertions(+), 4 deletions(-) diff --git a/apps/pndnotifyd.c b/apps/pndnotifyd.c index 4dbbe7d..797fb80 100644 --- a/apps/pndnotifyd.c +++ b/apps/pndnotifyd.c @@ -46,6 +46,7 @@ char *dotdesktoppath = NULL; char *run_searchpath; char *run_script; char *pndrun; +char *pndhup = NULL; // notifier handle pnd_notify_handle nh = 0; @@ -78,6 +79,7 @@ int main ( int argc, char *argv[] ) { printf ( "-n\tDo not scan on launch; default is to run a scan for apps when %s is invoked.\n", argv [ 0 ] ); printf ( "##\tA numeric value is interpreted as number of seconds between checking for filesystem changes. Default %u.\n", interval_secs ); + printf ( "Signal: HUP the process to force reload of configuration and reset the notifier watch paths\n" ); exit ( 0 ); } @@ -138,7 +140,12 @@ int main ( int argc, char *argv[] ) { /* set up notifies */ + + // if we're gong to scan on launch, it'll set things right up and then set up notifications. + // if no scan on launch, we need to set the notif's up now. + //if ( ! scanonlaunch ) { setup_notifications(); + //} /* daemon main loop */ @@ -160,6 +167,7 @@ int main ( int argc, char *argv[] ) { // has occurred; we should be clever, but we're not, so just re-brute force the // discovery and spit out .desktop files.. if ( ! g_daemon_mode ) { + printf ( "------------------------------------------------------\n" ); printf ( "Changes within watched paths .. performing re-discover!\n" ); } @@ -326,10 +334,18 @@ int main ( int argc, char *argv[] ) { } // purge old .desktop files + // if we've got a hup script located, lets invoke it + if ( pndhup ) { + if ( ! g_daemon_mode ) { + printf ( "Invoking hup script '%s'.\n", pndhup ); + } + pnd_exec_no_wait_1 ( pndhup, NULL ); + } + // since its entirely likely new directories have been found (ie: SD with a directory structure was inserted) // we should re-apply watches to catch all these new directories; ie: user might use on-device browser to // drop in new applications, or use the shell to juggle them around, or any number of activities. - setup_notifications(); + //setup_notifications(); } // need to rediscover? @@ -391,7 +407,7 @@ void consume_configuration ( void ) { dotdesktoppath = PND_DOTDESKTOP_DEFAULT; } - // try to locate a runscript + // try to locate a runscript and optional hupscript if ( apph ) { run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY ); @@ -418,10 +434,29 @@ void consume_configuration ( void ) { } + if ( apph && run_searchpath ) { + char *t; + + if ( ( t = pnd_conf_get_as_char ( apph, PND_PNDHUP_KEY ) ) ) { + pndhup = pnd_locate_filename ( run_searchpath, t ); +#if 0 // don't enable this; if no key in config, we don't want to bother hupping + } else { + pndhup = pnd_locate_filename ( run_searchpath, PND_PNDHUP_FILENAME ); +#endif + } + + } + + // debug if ( ! g_daemon_mode ) { if ( run_searchpath ) printf ( "Locating pnd run in %s\n", run_searchpath ); if ( run_script ) printf ( "Locating pnd runscript as %s\n", run_script ); - if ( pndrun ) printf ( "Default pndrun is %s\n", pndrun ); + if ( pndrun ) printf ( "pndrun is %s\n", pndrun ); + if ( pndhup ) { + printf ( "pndhup is %s\n", pndhup ); + } else { + printf ( "No pndhup found (which is fine.)\n" ); + } } /* handle globbing or variable substitution @@ -442,12 +477,17 @@ void setup_notifications ( void ) { // if this is first time through, we can just set it up; for subsequent times // through, we need to close existing fd and re-open it, since we're too lame // to store the list of watches and 'rm' them +#if 1 if ( nh ) { pnd_notify_shutdown ( nh ); + nh = 0; } +#endif // set up a new set of notifies - nh = pnd_notify_init(); + if ( ! nh ) { + nh = pnd_notify_init(); + } if ( ! nh ) { if ( ! g_daemon_mode ) { @@ -479,6 +519,10 @@ void setup_notifications ( void ) { void sighup_handler ( int n ) { + if ( ! g_daemon_mode ) { + printf ( "---[ SIGHUP received ]---\n" ); + } + // reparse config files consume_configuration(); diff --git a/deployment/etc/pandora/conf/apps b/deployment/etc/pandora/conf/apps index 6cc8aa0..cc8659c 100644 --- a/deployment/etc/pandora/conf/apps +++ b/deployment/etc/pandora/conf/apps @@ -13,3 +13,4 @@ searchpath ~/pxml-overrides [pnd] searchpath /media/*/pandora/scripts:/usr/pandora/scripts runscript pnd_run.sh +hupscript pnd_hup.sh diff --git a/include/pnd_apps.h b/include/pnd_apps.h index e24dfd7..af179e0 100644 --- a/include/pnd_apps.h +++ b/include/pnd_apps.h @@ -14,6 +14,9 @@ extern "C" { #define PND_PNDRUN_FILENAME "pnd_run.sh" #define PND_PNDRUN_DEFAULT "./testdata/scripts/pnd_run.sh" +#define PND_PNDHUP_KEY "pnd.hupscript" +#define PND_PNDHUP_FILENAME "pnd_hup.sh" + #define PND_PXML_OVERRIDE_SEARCHPATH "~/pxml-overrides" #define PND_PXML_OVERRIDE_KEY "overrides.searchpath" diff --git a/include/pnd_utility.h b/include/pnd_utility.h index 257bfb7..81c5f9d 100644 --- a/include/pnd_utility.h +++ b/include/pnd_utility.h @@ -10,6 +10,9 @@ extern "C" { // new string; the old string is destroyed in the process, or returned as-is. char *pnd_expand_tilde ( char *freeable_buffer ); +// arbtrary execute function; fire and forget really +void pnd_exec_no_wait_1 ( char *fullpath, char *arg1 ); + #ifdef __cplusplus } /* "C" */ #endif diff --git a/lib/pnd_utility.c b/lib/pnd_utility.c index 33f672e..d66b9d3 100644 --- a/lib/pnd_utility.c +++ b/lib/pnd_utility.c @@ -2,6 +2,7 @@ #include /* for FILE etc */ #include /* for malloc */ #include /* for making ftw.h happy */ +#include /* for fork exec */ #include "pnd_utility.h" @@ -32,3 +33,28 @@ char *pnd_expand_tilde ( char *freeable_buffer ) { return ( s ); } + +void pnd_exec_no_wait_1 ( char *fullpath, char *arg1 ) { + int i; + + if ( ( i = fork() ) < 0 ) { + printf ( "ERROR: Couldn't fork()\n" ); + return; + } + + if ( i ) { + return; // parent process, don't care + } + + // child process, do something + if ( arg1 ) { + execl ( fullpath, fullpath, arg1, (char*) NULL ); + } else { + execl ( fullpath, fullpath, (char*) NULL ); + } + + // getting here is an error + //printf ( "Error attempting to run %s\n", fullpath ); + + return; +} diff --git a/testdata/conf/apps b/testdata/conf/apps index 3257bd3..0f8ff92 100644 --- a/testdata/conf/apps +++ b/testdata/conf/apps @@ -13,3 +13,4 @@ searchpath ~/pxml-overrides:./testdata/apps-override [pnd] searchpath /mnt/sd?/pandora/scripts:./testdata/scripts runscript pnd_run.sh +hupscript pnd_hup.sh -- 2.39.2