file-lock.h revision 9e86ad9eb313004cd4c8b5427daeb4c241b57af6
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen#ifndef __FILE_LOCK_H
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#define __FILE_LOCK_H
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen#include <unistd.h>
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen#include <fcntl.h>
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#define DEFAULT_LOCK_TIMEOUT 120
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen/* Lock whole file descriptor. Returns 1 if successful, 0 if lock failed,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen or -1 if error. lock_type is F_WRLCK, F_RDLCK or F_UNLCK. */
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainenint file_try_lock(int fd, int lock_type);
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen/* Lock whole file descriptor. Returns 1 if successful, 0 if timeout or
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen -1 if error. When returning 0, errno is also set to EAGAIN.
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen NOTE: timeout uses SIGALRM and resets it at the end. */
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainenint file_wait_lock(int fd, int lock_type, unsigned int timeout);
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#endif
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen