Bugzilla bug #62457: set the flock structure correctly and use fcntl
authorwtc%netscape.com
Fri, 22 Dec 2000 06:02:52 +0000
changeset 1645 cad5533d16fb2b7e10cf7cb73ef13d844085d837
parent 1642 3f348f6edfd3a9098fa5d4daea2cd7e0ad3648df
child 1647 3e1aeaa37ef2671bbc720e62edb1300152c20b4e
push idunknown
push userunknown
push dateunknown
bugs62457
Bugzilla bug #62457: set the flock structure correctly and use fcntl file locking on AIX 4.3, HP-UX 11.00, IRIX, Linux, OSF1 V4.0, and Solaris. Modified Files: AIX.mk, HP-UX.mk, IRIX.mk, Linux.mk, OSF1.mk, SunOS5.mk, and unix.c.
config/AIX.mk
config/HP-UX.mk
config/IRIX.mk
config/Linux.mk
config/OSF1.mk
config/SunOS5.mk
pr/src/md/unix/unix.c
--- a/config/AIX.mk
+++ b/config/AIX.mk
@@ -129,16 +129,20 @@ OS_CFLAGS	+= -DAIX4_3
 endif
 endif
 
 # Have the socklen_t data type
 ifeq ($(OS_RELEASE),4.3)
 OS_CFLAGS	+= -DHAVE_SOCKLEN_T
 endif
 
+ifneq (,$(filter-out 3.2 4.1 4.2,$(OS_RELEASE)))
+OS_CFLAGS	+= -DHAVE_FCNTL_FILE_LOCKING
+endif
+
 ifeq (,$(filter-out 4.2 4.3,$(OS_RELEASE)))
 # On these OS revisions, localtime_r() is declared if _THREAD_SAFE
 # is defined.
 ifneq ($(CLASSIC_NSPR),1)
 OS_CFLAGS	+= -DHAVE_POINTER_LOCALTIME_R
 endif
 endif
 
--- a/config/HP-UX.mk
+++ b/config/HP-UX.mk
@@ -138,17 +138,17 @@ ifeq ($(OS_RELEASE),B.11.00)
 		ifeq ($(USE_64), 1)
 			OS_CFLAGS       += +DA2.0W +DS2.0
 			COMPILER_TAG    = _64
 		else
 			OS_CFLAGS       += +DAportable +DS2.0
 			COMPILER_TAG    = _32
 		endif
 	endif
-OS_CFLAGS		+= -DHPUX10 -DHPUX11 -D_LARGEFILE64_SOURCE -D_PR_HAVE_OFF64_T
+OS_CFLAGS		+= -DHPUX10 -DHPUX11 -D_LARGEFILE64_SOURCE -D_PR_HAVE_OFF64_T -DHAVE_FCNTL_FILE_LOCKING
 DEFAULT_IMPL_STRATEGY = _PTH
 endif
 
 ifeq ($(DEFAULT_IMPL_STRATEGY),_EMU)
 CLASSIC_NSPR = 1
 endif
 
 ifeq ($(DEFAULT_IMPL_STRATEGY),_PTH)
--- a/config/IRIX.mk
+++ b/config/IRIX.mk
@@ -111,17 +111,17 @@ else
 				COMPILER_TAG = _o32
 			endif
 		endif
 	else
 		ODD_CFLAGS += -xgot
 	endif
 endif
 
-ODD_CFLAGS		+= -DSVR4 -DIRIX
+ODD_CFLAGS		+= -DSVR4 -DIRIX -DHAVE_FCNTL_FILE_LOCKING
 
 CPU_ARCH		= mips
 
 RANLIB			= /bin/true
 
 # For purify
 # XXX: should always define _SGI_MP_SOURCE
 NOMD_OS_CFLAGS		= $(ODD_CFLAGS) -D_SGI_MP_SOURCE
--- a/config/Linux.mk
+++ b/config/Linux.mk
@@ -77,17 +77,17 @@ CPU_ARCH_TAG		= _$(CPU_ARCH)
 CC			= gcc
 CCC			= g++
 RANLIB			= ranlib
 
 OS_INCLUDES		=
 G++INCLUDES		= -I/usr/include/g++
 
 PLATFORM_FLAGS		= -ansi -Wall -pipe -DLINUX -Dlinux
