3 # AMANDA_SETUP_FILE_LOCKING
7 # Set up file locking support. Four types of locking are available:
8 # USE_POSIX_FCNTL - use fcntl(). The full job.
9 # USE_FLOCK - use flock(). Does just as well.
10 # USE_LOCKF - use lockf(). Only handles advisory, exclusive,
11 # blocking file locks as used by Amanda.
12 # USE_LNLOCK - Home brew exclusive, blocking file lock.
13 # <none> - No locking available. User beware!
14 # One of given symbols are defined if the method is discovered to
15 # be available; the methods are searched in the above order.
17 AC_DEFUN([AMANDA_SETUP_FILE_LOCKING],
27 # find a working file-locking mechanism.
28 # Note: these all use AC_TRY_LINK to make sure that we can compile
29 # and link each variant. They do not try to test the variants --
30 # that is left to runtime.
31 WORKING_FILE_LOCK="no"
35 [whether POSIX locking (with fcntl(2)) is available],
36 amanda_cv_posix_filelocking,
40 # include <sys/types.h>
51 lock.l_type = F_RDLCK;
53 lock.l_whence = SEEK_CUR;
55 return fcntl(1, F_SETLK, &lock);
57 amanda_cv_posix_filelocking="yes"
59 amanda_cv_posix_filelocking="no"
62 if test "x$amanda_cv_posix_filelocking" = xyes; then
63 AC_DEFINE(WANT_AMFLOCK_POSIX,1,[Define to use POSIX (fcntl()) for file locking])
64 WANT_AMFLOCK_POSIX="yes"
65 WORKING_FILE_LOCK="yes"
67 AM_CONDITIONAL(WANT_AMFLOCK_POSIX, test x"$WANT_AMFLOCK_POSIX" = x"yes")
69 # check flock-based (BSD) locking
71 [whether flock locking is available],
72 amanda_cv_flock_filelocking,
76 # include <sys/file.h>
79 return flock(1, LOCK_SH);
81 amanda_cv_flock_filelocking="yes"
83 amanda_cv_flock_filelocking="no"
86 if test "x$amanda_cv_flock_filelocking" = xyes; then
87 AC_DEFINE(WANT_AMFLOCK_FLOCK,1,[Define to use flock(2) for file locking])
88 WANT_AMFLOCK_FLOCK="yes"
89 WORKING_FILE_LOCK="yes"
91 AM_CONDITIONAL(WANT_AMFLOCK_FLOCK, test x"$WANT_AMFLOCK_FLOCK" = x"yes")
93 # check lockf-based (SVR2, SVR3, SVR4) locking
95 [whether lockf(3) locking is available],
96 amanda_cv_lockf_filelocking,
103 return lockf(1, F_LOCK, 0);
105 amanda_cv_lockf_filelocking="yes"
107 amanda_cv_lockf_filelocking="no"
110 if test "x$amanda_cv_lockf_filelocking" = xyes; then
111 AC_DEFINE(WANT_AMFLOCK_LOCKF,1,[Define to use lockf(3) for file locking.])
112 WANT_AMFLOCK_LOCKF="yes"
113 WORKING_FILE_LOCK="yes"
115 AM_CONDITIONAL(WANT_AMFLOCK_LOCKF, test x"$WANT_AMFLOCK_LOCKF" = x"yes")
117 # check our homebrew hardlink-based locking (requires hardlinks)
119 [whether link(2) is available for locking],
120 amanda_cv_lnlock_filelocking,
127 return link("/tmp/foo", "/tmp/bar");
129 amanda_cv_lnlock_filelocking="yes"
131 amanda_cv_lnlock_filelocking="no"
134 if test "x$amanda_cv_lnlock_filelocking" = xyes; then
135 AC_DEFINE(WANT_AMFLOCK_LNLOCK,1,[Define to use link(2) to emulate file locking.])
136 WANT_AMFLOCK_LNLOCK="yes"
137 WORKING_FILE_LOCK="yes"
139 AM_CONDITIONAL(WANT_AMFLOCK_LNLOCK, test x"$WANT_AMFLOCK_LNLOCK" = x"yes")
141 if test x"$WORKING_FILE_LOCK" = "no"; then
142 # this shouldn't happen, and is *bad* if it does
143 AC_MSG_ERROR([*** No working file locking capability found!])