file-lock.h revision f1243d7759a3dddc1c3eaf7eda8a153c8ef0112b
6e77746e501c2b45850b1c530836058ed75e09eeTimo Sirainen/* Parse lock method from given string. Returns TRUE if ok,
6e77746e501c2b45850b1c530836058ed75e09eeTimo Sirainen FALSE if name is unknown. */
6e77746e501c2b45850b1c530836058ed75e09eeTimo Sirainenbool file_lock_method_parse(const char *name, enum file_lock_method *method_r);
8c8f7ac580b661aee3d8b8dd37df4a9b41c77000Timo Sirainen/* Convert lock method to string. */
8c8f7ac580b661aee3d8b8dd37df4a9b41c77000Timo Sirainenconst char *file_lock_method_to_str(enum file_lock_method method);
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen/* Lock the file. Returns 1 if successful, 0 if file is already locked,
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen or -1 if error. lock_type is F_WRLCK or F_RDLCK. */
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainenint file_try_lock(int fd, const char *path, int lock_type,
0dc7891233a973829f00371b27810f849b987c66Timo Sirainen/* Like file_try_lock(), but return the error message as a string instead
0dc7891233a973829f00371b27810f849b987c66Timo Sirainen of logging it. Also when returning 0 an error message is returned. */
0dc7891233a973829f00371b27810f849b987c66Timo Sirainenint file_try_lock_error(int fd, const char *path, int lock_type,
0dc7891233a973829f00371b27810f849b987c66Timo Sirainen struct file_lock **lock_r, const char **error_r);
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen/* Like lock_try_lock(), but return 0 only after having tried to lock for
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen timeout_secs. */
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainenint file_wait_lock(int fd, const char *path, int lock_type,
0dc7891233a973829f00371b27810f849b987c66Timo Sirainen/* Like file_wait_lock(), but return the error message as a string instead
0dc7891233a973829f00371b27810f849b987c66Timo Sirainen of logging it. Also when returning 0 an error message is returned. */
0dc7891233a973829f00371b27810f849b987c66Timo Sirainenint file_wait_lock_error(int fd, const char *path, int lock_type,
0dc7891233a973829f00371b27810f849b987c66Timo Sirainen struct file_lock **lock_r, const char **error_r);
cac6b8b1a2bcf672fe43d3fb91a7278877f8cf09Timo Sirainen/* Change the lock type. WARNING: This isn't an atomic operation!
cac6b8b1a2bcf672fe43d3fb91a7278877f8cf09Timo Sirainen The result is the same as file_unlock() + file_try_lock(). */
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainenint file_lock_try_update(struct file_lock *lock, int lock_type);
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen/* Unlock and free the lock. */
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen/* Free the lock without unlocking it (because you're closing the fd anyway). */
f1243d7759a3dddc1c3eaf7eda8a153c8ef0112bTimo Sirainen/* Returns the path given as parameter to file_*lock*(). */
f1243d7759a3dddc1c3eaf7eda8a153c8ef0112bTimo Sirainenconst char *file_lock_get_path(struct file_lock *lock);
1107c86ff3fa4f29796c2e76134b78d0b4a0db50Timo Sirainen/* Returns human-readable string containing the process that has the file
1107c86ff3fa4f29796c2e76134b78d0b4a0db50Timo Sirainen currently locked. Returns "" if unknown, otherwise " (string)". */
1107c86ff3fa4f29796c2e76134b78d0b4a0db50Timo Sirainenconst char *file_lock_find(int lock_fd, enum file_lock_method lock_method,
4a7e04d325db0c03f575f98f045246fceb0de279Timo Sirainen/* Track the duration of a lock wait. */
f83fd83f9c6708d198748e714aa947cad9362c02Timo Sirainenvoid file_lock_wait_end(const char *lock_name);
4a7e04d325db0c03f575f98f045246fceb0de279Timo Sirainen/* Return how many microseconds has been spent on lock waiting. */