Commit | Line | Data |
---|---|---|
5230d901 AD |
1 | ?RCS: $Id: d_fcntl_can_lock.U,v$ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 2000, Andrew Dougherty | |
4 | ?RCS: | |
5 | ?RCS: You may distribute under the terms of either the GNU General Public | |
6 | ?RCS: License or the Artistic License, as specified in the README file. | |
7 | ?RCS: | |
8 | ?RCS: $Log: d_fcntl_can_lock.U,v $ | |
9 | ?RCS: | |
2cb64bf6 | 10 | ?MAKE:d_fcntl_can_lock: d_fcntl Compile Setvar cat rm_try run signal_t i_stdlib |
5230d901 AD |
11 | ?MAKE: -pick add $@ %< |
12 | ?S:d_fcntl_can_lock: | |
13 | ?S: This variable conditionally defines the FCNTL_CAN_LOCK symbol | |
14 | ?S: and indicates whether file locking with fcntl() works. | |
15 | ?S:. | |
16 | ?C:FCNTL_CAN_LOCK: | |
17 | ?C: This symbol, if defined, indicates that fcntl() can be used | |
18 | ?C: for file locking. Normally on Unix systems this is defined. | |
19 | ?C: It may be undefined on VMS. | |
20 | ?C:. | |
21 | ?H:#$d_fcntl_can_lock FCNTL_CAN_LOCK /**/ | |
22 | ?H:. | |
0065f4af | 23 | ?F:!try |
5230d901 | 24 | ?LINT: set d_fcntl_can_lock |
5230d901 AD |
25 | ?X: fcntl may not be fully functional. As of November 2000, on VMS and |
26 | ?X: DOS/DJGPP, fctnl-based locking doesn't work. | |
27 | ?X: Thanks to Craig A. Berry <craig.berry@psinetcs.com> for this test. | |
5230d901 | 28 | : See if fcntl-based locking works. |
0065f4af | 29 | echo " " |
9e3a169e | 30 | $cat >try.c <<EOCP |
1273bb5e JH |
31 | #$i_stdlib I_STDLIB |
32 | #ifdef I_STDLIB | |
5230d901 | 33 | #include <stdlib.h> |
1273bb5e | 34 | #endif |
5230d901 AD |
35 | #include <unistd.h> |
36 | #include <fcntl.h> | |
9e3a169e | 37 | #include <signal.h> |
dc952a08 | 38 | $signal_t blech(int x) { exit(3); } |
5230d901 AD |
39 | int main() { |
40 | #if defined(F_SETLK) && defined(F_SETLKW) | |
41 | struct flock flock; | |
42 | int retval, fd; | |
43 | fd = open("try.c", O_RDONLY); | |
44 | flock.l_type = F_RDLCK; | |
45 | flock.l_whence = SEEK_SET; | |
46 | flock.l_start = flock.l_len = 0; | |
9e3a169e JH |
47 | signal(SIGALRM, blech); |
48 | alarm(10); | |
5230d901 AD |
49 | retval = fcntl(fd, F_SETLK, &flock); |
50 | close(fd); | |
51 | (retval < 0 ? exit(2) : exit(0)); | |
52 | #else | |
53 | exit(2); | |
54 | #endif | |
55 | } | |
56 | EOCP | |
57 | echo "Checking if fcntl-based file locking works... " | |
58 | case "$d_fcntl" in | |
59 | "$define") | |
60 | set try | |
61 | if eval $compile_ok; then | |
0f00356b | 62 | if $run ./try; then |
5230d901 AD |
63 | echo "Yes, it seems to work." |
64 | val="$define" | |
65 | else | |
66 | echo "Nope, it didn't work." | |
67 | val="$undef" | |
9e3a169e JH |
68 | case "$?" in |
69 | 3) $cat >&4 <<EOM | |
70 | *** | |
71 | *** I had to forcibly timeout from fcntl(..., F_SETLK, ...). | |
72 | *** This is (almost) impossible. | |
73 | *** If your NFS lock daemons are not feeling well, something like | |
74 | *** this may happen, please investigate. Cannot continue, aborting. | |
75 | *** | |
76 | EOM | |
77 | exit 1 | |
78 | ;; | |
79 | esac | |
5230d901 AD |
80 | fi |
81 | else | |
82 | echo "I'm unable to compile the test program, so I'll assume not." | |
83 | val="$undef" | |
84 | fi | |
85 | ;; | |
86 | *) val="$undef"; | |
87 | echo "Nope, since you don't even have fcntl()." | |
88 | ;; | |
89 | esac | |
90 | set d_fcntl_can_lock | |
91 | eval $setvar | |
2cb64bf6 | 92 | $rm_try |
5230d901 | 93 |