-PORT_FLAGS		= -D_POSIX_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -DHAVE_STRERROR
+PORT_FLAGS		= -D_POSIX_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -DHAVE_STRERROR -DHAVE_FCNTL_FILE_LOCKING
 
 OS_CFLAGS		= $(DSO_CFLAGS) $(PLATFORM_FLAGS) $(PORT_FLAGS)
 
 ######################################################################
 # Version-specific stuff
 ######################################################################
 
 ifeq ($(CPU_ARCH),alpha)
--- a/config/OSF1.mk
+++ b/config/OSF1.mk
@@ -91,16 +91,20 @@ endif
 NON_LD_FLAGS		= -ieee_with_inexact
 
 OS_CFLAGS		= -DOSF1 -D_REENTRANT
 
 ifneq (,$(filter-out V2.0 V3.2,$(OS_RELEASE)))
 OS_CFLAGS		+= -DOSF1_HAVE_MACHINE_BUILTINS_H
 endif
 
+ifneq (,$(filter-out V2.0 V3.2,$(OS_RELEASE)))
+OS_CFLAGS		+= -DHAVE_FCNTL_FILE_LOCKING
+endif
+
 ifeq (,$(filter-out V2.0 V3.2,$(OS_RELEASE)))
 OS_CFLAGS		+= -DHAVE_INT_LOCALTIME_R
 else
 OS_CFLAGS		+= -DHAVE_POINTER_LOCALTIME_R
 endif
 
 ifeq (,$(filter-out V4.0%,$(OS_RELEASE)))
 OS_CFLAGS		+= -DOSF1V4_MAP_PRIVATE_BUG
--- a/config/SunOS5.mk
+++ b/config/SunOS5.mk
@@ -104,17 +104,17 @@ endif
 endif
 COMPILER_TAG		= _64
 else
 COMPILER_TAG		= _32
 endif
 
 RANLIB			= echo
 
-OS_DEFINES		= -DSVR4 -DSYSV -D__svr4 -D__svr4__ -DSOLARIS
+OS_DEFINES		= -DSVR4 -DSYSV -D__svr4 -D__svr4__ -DSOLARIS -DHAVE_FCNTL_FILE_LOCKING
 
 ifeq ($(OS_TEST),i86pc)
 CPU_ARCH		= x86
 OS_DEFINES		+= -Di386
 # The default debug format, DWARF (-g), is not supported by gcc
 # on i386-ANY-sysv4/solaris, but the stabs format is.  It is
 # assumed that the Solaris assembler /usr/ccs/bin/as is used.
 # If your gcc uses GNU as, you do not need the -Wa,-s option.
--- a/pr/src/md/unix/unix.c
+++ b/pr/src/md/unix/unix.c
@@ -3300,44 +3300,53 @@ void PR_XNotifyAll(void)
 
 PR_IMPLEMENT(PRStatus)
 _MD_LockFile(PRInt32 f)
 {
     PRInt32 rv;
     struct flock arg;
 
     arg.l_type = F_WRLCK;
+    arg.l_whence = SEEK_SET;
+    arg.l_start = 0;
+    arg.l_len = 0;  /* until EOF */
     rv = fcntl(f, F_SETLKW, &arg);
     if (rv == 0)
         return PR_SUCCESS;
     _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
     return PR_FAILURE;
 }
 
 PR_IMPLEMENT(PRStatus)
 _MD_TLockFile(PRInt32 f)
 {
     PRInt32 rv;
     struct flock arg;
 
     arg.l_type = F_WRLCK;
+    arg.l_whence = SEEK_SET;
+    arg.l_start = 0;
+    arg.l_len = 0;  /* until EOF */
     rv = fcntl(f, F_SETLK, &arg);
     if (rv == 0)
         return PR_SUCCESS;
     _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
     return PR_FAILURE;
 }
 
 PR_IMPLEMENT(PRStatus)
 _MD_UnlockFile(PRInt32 f)
 {
     PRInt32 rv;
     struct flock arg;
 
     arg.l_type = F_UNLCK;
+    arg.l_whence = SEEK_SET;
+    arg.l_start = 0;
+    arg.l_len = 0;  /* until EOF */
     rv = fcntl(f, F_SETLK, &arg);
     if (rv == 0)
         return PR_SUCCESS;
     _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
     return PR_FAILURE;
 }
 
 #elif defined(HAVE_BSD_FLOCK)