Changed to use the proper POSIX locking function if POSIX_FILE_LOCKS is
authorTheodore Tso <tytso@mit.edu>
Wed, 22 Sep 1993 02:31:48 +0000 (02:31 +0000)
committerTheodore Tso <tytso@mit.edu>
Wed, 22 Sep 1993 02:31:48 +0000 (02:31 +0000)
defined.  (i.e., fcntl instead of lockf).

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2648 dc483132-0cff-0310-8789-dd5450dbe970

src/slave/kprop.c

index fbabf1a7b674e6a427936e763e5cfdf929d0cb98..c53f9deabdca57b296efd9b4f73fb0c3cd889847 100644 (file)
@@ -38,6 +38,9 @@ static char rcsid_kprop_c[] =
 #include <krb5/los-proto.h>
 #include <com_err.h>
 #include <errno.h>
+#ifdef POSIX_FILE_LOCKS
+#include <fcntl.h>
+#endif
 
 #include <stdio.h>
 #include <ctype.h>
@@ -409,6 +412,9 @@ open_database(data_fn, size)
        struct stat     stbuf, stbuf_ok;
        char            *data_ok_fn;
        static char ok[] = ".dump_ok";
+#ifdef POSIX_FILE_LOCKS
+       struct flock lock_arg;
+#endif
 
        if ((fd = open(data_fn, O_RDONLY)) < 0) {
                com_err(progname, errno, "while trying to open %s",
@@ -417,8 +423,11 @@ open_database(data_fn, size)
        }
        
 #ifdef POSIX_FILE_LOCKS
-       if (lockf(fd, LOCK_SH | LOCK_NB, 0) < 0) {
-               if (errno == EWOULDBLOCK || errno == EAGAIN)
+       lock_arg.l_whence = 0;
+       lock_arg.l_start = 0;
+       lock_arg.l_len = 0;
+       if (fcntl(fd, F_SETLK, &lock_arg) == -1) {
+               if (errno == EACCES || errno == EAGAIN)
                        com_err(progname, 0, "database locked");
                else
                        com_err(progname, errno, "while trying to flock %s",