Preliminary stab at app scan locking; pndnotifyd creates logfile /tmp/whatever and...
[pandora-libraries.git] / include / pnd_utility.h
index e468258..09ea621 100644 (file)
@@ -6,6 +6,8 @@
 extern "C" {
 #endif
 
+#include <time.h>
+
 // expand_tilde() will only function correctly if a user is actually logged in; perhaps you
 // want to spin until it looks like someone has in fact done so. (most devices will likely
 // have auto-login, but its not instantaneous!)
@@ -30,6 +32,17 @@ unsigned char pnd_determine_mountpoint ( char *fullpath, char *r_mountpoint, uns
 // filecopy will return >0 on success
 unsigned char pnd_filecopy ( char *sourcepath, char *targetpath );
 
+// some lame file locking utility (not using 'flock')
+// ** This is not race condition safe, so not for serious locking; this is just for casual locking, not high speed
+#define PND_LOCK_PATH "/tmp" /* default path to stick lockfiles */
+unsigned char pnd_lock ( char *lockname ); // return 0 on fail, >0 on success; lock file, not semaphore/etc
+time_t pnd_is_locked ( char *lockname );   // return 0 on unlocked, >0 is epoch time when locked
+void pnd_unlock ( char *lockname );        // assumes success
+// wait 'max' occurances of microseconds (usleep) for unlock
+// if max is 0, will not wait at all (will just check, same as pnd_is_locked())
+// return '1' for unlock (may be immediate), 0 for failed 'max' timse
+unsigned char pnd_wait_for_unlock ( char *lockname, unsigned short int max, unsigned int usec_delta );
+
 #ifdef __cplusplus
 } /* "C" */
 #endif