This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[metaconfig.git] / U / perl / d_fcntl_can_lock.U
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:
10 ?MAKE:d_fcntl_can_lock: d_fcntl Compile Setvar cat rm_try run signal_t i_stdlib
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:.
23 ?F:!try
24 ?LINT: set d_fcntl_can_lock
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.
28 : See if fcntl-based locking works.
29 echo " "
30 $cat >try.c <<EOCP
31 #$i_stdlib I_STDLIB
32 #ifdef I_STDLIB
33 #include <stdlib.h>
34 #endif
35 #include <unistd.h>
36 #include <fcntl.h>
37 #include <signal.h>
38 $signal_t blech(int x) { exit(3); }
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;
47      signal(SIGALRM, blech);
48      alarm(10);
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
62                 if $run ./try; then
63                         echo "Yes, it seems to work."
64                         val="$define"
65                 else
66                         echo "Nope, it didn't work."
67                         val="$undef"
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
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
92 $rm_try
93