Merge branch 'master' of git://git.openpandora.org/pandora-libraries
[pandora-libraries.git] / apps / pndnotifyd.c
1
2 /* pndnotifyd - a daemon whose job is to monitor searchpaths for app changes (appearing, disappearing, changing).
3  * If a change is found, the discovery code is invoked and apps registered for the launchers to see
4  *
5  */
6
7 #include <stdio.h>     // for stdio
8 #include <unistd.h>    // for exit()
9 #include <stdlib.h>    // for exit()
10 #define __USE_GNU /* for strcasestr */
11 #include <string.h>
12 #include <time.h>      // for time()
13 #include <ctype.h>     // for isdigit()
14 #include <sys/types.h> // for umask
15 #include <sys/stat.h>  // for umask
16 #include <dirent.h>    // for opendir()
17 #include <signal.h>    // for sigaction
18
19 #include "pnd_conf.h"
20 #include "pnd_container.h"
21 #include "pnd_apps.h"
22 #include "pnd_notify.h"
23 #include "../lib/pnd_pathiter.h"
24 #include "pnd_discovery.h"
25 #include "pnd_locate.h"
26 #include "pnd_pxml.h"
27 #include "pnd_utility.h"
28 #include "pnd_desktop.h"
29 #include "pnd_logger.h"
30
31 // this piece of code was simpler once; but need to grow it a bit and in a rush
32 // moving all these to globals rather than refactor the code a bit; tsk tsk..
33
34 // op mode; emitting stdout or no?
35 static unsigned char g_daemon_mode = 0;
36
37 typedef enum {
38   pndn_debug = 0,
39   pndn_rem,          // will set default log level to here, so 'debug' is omitted
40   pndn_warning,
41   pndn_error,
42   pndn_none
43 } pndnotify_loglevels_e;
44
45 // like discotest
46 char *configpath;
47 char *overridespath;
48 // daemon stuff
49 char *searchpath = NULL;
50 char *notifypath = NULL;
51 time_t createtime = 0; // all 'new' .destops are created at or after this time; prev are old.
52 // dotfiles; this used to be a single pai .. now two pairs, a little unwieldy; pnd_box it up?
53 char *desktop_dotdesktoppath = NULL;
54 char *desktop_iconpath = NULL;
55 char *desktop_appspath = NULL;
56 char *menu_dotdesktoppath = NULL;
57 char *menu_iconpath = NULL;
58 char *menu_appspath = NULL;
59 // pnd runscript
60 char *run_searchpath; // searchpath to find pnd_run.sh
61 char *run_script;     // name of pnd_run.sh script from config
62 char *pndrun;         // full path to located pnd_run.sh
63 char *pndhup = NULL;  // full path to located pnd_hup.sh
64 // notifier handle
65 pnd_notify_handle nh = 0;
66
67 // constants
68 #define PNDNOTIFYD_LOGLEVEL "pndnotifyd.loglevel"
69
70 // decl's
71 void consume_configuration ( void );
72 void setup_notifications ( void );
73 void sighup_handler ( int n );
74 void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char *emiticonpath );
75 unsigned char perform_discoveries ( char *appspath, char *overridespath,
76                                     char *emitdesktoppath, char *emiticonpath );
77
78 int main ( int argc, char *argv[] ) {
79   // behaviour
80   unsigned char scanonlaunch = 1;
81   unsigned int interval_secs = 5;
82   // misc
83   int i;
84
85   /* iterate across args
86    */
87   for ( i = 1; i < argc; i++ ) {
88
89     if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'd' ) {
90       //printf ( "Going daemon mode. Silent running.\n" );
91       g_daemon_mode = 1;
92     } else if ( isdigit ( argv [ i ][ 0 ] ) ) {
93       interval_secs = atoi ( argv [ i ] );
94     } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'n' ) {
95       scanonlaunch = 0;
96     } else {
97       printf ( "%s [-d] [##]\n", argv [ 0 ] );
98       printf ( "-d\tDaemon mode; detach from terminal, chdir to /tmp, suppress output. Optional.\n" );
99       printf ( "-n\tDo not scan on launch; default is to run a scan for apps when %s is invoked.\n", argv [ 0 ] );
100       printf ( "##\tA numeric value is interpreted as number of seconds between checking for filesystem changes. Default %u.\n",
101                interval_secs );
102       printf ( "Signal: HUP the process to force reload of configuration and reset the notifier watch paths\n" );
103       exit ( 0 );
104     }
105
106   } // for
107
108   /* enable logging?
109    */
110   if ( g_daemon_mode ) {
111     // nada
112   } else {
113     pnd_log_set_filter ( pndn_rem );
114     pnd_log_set_pretext ( "pndnotifyd" );
115     pnd_log_to_stdout();
116     pnd_log ( pndn_rem, "log level starting as %u", pnd_log_get_filter() );
117   }
118
119   pnd_log ( pndn_rem, "Interval between checks is %u seconds\n", interval_secs );
120
121   // check if inotify is awake yet; if not, try waiting for awhile to see if it does
122   pnd_log ( pndn_rem, "Starting INOTIFY test; should be instant, but may take awhile...\n" );
123
124   if ( ! pnd_notify_wait_until_ready ( 120 /* seconds */ ) ) {
125     pnd_log ( pndn_error, "ERROR: INOTIFY refuses to be useful and quite awhile has passed. Bailing out.\n" );
126     return ( -1 );
127   }
128
129   pnd_log ( pndn_rem, "INOTIFY seems to be useful, whew.\n" );
130
131   // basic daemon set up
132   if ( g_daemon_mode ) {
133
134     // set a CWD somewhere else
135 #if 0
136     chdir ( "/tmp" );
137 #endif
138
139     // detach from terminal
140     if ( ( i = fork() ) < 0 ) {
141       pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
142       exit ( i );
143     }
144     if ( i ) {
145       exit ( 0 ); // exit parent
146     }
147     setsid();
148
149     // umask
150     umask ( 022 ); // emitted files can be rwxr-xr-x
151     
152   } // set up daemon
153
154   // wait for a user to be logged in - we should probably get hupped when a user logs in, so we can handle
155   // log-out and back in again, with SDs popping in and out between..
156   pnd_log ( pndn_rem, "Checking to see if a user is logged in\n" );
157   char tmp_username [ 128 ];
158   while ( 1 ) {
159     if ( pnd_check_login ( tmp_username, 127 ) ) {
160       break;
161     }
162     pnd_log ( pndn_debug, "  No one logged in yet .. spinning.\n" );
163     sleep ( 2 );
164   } // spin
165   pnd_log ( pndn_rem, "Looks like user '%s' is in, continue.\n", tmp_username );
166
167   /* parse configs
168    */
169
170   consume_configuration();
171
172   /* startup
173    */
174
175   pnd_log ( pndn_rem, "PXML overrides searchpath is '%s'\n", overridespath );
176   pnd_log ( pndn_rem, "Notify searchpath is '%s'\n", notifypath );
177
178   pnd_log ( pndn_rem, "Desktop apps ---------------------------------\n" );
179   pnd_log ( pndn_rem, "Apps searchpath is '%s'\n", desktop_appspath );
180   pnd_log ( pndn_rem, ".desktop files emit to '%s'\n", desktop_dotdesktoppath );
181   pnd_log ( pndn_rem, ".desktop icon files emit to '%s'\n", desktop_iconpath );
182
183   pnd_log ( pndn_rem, "Menu apps ---------------------------------\n" );
184   pnd_log ( pndn_rem, "Apps searchpath is '%s'\n", menu_appspath );
185   pnd_log ( pndn_rem, ".desktop files emit to '%s'\n", menu_dotdesktoppath );
186   pnd_log ( pndn_rem, ".desktop icon files emit to '%s'\n", menu_iconpath );
187
188   /* set up signal handler
189    */
190   sigset_t ss;
191   sigemptyset ( &ss );
192
193   struct sigaction siggy;
194   siggy.sa_handler = sighup_handler;
195   siggy.sa_mask = ss; /* implicitly blocks the origin signal */
196   siggy.sa_flags = 0; /* don't need anything */
197
198   sigaction ( SIGHUP, &siggy, NULL );
199
200   /* set up notifies
201    */
202
203   // if we're gong to scan on launch, it'll set things right up and then set up notifications.
204   // if no scan on launch, we need to set the notif's up now.
205   //if ( ! scanonlaunch ) {
206   setup_notifications();
207   //}
208
209   /* daemon main loop
210    */
211   while ( 1 ) {
212
213     // need to rediscover?
214     if ( scanonlaunch ||
215          pnd_notify_rediscover_p ( nh ) )
216     {
217       createtime = time ( NULL ); // all 'new' .destops are created at or after this time; prev are old.
218
219       // if this was a forced scan, lets not do that next iteration
220       if ( scanonlaunch ) {
221         scanonlaunch = 0;
222       }
223
224       // by this point, the watched directories have notified us that something of relevent
225       // has occurred; we should be clever, but we're not, so just re-brute force the
226       // discovery and spit out .desktop files..
227       pnd_log ( pndn_rem, "------------------------------------------------------\n" );
228       pnd_log ( pndn_rem, "Changes within watched paths .. performing re-discover!\n" );
229
230       /* run the discovery
231        */
232
233       pnd_log ( pndn_rem, "Scanning desktop paths----------------------------\n" );
234       if ( ! perform_discoveries ( desktop_appspath, overridespath, desktop_dotdesktoppath, desktop_iconpath ) ) {
235         pnd_log ( pndn_rem, "No applications found in desktop search path\n" );
236       }
237
238       if ( menu_appspath && menu_dotdesktoppath && menu_iconpath ) {
239         pnd_log ( pndn_rem, "Scanning menu paths----------------------------\n" );
240         if ( ! perform_discoveries ( menu_appspath, overridespath, menu_dotdesktoppath, menu_iconpath ) ) {
241           pnd_log ( pndn_rem, "No applications found in menu search path\n" );
242         }
243       }
244
245       // if we've got a hup script located, lets invoke it
246       if ( pndhup ) {
247         pnd_log ( pndn_rem, "Invoking hup script '%s'.\n", pndhup );
248         pnd_exec_no_wait_1 ( pndhup, NULL );
249       }
250
251       // since its entirely likely new directories have been found (ie: SD with a directory structure was inserted)
252       // we should re-apply watches to catch all these new directories; ie: user might use on-device browser to
253       // drop in new applications, or use the shell to juggle them around, or any number of activities.
254       //setup_notifications();
255
256     } // need to rediscover?
257
258     // lets not eat up all the CPU
259     // should use an alarm or select() or something -- I mean really, why aren't I putting interval_secs into
260     // the select() call above in pnd_notify_whatsitcalled()? -- but lets not break this right before release shall we
261     // NOTE: Oh right, I remember now -- inotify will spam when a card is inserted, and it will not be instantaneoous..
262     // the events will dribble in over a second. So this sleep is a lame trick that generally works. I really should
263     // do select(), and then when it returns just spin for a couple seconds slurping up events until no more and a thresh-hold
264     // time is hit, but this will do for now. I suck.
265     sleep ( interval_secs );
266
267   } // while
268
269   /* shutdown
270    */
271   pnd_notify_shutdown ( nh );
272
273   return ( 0 );
274 }
275
276 void consume_configuration ( void ) {
277
278   // attempt to fetch a sensible default searchpath for configs
279   configpath = pnd_conf_query_searchpath();
280
281   // attempt to fetch the apps config to pick up a searchpath
282   pnd_conf_handle apph;
283
284   apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
285
286   if ( apph ) {
287
288     overridespath = pnd_conf_get_as_char ( apph, PND_PXML_OVERRIDE_KEY );
289
290     if ( ! overridespath ) {
291       overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
292     }
293
294     notifypath = pnd_conf_get_as_char ( apph, PND_APPS_NOTIFY_KEY );
295
296     if ( ! notifypath ) {
297       notifypath = PND_APPS_NOTIFYPATH;
298     }
299
300   } else {
301     // couldn't find a useful app search path so use the default
302     overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
303     notifypath = PND_APPS_NOTIFYPATH;
304   }
305
306   // attempt to figure out where to drop dotfiles .. now that we're going
307   // multi-target we see the limit of my rudimentary conf-file parser; should
308   // just parse to an array of targets, rather that hardcoding two, but
309   // on the other hand, don't likely see the need for more than two? (famous
310   // last words.)
311   pnd_conf_handle desktoph;
312
313   desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, configpath );
314
315   // for 'desktop' main applications
316   if ( desktoph ) {
317     desktop_dotdesktoppath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_DOTDESKTOP_PATH_KEY );
318     desktop_iconpath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_ICONS_PATH_KEY );
319     desktop_appspath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_SEARCH_KEY );
320   }
321
322   if ( ! desktop_dotdesktoppath ) {
323     desktop_dotdesktoppath = PND_DESKTOP_DOTDESKTOP_PATH_DEFAULT;
324   }
325
326   if ( ! desktop_iconpath ) {
327     desktop_iconpath = PND_DESKTOP_ICONS_PATH_DEFAULT;
328   }
329
330   if ( ! desktop_appspath ) {
331     desktop_appspath = PND_DESKTOP_SEARCH_PATH_DEFAULT;
332   }
333
334   // for 'menu' applications
335   if ( desktoph ) {
336     menu_dotdesktoppath = pnd_conf_get_as_char ( desktoph, PND_MENU_DOTDESKTOP_PATH_KEY );
337     menu_iconpath = pnd_conf_get_as_char ( desktoph, PND_MENU_ICONS_PATH_KEY );
338     menu_appspath = pnd_conf_get_as_char ( desktoph, PND_MENU_SEARCH_KEY );
339   }
340
341   /* try to locate a runscript and optional hupscript
342    */
343
344   if ( apph ) {
345     run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY );
346     run_script = pnd_conf_get_as_char ( apph, PND_PNDRUN_KEY );
347     pndrun = NULL;
348
349     if ( ! run_searchpath ) {
350       run_searchpath = PND_APPS_SEARCHPATH;
351       run_script = PND_PNDRUN_FILENAME;
352     }
353
354     if ( pnd_conf_get_as_int ( apph, PNDNOTIFYD_LOGLEVEL ) != PND_CONF_BADNUM ) {
355       pnd_log_set_filter ( pnd_conf_get_as_int ( apph, PNDNOTIFYD_LOGLEVEL ) );
356       pnd_log ( pndn_rem, "config file causes loglevel to change to %u", pnd_log_get_filter() );
357     }
358
359   } else {
360     run_searchpath = NULL;
361     run_script = NULL;
362     pndrun = PND_PNDRUN_DEFAULT;
363   }
364
365   if ( ! pndrun ) {
366     pndrun = pnd_locate_filename ( run_searchpath, run_script );
367
368     if ( pndrun ) {
369       pndrun = strdup ( pndrun ); // so we don't just use the built in buffer; next locate will overwrite it
370     } else {
371       pndrun = PND_PNDRUN_DEFAULT;
372     }
373
374   }
375
376   if ( desktoph && run_searchpath ) {
377     char *t;
378
379     if ( ( t = pnd_conf_get_as_char ( desktoph, PND_PNDHUP_KEY ) ) ) {
380       pndhup = pnd_locate_filename ( run_searchpath, t );
381
382       if ( pndhup ) {
383         pndhup = strdup ( pndhup ); // so we don't just use the built in buffer; next locate will overwrite it
384       }
385
386 #if 0 // don't enable this; if no key in config, we don't want to bother hupping
387     } else {
388       pndhup = pnd_locate_filename ( run_searchpath, PND_PNDHUP_FILENAME );
389 #endif
390     }
391
392   }
393
394   // debug
395   if ( run_searchpath ) pnd_log ( pndn_rem, "Locating pnd run in %s\n", run_searchpath );
396   if ( run_script ) pnd_log ( pndn_rem, "Locating pnd runscript as %s\n", run_script );
397   if ( pndrun ) pnd_log ( pndn_rem, "pndrun is %s\n", pndrun );
398   if ( pndhup ) {
399     pnd_log ( pndn_rem, "pndhup is %s\n", pndhup );
400   } else {
401     pnd_log ( pndn_rem, "No pndhup found (which is fine.)\n" );
402   }
403
404   /* handle globbing or variable substitution
405    */
406   desktop_dotdesktoppath = pnd_expand_tilde ( strdup ( desktop_dotdesktoppath ) );
407   desktop_iconpath = pnd_expand_tilde ( strdup ( desktop_iconpath ) );
408   mkdir ( desktop_dotdesktoppath, 0777 );
409   mkdir ( desktop_iconpath, 0777 );
410
411   if ( menu_dotdesktoppath ) {
412     menu_dotdesktoppath = pnd_expand_tilde ( strdup ( menu_dotdesktoppath ) );
413     mkdir ( menu_dotdesktoppath, 0777 );
414   }
415   if ( menu_iconpath ) {
416     menu_iconpath = pnd_expand_tilde ( strdup ( menu_iconpath ) );
417     mkdir ( menu_iconpath, 0777 );
418   }
419
420   // done
421   return;
422 }
423
424 void setup_notifications ( void ) {
425   searchpath = notifypath;
426
427   // if this is first time through, we can just set it up; for subsequent times
428   // through, we need to close existing fd and re-open it, since we're too lame
429   // to store the list of watches and 'rm' them
430 #if 1
431   if ( nh ) {
432     pnd_notify_shutdown ( nh );
433     nh = 0;
434   }
435 #endif
436
437   // set up a new set of notifies
438   if ( ! nh ) {
439     nh = pnd_notify_init();
440   }
441
442   if ( ! nh ) {
443     pnd_log ( pndn_rem, "INOTIFY failed to init.\n" );
444     exit ( -1 );
445   }
446
447 #if 0
448   pnd_log ( pndn_rem, "INOTIFY is up.\n" );
449 #endif
450
451   SEARCHPATH_PRE
452   {
453
454     pnd_log ( pndn_rem, "Watching path '%s' and its descendents.\n", buffer );
455     pnd_notify_watch_path ( nh, buffer, PND_NOTIFY_RECURSE );
456
457   }
458   SEARCHPATH_POST
459
460   return;
461 }
462
463 void sighup_handler ( int n ) {
464
465   pnd_log ( pndn_rem, "---[ SIGHUP received ]---\n" );
466
467   // reparse config files
468   consume_configuration();
469
470   // re set up the notifier watches
471   setup_notifications();
472
473   return;
474 }
475
476 // This very recently was inline code; just slight refactor to functionize it so that it can be
477 // reused in a couple of places. Simple code with simple design quickly became too large for
478 // its simple design; should revisit a lot of these little things..
479 void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char *emiticonpath ) {
480   pnd_disco_t *d = pnd_box_get_head ( applist );
481
482   while ( d ) {
483
484     pnd_log ( pndn_rem, "Found app: %s\n", pnd_box_get_key ( d ) );
485
486     // check if icon already exists (from a previous extraction say); if so, we needn't
487     // do it again
488     char existingpath [ FILENAME_MAX ];
489     sprintf ( existingpath, "%s/%s.png", emiticonpath, d -> unique_id );
490
491     struct stat dirs;
492     if ( stat ( existingpath, &dirs ) == 0 ) {
493       // icon seems to exist, so just crib the location into the .desktop
494
495       pnd_log ( pndn_rem, "  Found icon already existed, so reusing it! %s\n", existingpath );
496
497       if ( d -> icon ) {
498         free ( d -> icon );
499       }
500       d -> icon = strdup ( existingpath );
501
502     } else {
503       // icon seems unreadable or does not exist; lets try to create it..
504
505       pnd_log ( pndn_debug, "  Icon not already present, so trying to write it! %s\n", existingpath );
506
507       // attempt to create icon files; if successful, alter the disco struct to contain new
508       // path, otherwise leave it alone (since it could be a generic icon reference..)
509       if ( pnd_emit_icon ( emiticonpath, d ) ) {
510         // success; fix up icon path to new one..
511         if ( d -> icon ) {
512           free ( d -> icon );
513         }
514         d -> icon = strdup ( existingpath );
515       } else {
516         pnd_log ( pndn_debug, "  WARN: Couldn't write out icon %s\n", existingpath );
517       }
518
519     } // icon already exists?
520
521     // create the .desktop file
522     if ( pnd_emit_dotdesktop ( emitdesktoppath, pndrun, d ) ) {
523       // add a watch onto the newly created .desktop?
524 #if 0
525       char buffer [ FILENAME_MAX ];
526       sprintf ( buffer, "%s/%s", emitdesktoppath, d -> unique_id );
527       pnd_notify_watch_path ( nh, buffer, PND_NOTIFY_RECURSE );
528 #endif
529     } else {
530       pnd_log ( pndn_rem, "ERROR: Error creating .desktop file for app: %s\n", pnd_box_get_key ( d ) );
531     }
532
533     // next!
534     d = pnd_box_get_next ( d );
535
536   } // while applist
537
538   return;
539 }
540
541 // returns true if any applications were found
542 unsigned char perform_discoveries ( char *appspath, char *overridespath,              // args to do discovery
543                                     char *emitdesktoppath, char *emiticonpath )       // args to do emitting
544 {
545   pnd_box_handle applist;
546
547   // attempt to auto-discover applications in the given path
548   applist = pnd_disco_search ( appspath, overridespath );
549
550   if ( applist ) {
551     process_discoveries ( applist, emitdesktoppath, emiticonpath );
552   }
553
554   // run a clean up, to remove any dotdesktop files that we didn't
555   // just now create (that seem to have been created by pndnotifyd
556   // previously.) This allows SD eject (or .pnd remove) to remove
557   // an app from the launcher
558   //   NOTE: Could opendir and iterate across all .desktop files,
559   // removing any that have Source= something else, and that the
560   // app name is not in the list found in applist box above. But
561   // a cheesy simple way right now is to just remove .desktop files
562   // that have a last mod time prior to the time we stored above.
563   {
564     DIR *dir;
565
566     if ( ( dir = opendir ( emitdesktoppath ) ) ) {
567       struct dirent *dirent;
568       struct stat dirs;
569       char buffer [ FILENAME_MAX ];
570
571       while ( ( dirent = readdir ( dir ) ) ) {
572
573         // file is a .desktop?
574         if ( strstr ( dirent -> d_name, ".desktop" ) == NULL ) {
575           continue;
576         }
577
578         // figure out full path
579         sprintf ( buffer, "%s/%s", emitdesktoppath, dirent -> d_name );
580
581         // file was previously created by libpnd; check Source= line
582         // logic: default to 'yes' (in case we can't open the file for some reason)
583         //        if we can open the file, default to no and look for the source flag we added; if
584         //          that matches then we know its libpnd created, otherwise assume not.
585         unsigned char source_libpnd = 1;
586         {
587           char line [ 256 ];
588           FILE *grep = fopen ( buffer, "r" );
589           if ( grep ) {
590             source_libpnd = 0;
591             while ( fgets ( line, 255, grep ) ) {
592               if ( strcasestr ( line, PND_DOTDESKTOP_SOURCE ) ) {
593                 source_libpnd = 2;
594               }
595             } // while
596             fclose ( grep );
597           }
598         }
599         if ( source_libpnd ) {
600 #if 0
601           pnd_log ( pndn_rem,
602                     "File '%s' appears to have been created by libpnd so candidate for delete: %u\n", buffer, source_libpnd );
603 #endif
604         } else {
605 #if 0
606           pnd_log ( pndn_rem, "File '%s' appears NOT to have been created by libpnd, so leave it alone\n", buffer );
607 #endif
608           continue; // skip deleting it
609         }
610
611         // file is 'new'?
612         if ( stat ( buffer, &dirs ) == 0 ) {
613           if ( dirs.st_mtime >= createtime ) {
614 #if 0
615             pnd_log ( pndn_rem, "File '%s' seems 'new', so leave it alone.\n", buffer );
616 #endif
617             continue; // skip deleting it
618           }
619         }
620
621         // by this point, the .desktop file must be 'old' and created by pndnotifyd
622         // previously, so can remove it
623         pnd_log ( pndn_rem, "File '%s' seems nolonger relevent; removing it.\n", dirent -> d_name );
624         unlink ( buffer );
625
626       } // while getting filenames from dir
627
628       closedir ( dir );
629     }
630
631   } // purge old .desktop files
632
633   //WARN: MEMORY LEAK HERE
634   pnd_log ( pndn_debug, "pndnotifyd - memory leak here - perform_discoveries()\n" );
635   if ( applist ) {
636     pnd_box_delete ( applist ); // does not free the disco_t contents!
637   }
638
639   return ( 1 );
640 }