Preliminary stab at app scan locking; pndnotifyd creates logfile /tmp/whatever and...
[pandora-libraries.git] / minimenu / mmenu.c
index 5946cc8..919b509 100644 (file)
@@ -37,6 +37,7 @@
 #include <sys/wait.h>
 #include <dirent.h>
 #include <signal.h> // for sigaction
+#include <time.h>
 
 #include "pnd_logger.h"
 #include "pnd_pxml.h"
@@ -61,6 +62,8 @@
 #include "mmui.h"
 #include "mmconf.h"
 
+#define PNDLOCKNAME "pndnotifyd-disco.lock" /* from pndnotifyd */
+
 pnd_box_handle g_active_apps = NULL;
 unsigned int g_active_appcount = 0;
 char g_username [ 128 ]; // since we have to wait for login (!!), store username here
@@ -597,9 +600,39 @@ void applications_scan ( void ) {
   // perform app discovery on .desktop files?
   //
   if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.disco_dotdesktop", 0 ) ) {
-    char *chunks[5] = {
+
+    // deal with locks
+    pnd_log ( pndn_debug, "Checking pndnotifyd disco lock %s\n", PNDLOCKNAME );
+
+    //   first, check if lock is 'old' -- maybe locker crashed, or if its old enough.. its just good, right?
+    time_t age = pnd_is_locked ( PNDLOCKNAME );
+
+    if ( age == 0 ) {
+      pnd_log ( pndn_debug, "Lock is all clear %s so no need to wait\n", PNDLOCKNAME );
+
+    } else if ( time ( NULL ) - age > pnd_conf_get_as_int_d ( g_conf, "minimenu.disco_lock_maxage_s", 120 ) ) {
+      // lock seems old, so who cares
+      pnd_log ( pndn_debug, "Lock is OLD so ignoring it: %s\n", PNDLOCKNAME );
+
+    } else {
+      // not too old, so lets wait.. we could be booting up!
+
+      int rv = pnd_wait_for_unlock ( PNDLOCKNAME,
+                                    pnd_conf_get_as_int_d ( g_conf, "minimenu.disco_lock_max", 20 ),
+                                    pnd_conf_get_as_int_d ( g_conf, "minimenu.disco_lock_usec_delta", 500000 ) );
+      if ( rv ) {
+       pnd_log ( pndn_debug, "Waited for lock and is now clear %s\n", PNDLOCKNAME );
+      } else {
+       pnd_log ( pndn_debug, "Waited for lock and timed out %s .. proceeding anyway.\n", PNDLOCKNAME );
+      }
+
+    } // locking
+
+    // where to scan..
+    char *chunks[10] = {
       pnd_conf_get_as_char ( g_desktopconf, "desktop.dotdesktoppath" ),
       pnd_conf_get_as_char ( g_desktopconf, "menu.dotdesktoppath" ),
+      pnd_conf_get_as_char ( g_conf, "minimenu.aux_searchpath" ),
       //"/usr/share/applications",
       NULL
     };
@@ -639,8 +672,11 @@ void applications_scan ( void ) {
            snprintf ( ddpath, 1024, "%s/%s", chunks [ i ], de -> d_name );
            pnd_disco_t *p = pnd_parse_dotdesktop ( ddpath, flags );
            if ( p ) {
+             // store
              pnd_disco_t *ai = pnd_box_allocinsert ( g_active_apps, ddpath, sizeof(pnd_disco_t) );
              memmove ( ai, p, sizeof(pnd_disco_t) );
+             // free
+             free ( p );
            }
          }
 
@@ -673,9 +709,16 @@ void applications_scan ( void ) {
   while ( iter ) {
     //pnd_log ( pndn_debug, "  App: '%s'\n", IFNULL(iter->title_en,"No Name") );
 
+    // dump
+#if 0
+    printf ( "App %s\t%s\t Cat %s:%s:%s %s:%s:%s\n", iter -> title_en, iter -> unique_id,
+            iter -> main_category, iter -> main_category1, iter -> main_category2,
+            iter -> alt_category, iter -> alt_category1, iter -> alt_category2 );
+#endif
+
     // update cachescreen
-    // ... every 5 filenames, just to avoid slowing it too much
-    if ( loadlater == 0 && itercount % 5 == 0 ) {
+    // ... every 10 filenames, just to avoid slowing it too much
+    if ( loadlater == 0 && itercount % 10 == 0 ) {
       ui_cachescreen ( 0 /* clear screen */, IFNULL(iter->title_en,"No Name") );
     }
 
@@ -725,7 +768,7 @@ void applications_scan ( void ) {
       // OR its a .desktop and we've got a path
       // THEN go try to cache/load the icon
       if ( ( iter -> pnd_icon_pos ) ||
-          ( iter -> icon && iter -> object_flags & PND_DISCO_CUSTOM1 )
+          ( iter -> icon && iter -> object_flags & PND_DISCO_LIBPND_DD )
         )
       {