From: Theodore Tso Date: Tue, 3 Nov 1998 21:27:35 +0000 (+0000) Subject: lock_file.c (krb5_lock_file): Move the flock() fallback code from X-Git-Tag: krb5-1.1-beta1~507 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=369dc3be4cd7fa48907da18ab07517ba9df72771;p=krb5.git lock_file.c (krb5_lock_file): Move the flock() fallback code from fcc_maybe.c into krb5_lock_file(). This works around the bug that certain lossy operating systems (mainly from our good friends at SunSoft) do not support POSIX_FILE_LOCKS on all filesystems (namely tmpfs) but do support flock on those filesystems. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11009 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 84f0dec67..c8ea14f65 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,12 @@ +1998-10-31 Theodore Ts'o + + * lock_file.c (krb5_lock_file): Move the flock() fallback code + from fcc_maybe.c into krb5_lock_file(). This works around + the bug that certain lossy operating systems (mainly from + our good friends at SunSoft) do not support + POSIX_FILE_LOCKS on all filesystems (namely tmpfs) but do + support flock on those filesystems. + 1998-10-27 Marc Horowitz * c_ustime.c, localaddr.c: moved here from lib/crypto diff --git a/src/lib/krb5/os/lock_file.c b/src/lib/krb5/os/lock_file.c index edc4d88d2..eb8e76183 100644 --- a/src/lib/krb5/os/lock_file.c +++ b/src/lib/krb5/os/lock_file.c @@ -1,7 +1,7 @@ /* * lib/krb5/os/lock_file.c * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990, 1998 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -35,20 +35,23 @@ #include #endif -#ifdef POSIX_FILE_LOCKS #include + +#ifdef POSIX_FILE_LOCKS #include -#define SHARED_LOCK F_RDLCK -#define EXCLUSIVE_LOCK F_WRLCK -#define UNLOCK_LOCK F_UNLCK -#else -#include -#define SHARED_LOCK LOCK_SH -#define EXCLUSIVE_LOCK LOCK_EX -#define UNLOCK_LOCK LOCK_UN #endif -extern int errno; +#ifdef HAVE_FLOCK +#ifndef sysvimp +#include +#endif +#else +#ifndef LOCK_SH +#define LOCK_SH 0 +#define LOCK_EX 0 +#define LOCK_UN 0 +#endif +#endif /*ARGSUSED*/ krb5_error_code @@ -57,26 +60,34 @@ krb5_lock_file(context, fd, mode) int fd; int mode; { + int lock_flag = -1; + krb5_error_code retval = 0; #ifdef POSIX_FILE_LOCKS int lock_cmd = F_SETLKW; static struct flock flock_zero; struct flock lock_arg; + lock_arg = flock_zero; -#define lock_flag lock_arg.l_type - lock_flag = -1; -#else - int lock_flag = -1; #endif switch (mode & ~KRB5_LOCKMODE_DONTBLOCK) { case KRB5_LOCKMODE_SHARED: - lock_flag = SHARED_LOCK; +#ifdef POSIX_FILE_LOCKS + lock_arg.l_type = F_RDLCK; +#endif + lock_flag = LOCK_SH; break; case KRB5_LOCKMODE_EXCLUSIVE: - lock_flag = EXCLUSIVE_LOCK; +#ifdef POSIX_FILE_LOCKS + lock_arg.l_type = F_WRLCK; +#endif + lock_flag = LOCK_EX; break; case KRB5_LOCKMODE_UNLOCK: - lock_flag = UNLOCK_LOCK; +#ifdef POSIX_FILE_LOCKS + lock_arg.l_type = F_UNLCK; +#endif + lock_flag = LOCK_UN; break; } @@ -86,7 +97,8 @@ krb5_lock_file(context, fd, mode) if (mode & KRB5_LOCKMODE_DONTBLOCK) { #ifdef POSIX_FILE_LOCKS lock_cmd = F_SETLK; -#else +#endif +#ifdef HAVE_FLOCK lock_flag |= LOCK_NB; #endif } @@ -99,13 +111,18 @@ krb5_lock_file(context, fd, mode) if (errno == EACCES || errno == EAGAIN) /* see POSIX/IEEE 1003.1-1988, 6.5.2.4 */ return(EAGAIN); - return(errno); + if (errno != EINVAL) /* Fall back to flock if we get EINVAL */ + return(errno); + retval = errno; } -#else +#endif + +#ifdef HAVE_FLOCK if (flock(fd, lock_flag) == -1) - return(errno); + retval = errno; #endif - return 0; + + return retval; } #else /* MSDOS or Macintosh */