file-dotlock.h revision fdcb22a688c4676face8db865736b217d9c07d19
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen /* Dotlock files are created by first creating a temp file and then
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen link()ing it to the dotlock. temp_prefix specifies the prefix to
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen use for temp files. It may contain a full path. Default is
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen ".temp.hostname.pid.". */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen /* Use this suffix for dotlock filenames. Default is ".lock". */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen /* Abort after this many seconds. */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen unsigned int timeout;
8ecbb74bc4c7f6f6145da3525941d1d0e20e67f1Timo Sirainen /* Override the lock file when it and the file we're protecting is
8ecbb74bc4c7f6f6145da3525941d1d0e20e67f1Timo Sirainen older than stale_timeout. */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen /* Callback is called once in a while. stale is set to TRUE if stale
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen lock is detected and will be overridden in secs_left. If callback
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen returns FALSE then, the lock will not be overridden. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen bool (*callback)(unsigned int secs_left, bool stale, void *context);
860c6cf85bd2a3808ab3a480aa697bac24c291dcTimo Sirainen /* Rely on O_EXCL locking to work instead of using hardlinks.
860c6cf85bd2a3808ab3a480aa697bac24c291dcTimo Sirainen It's faster, but doesn't work with all NFS implementations. */
fdcb22a688c4676face8db865736b217d9c07d19Timo Sirainen /* Use io_add_notify() to speed up finding out when an existing
fdcb22a688c4676face8db865736b217d9c07d19Timo Sirainen dotlock is deleted */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen /* If lock already exists, fail immediately */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen /* Don't actually create the lock file, only make sure it doesn't
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen exist. This is racy, so you shouldn't rely on it much. */
933a8cc7033e8a9bb7a1c7630fbc786b914f1510Timo Sirainen /* Check that lock file hasn't been overridden before renaming. */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen /* Don't close the file descriptor. */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen/* Create dotlock. Returns 1 if successful, 0 if timeout or -1 if error.
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen When returning 0, errno is also set to EAGAIN. */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenint file_dotlock_create(const struct dotlock_settings *set, const char *path,
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen/* Delete the dotlock file. Returns 1 if successful, 0 if the file was already
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen been deleted or reused by someone else, -1 if error. */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenint file_dotlock_delete(struct dotlock **dotlock);
892f02d4ab8f764f86015009aaf7437349398286Timo Sirainen/* Use dotlock as the new content for file. This provides read safety without
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen locks, but it's not very good for large files. Returns fd for lock file.
7698840ca7516916cba42d27d8bd09580ca393b5Timo Sirainen If locking timed out, returns -1 and errno = EAGAIN. */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenint file_dotlock_open(const struct dotlock_settings *set, const char *path,
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainen/* Replaces the file dotlock protects with the dotlock file itself. */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenint file_dotlock_replace(struct dotlock **dotlock,
933a8cc7033e8a9bb7a1c7630fbc786b914f1510Timo Sirainen/* Update dotlock's mtime. If you're keeping the dotlock for a long time,
933a8cc7033e8a9bb7a1c7630fbc786b914f1510Timo Sirainen it's a good idea to update it once in a while so others won't override it.
933a8cc7033e8a9bb7a1c7630fbc786b914f1510Timo Sirainen If the timestamp is less than a second old, it's not updated. */
933a8cc7033e8a9bb7a1c7630fbc786b914f1510Timo Sirainenint file_dotlock_touch(struct dotlock *dotlock);
d3dee2335ff3b0943085256fe341c2c13a678c4fTimo Sirainen/* Returns the lock file path. */
d3dee2335ff3b0943085256fe341c2c13a678c4fTimo Sirainenconst char *file_dotlock_get_lock_path(struct dotlock *dotlock);