00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "db_config.h"
00011
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014
00015 #include <fcntl.h>
00016 #include <string.h>
00017 #endif
00018
00019 #include "db_int.h"
00020
00021
00022
00023
00024
00025
00026
00027 int
00028 __os_fdlock(dbenv, fhp, offset, acquire, nowait)
00029 DB_ENV *dbenv;
00030 DB_FH *fhp;
00031 int acquire, nowait;
00032 off_t offset;
00033 {
00034 struct flock fl;
00035 int ret;
00036
00037 DB_ASSERT(F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1);
00038
00039 #ifdef HAVE_FCNTL
00040 fl.l_start = offset;
00041 fl.l_len = 1;
00042 fl.l_type = acquire ? F_WRLCK : F_UNLCK;
00043 fl.l_whence = SEEK_SET;
00044
00045 RETRY_CHK_EINTR_ONLY(
00046 (fcntl(fhp->fd, nowait ? F_SETLK : F_SETLKW, &fl)), ret);
00047
00048 if (ret != 0 && ret != EACCES && ret != EAGAIN)
00049 __db_err(dbenv, "fcntl: %s", strerror(ret));
00050 return (ret);
00051 #else
00052 __db_err(dbenv,
00053 "advisory file locking unavailable: %s", strerror(DB_OPNOTSUP));
00054 return (DB_OPNOTSUP);
00055 #endif
00056 }