+ // sleep a sec, just to be safe; seems to dislike being called immediately sometimes
+ usleep ( 1000000 / 2 );
+
+ // create a temp file
+ FILE *f;
+ if ( ! ( f = fopen ( _INOTIFY_TEST_FILE, "w" ) ) ) {
+ close ( fdt.fd );
+ return ( 0 ); // couldn't create test file?!
+ }
+
+ fclose ( f );
+
+ // delete the temp file; this should trigger an event
+ if ( unlink ( _INOTIFY_TEST_FILE ) < 0 ) {
+ return ( 0 ); // couldn't rm a file? life is harsh.
+ }
+
+ // did we get anything?
+ unsigned char s;
+ s = pnd_notify_rediscover_p ( &fdt );
+
+ // ditch inotify
+ close ( fdt.fd );
+
+ // success
+ return ( s );
+}
+
+/* we've run into the issue where inotify returns that it is set up, but in
+ * fact is not doing anything; restarting the process repairs it.. so here
+ * we devise a wank that continually tests inotify until it responds, then
+ * returns knowing we're good
+ */
+unsigned char pnd_notify_wait_until_ready ( unsigned int secs_timeout ) {
+ time_t start = time ( NULL );
+
+ while ( ( secs_timeout == 0 ) ||
+ ( time ( NULL ) - start < secs_timeout ) )
+ {
+ if ( _inotify_test_run() ) {
+ return ( 1 );
+ }
+ usleep ( 1000000 / 2 );
+ }
+
+ return ( 0 ); // fail