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. */
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. */
8da095519878426b012058e6f331a669f327f47fTimo Sirainen /* Flush NFS attribute cache before stating files. */
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,
6cb2c6ecddcdbeac9e6c73a292244747e12a793eTimo Sirainen/* Delete the dotlock file. Returns 1 if successful, 0 if the file had already
6cb2c6ecddcdbeac9e6c73a292244747e12a793eTimo Sirainen been deleted or reused by someone else, -1 if I/O error. */
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,
6f7617d14ae27473f55628fbdad2af2d75b909a9Timo Sirainen/* Like file_dotlock_open(), but use the given file permissions. */
6f7617d14ae27473f55628fbdad2af2d75b909a9Timo Sirainenint file_dotlock_open_mode(const struct dotlock_settings *set, const char *path,
e156adefc1260d31a145df2f5e9b3c82050d4163Timo Sirainenint file_dotlock_open_group(const struct dotlock_settings *set, const char *path,
e156adefc1260d31a145df2f5e9b3c82050d4163Timo Sirainen mode_t mode, gid_t gid, const char *gid_origin,
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);
021665c0147e5c655efb2c3f0eff2549b31f6b5aTimo Sirainen/* Returns TRUE if the lock is still ok, FALSE if it's been overridden. */
021665c0147e5c655efb2c3f0eff2549b31f6b5aTimo Sirainenbool file_dotlock_is_locked(struct dotlock *dotlock);
d3dee2335ff3b0943085256fe341c2c13a678c4fTimo Sirainen/* Returns the lock file path. */
d3dee2335ff3b0943085256fe341c2c13a678c4fTimo Sirainenconst char *file_dotlock_get_lock_path(struct dotlock *dotlock);