* configure.in: check for HAVE_FLOCK, since we may need to use
authorMark Eichin <eichin@mit.edu>
Tue, 21 Feb 1995 23:51:47 +0000 (23:51 +0000)
committerMark Eichin <eichin@mit.edu>
Tue, 21 Feb 1995 23:51:47 +0000 (23:51 +0000)
both flock and fcntl.
* fcc_maybe.c: try fcntl lock, if we get EINVAL specifically, fall
back to flock (if we have it.)

Now kinit et. al. "just work" on sunos and solaris, even if you use tmpfs.
(tested on sunos, the solaris build has recently broken elsewhere...)

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

src/lib/krb5/ccache/file/ChangeLog
src/lib/krb5/ccache/file/configure.in
src/lib/krb5/ccache/file/fcc_maybe.c

index f092634c912c335d13701df239098f2ace046685..4fa03c711480d804d99682d5f254cffc73e42d50 100644 (file)
@@ -1,3 +1,10 @@
+Tue Feb 21 16:14:25 1995  Mark Eichin  (eichin@cygnus.com)
+
+       * configure.in: check for HAVE_FLOCK, since we may need to use
+       both flock and fcntl.
+       * fcc_maybe.c: try fcntl lock, if we get EINVAL specifically, fall
+       back to flock (if we have it.)
+
 Fri Jan 27 00:49:36 1995  Chris Provenzano (proven@mit.edu)
 
         * Fix fcc_read.c (krb5_fcc_read_authdatum()) krb5_authdatatype
index 20561dac0163336ac32f70594bfa58476d77e1ab..a0d75eaaf01f0b20bccaa77b20bc9743ca18fd62 100644 (file)
@@ -4,6 +4,7 @@ AC_SET_BUILDTOP
 CONFIG_RULES
 ISODE_DEFS
 AC_HAVE_HEADERS(unistd.h)
+AC_FUNC_CHECK(flock,AC_DEFINE(HAVE_FLOCK))
 SubdirLibraryRule([${OBJS}])
 KRB_INCLUDE
 V5_AC_OUTPUT_MAKEFILE
index e72e812cc0af01c33d2ae47ce010d3e538770d7a..9e4314c47638925b11877b993257fb4623b43ffb 100644 (file)
@@ -44,30 +44,26 @@ int krb5_fcc_default_format = KRB5_FCC_DEFAULT_FVNO;
 #include <krb5/los-proto.h>
 #include <stdio.h>
 
+#define LOCK_IT 0
+#define UNLOCK_IT 1
+
+/* Under SunOS 4 and SunOS 5 and possibly other operating systems, having
+   POSIX fcntl locks doesn't mean that they work on every filesystem. If we
+   get EINVAL, try flock (if we have it) since that might work... */
+
 #ifdef POSIX_FILE_LOCKS
+static krb5_error_code fcc_lock_file_posix PROTOTYPE((krb5_fcc_data *, int, int));
+
 #ifndef unicos61
 #include <fcntl.h>
 #endif /* unicos61 */
+
 #define SHARED_LOCK    F_RDLCK
 #define EXCLUSIVE_LOCK F_WRLCK
 #define UNLOCK_LOCK    F_UNLCK
-#else /* !POSIX_FILE_LOCKS */
-#ifndef sysvimp
-#include <sys/file.h>
-#endif /* sysvimp */
-#define SHARED_LOCK    LOCK_SH
-#define EXCLUSIVE_LOCK LOCK_EX
-#define UNLOCK_LOCK    LOCK_UN
-#endif /* POSIX_FILE_LOCKS */
-
-#define LOCK_IT 0
-#define UNLOCK_IT 1
-
-static krb5_error_code fcc_lock_file PROTOTYPE((krb5_fcc_data *,
-                                               int, int));
 
 static krb5_error_code
-fcc_lock_file(data, fd, lockunlock)
+fcc_lock_file_posix(data, fd, lockunlock)
 krb5_fcc_data *data;
 int fd;
 int lockunlock;
@@ -75,14 +71,10 @@ int lockunlock;
     /* XXX need to in-line lock_file.c here, but it's sort-of OK since
        we're already unix-dependent for file descriptors */
 
-#ifdef POSIX_FILE_LOCKS
     int lock_cmd = F_SETLKW;
     struct flock lock_arg;
 #define lock_flag lock_arg.l_type
     lock_flag = -1;
-#else
-    int lock_flag = -1;
-#endif
 
     if (lockunlock == LOCK_IT)
        switch (data->mode) {
@@ -100,7 +92,6 @@ int lockunlock;
     if (lock_flag == -1)
        return(KRB5_LIBOS_BADLOCKFLAG);
 
-#ifdef POSIX_FILE_LOCKS
     lock_arg.l_whence = 0;
     lock_arg.l_start = 0;
     lock_arg.l_len = 0;
@@ -110,13 +101,87 @@ int lockunlock;
            return(EAGAIN);
        return(errno);
     }
-#else
+    return 0;
+}
+#undef lock_flag
+
+#undef SHARED_LOCK
+#undef EXCLUSIVE_LOCK
+#undef UNLOCK_LOCK
+
+#endif /* POSIX_FILE_LOCKS */
+
+#ifdef HAVE_FLOCK
+
+#ifndef sysvimp
+#include <sys/file.h>
+#endif /* sysvimp */
+
+#define SHARED_LOCK    LOCK_SH
+#define EXCLUSIVE_LOCK LOCK_EX
+#define UNLOCK_LOCK    LOCK_UN
+
+static krb5_error_code fcc_lock_file_flock PROTOTYPE((krb5_fcc_data *, int, int));
+static krb5_error_code
+fcc_lock_file_flock(data, fd, lockunlock)
+krb5_fcc_data *data;
+int fd;
+int lockunlock;
+{
+    /* XXX need to in-line lock_file.c here, but it's sort-of OK since
+       we're already unix-dependent for file descriptors */
+
+    int lock_flag = -1;
+
+    if (lockunlock == LOCK_IT)
+       switch (data->mode) {
+       case FCC_OPEN_RDONLY:
+           lock_flag = SHARED_LOCK;
+           break;
+       case FCC_OPEN_RDWR:
+       case FCC_OPEN_AND_ERASE:
+           lock_flag = EXCLUSIVE_LOCK;
+           break;
+       }
+    else
+       lock_flag = UNLOCK_LOCK;
+
+    if (lock_flag == -1)
+       return(KRB5_LIBOS_BADLOCKFLAG);
+
     if (flock(fd, lock_flag) == -1)
        return(errno);
-#endif
     return 0;
 }
 
+#undef SHARED_LOCK
+#undef EXCLUSIVE_LOCK
+#undef UNLOCK_LOCK
+
+#endif HAVE_FLOCK
+
+static krb5_error_code fcc_lock_file PROTOTYPE((krb5_fcc_data *, int, int));
+static krb5_error_code
+fcc_lock_file(data, fd, lockunlock)
+krb5_fcc_data *data;
+int fd;
+int lockunlock;
+{
+  krb5_error_code st;
+#ifdef POSIX_FILE_LOCKS
+  st = fcc_lock_file_posix(data, fd, lockunlock);
+  if (st != EINVAL) {
+    return st;
+  }
+#endif /* POSIX_FILE_LOCKS */
+
+#ifdef HAVE_FLOCK
+  return fcc_lock_file_flock(data, fd, lockunlock);
+#else
+  return st;
+#endif
+}
+
 krb5_error_code
 krb5_fcc_close_file (context, id)
    krb5_context context;