3 # AMANDA_SETUP_FILE_LOCKING
7 # Set up file locking support. Four locking mechanisms are available:
8 # POSIX_FCNTL - use fcntl(). The full job.
9 # FLOCK - use flock(). Does just as well.
10 # LOCKF - use lockf(). Only handles advisory, exclusive,
11 # blocking file locks as used by Amanda.
12 # LNLOCK - Home brew exclusive, blocking file lock.
14 # For the chosen method, WANT_AMFLOCK_mech is defined and set up as an
15 # AM_CONDITIONAL. Also, LOCKING, which contains the mechanism, is substituted.
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.
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"
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"
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"
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"
139 AM_CONDITIONAL(WANT_AMFLOCK_LNLOCK, test x"$WANT_AMFLOCK_LNLOCK" = x"yes")
141 if test x"$LOCKING" = "no"; then
142 # this shouldn't happen, and is *bad* if it does
143 AC_MSG_ERROR([*** No working file locking capability found!])