The following message is a courtesy copy of an article
that has been posted to gmane.comp.db.sqlite.general as well.


[EMAIL PROTECTED] writes:
> It is true that I do not use autoconf much.  But I do use it now
> and then.  The main problem is that autoconf is broken on my
> SuSE 10.1 installation and I have not taken the time to try to
> fix it.

A few months ago, I posted a patch to make the autoconfigury deal with
HAVE_FSCTL and HAVE_STATFS_H, as well as add a configure option for
SQLITE_ENABLE_LOCKING_STYLE.

I also printed out and signed the copyright papers and mailed them in.

I never got a response on any of this; not even a "no thanks".

Could you please let me know what happened?  If the patch is
officially rejected, please say so.  It's pretty disheartening to go
to this trouble and be ignored.

  http://www.mail-archive.com/sqlite-users%40sqlite.org/msg20672.html

  http://www.sqlite.org/cvstrac/tktview?tn=2136
  (note that the first "remark" confuses this with something else)

Below is a copy of the patch updated to work against latest CVS.
Don't forget to run 'autoreconf' after applying.

I also have a patch which exposes a configure option for FTS1; I would
be happy to contribute it.

  - a


Index: Makefile.in
===================================================================
RCS file: /sqlite/sqlite/Makefile.in,v
retrieving revision 1.163
diff -u -r1.163 Makefile.in
--- Makefile.in 17 Feb 2007 14:46:31 -0000      1.163
+++ Makefile.in 25 Feb 2007 19:54:42 -0000
@@ -32,7 +32,7 @@
 # Omitting the define will cause extra debugging code to be inserted and
 # includes extra comments when "EXPLAIN stmt" is used.
 #
-TCC += @TARGET_DEBUG@ @XTHREADCONNECT@
+TCC += @TARGET_DEBUG@ @XTHREADCONNECT@ @ENABLELOCKINGSTYLE@
 
 # Compiler options needed for programs that use the TCL library.
 #
Index: configure.ac
===================================================================
RCS file: /sqlite/sqlite/configure.ac,v
retrieving revision 1.29
diff -u -r1.29 configure.ac
--- configure.ac        17 Feb 2007 14:59:18 -0000      1.29
+++ configure.ac        25 Feb 2007 19:54:42 -0000
@@ -217,6 +217,21 @@
 AC_SUBST(XTHREADCONNECT)
 
 ##########
+# Do we want to allow different locking styles?
+#
+AC_ARG_ENABLE(locking-style, 
+AC_HELP_STRING([--enable-locking-style],[Enable different locking 
styles]),,enable_lockingstyle=no)
+AC_MSG_CHECKING([whether to allow connections to be shared across threads])
+if test "$enable_lockingstyle" = "no"; then
+  ENABLELOCKINGSTYLE=''
+  AC_MSG_RESULT([no])
+else
+  ENABLELOCKINGSTYLE='-DSQLITE_ENABLE_LOCKING_STYLE=1'
+  AC_MSG_RESULT([yes])
+fi
+AC_SUBST(ENABLELOCKINGSTYLE)
+
+##########
 # Do we want to set threadsOverrideEachOthersLocks variable to be 1 (true) by
 # default. Normally, a test at runtime is performed to determine the
 # appropriate value of this variable. Use this option only if you're sure that
@@ -571,7 +586,35 @@
 # Redefine fdatasync as fsync on systems that lack fdatasync
 #--------------------------------------------------------------------
 
+AC_CHECK_HEADER([sys/statfs.h], [TARGET_CFLAGS="$TARGET_CFLAGS 
-DHAVE_SYS_STATFS_H=1"],)
+
 AC_CHECK_FUNC(fdatasync, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_FDATASYNC=1"])
+AC_CHECK_FUNC(fsctl, [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_FSCTL=1"])
+
+AC_CHECK_MEMBER(struct statfs.f_flags,
+  [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_STATFS_F_FLAGS=1"],,
+  [
+    #include <sys/ioctl.h>
+    #include <sys/param.h>
+    #include <sys/mount.h>
+  ])
+
+AC_CHECK_MEMBER(struct statfs.f_type,
+  [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_STATFS_F_TYPE=1"],,
+  [
+    #include <sys/ioctl.h>
+    #include <sys/statfs.h>
+    #include <sys/param.h>
+    #include <sys/mount.h>
+  ])
+
+AC_CHECK_MEMBER(struct statfs.f_fstypename,
+  [TARGET_CFLAGS="$TARGET_CFLAGS -DHAVE_STATFS_F_FSTYPENAME=1"],,
+  [
+    #include <sys/ioctl.h>
+    #include <sys/param.h>
+    #include <sys/mount.h>
+  ])
 
 #########
 # Generate the output files.
Index: src/os_unix.c
===================================================================
RCS file: /sqlite/sqlite/src/os_unix.c,v
retrieving revision 1.117
diff -u -r1.117 os_unix.c
--- src/os_unix.c       6 Feb 2007 11:11:08 -0000       1.117
+++ src/os_unix.c       25 Feb 2007 19:54:44 -0000
@@ -52,6 +52,9 @@
 #ifdef SQLITE_ENABLE_LOCKING_STYLE
 #include <sys/ioctl.h>
 #include <sys/param.h>
+#ifdef HAVE_SYS_STATFS_H
+#include <sys/statfs.h>
+#endif /* HAVE_SYS_STATFS_H */
 #include <sys/mount.h>
 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
 
@@ -479,6 +482,52 @@
 #define fcntl lockTrace
 #endif /* SQLITE_LOCK_TRACE */
 
+#ifdef SQLITE_ENABLE_LOCKING_STYLE
+/**
+ *  Check to see if the OS fcntl() byte-range locking call will "lie"
+ *  to us and grant a lock that is not enforced.  This happens notably
+ *  with files in AFS (OpenAFS client <1.5.0, all OSes but Linux).
+ *
+ *  Returns zero if byte-range locks appear to work as expected.
+ */
+static int testProcessLockingBehavior(int fd_orig){
+  int fd;
+  int result;
+  struct flock lock;
+  
+  fd = dup(fd_orig);
+  if( fd<0 ) return 1;
+  memset(&lock, 0, sizeof(struct flock));
+  lock.l_type = F_WRLCK;
+  lock.l_len = 1;
+  lock.l_start = 0;
+  lock.l_whence = SEEK_SET;
+  
+  result = fcntl(fd, F_SETLK, &lock);
+  if (result) {
+    TRACE1("testProcessLockingBehavior(): initial lock in parent failed\n");
+    close(fd);
+    return 1;
+  }
+  
+  if (fork()==0) {
+    result = fcntl(fd, F_SETLK, &lock);
+    exit(result);
+    
+  } else {
+    wait(&result);
+    if (!result) {
+      TRACE1("testProcessLockingBehavior(): parent and child both got 
locks\n");
+      close(fd);
+      return 1;
+    }
+  }
+  
+  close(fd);
+  return 0;
+}
+#endif /* SQLITE_ENABLE_LOCKING_STYLE */
+
 /*
 ** The testThreadLockingBehavior() routine launches two separate
 ** threads on this routine.  This routine attempts to lock a file
@@ -587,15 +636,18 @@
 
 #ifdef SQLITE_FIXED_LOCKING_STYLE
   return (sqlite3LockingStyle)SQLITE_FIXED_LOCKING_STYLE;
-#else
+#else /*  SQLITE_FIXED_LOCKING_STYLE */
   struct statfs fsInfo;
 
   if (statfs(filePath, &fsInfo) == -1)
     return sqlite3TestLockingStyle(filePath, fd);
   
+#ifdef HAVE_STATFS_F_FLAGS
   if (fsInfo.f_flags & MNT_RDONLY)
     return noLockingStyle;
+#endif /* HAVE_STATFS_F_FLAGS */
   
+#ifdef HAVE_STATFS_F_FSTYPENAME
   if( (!strcmp(fsInfo.f_fstypename, "hfs")) ||
     (!strcmp(fsInfo.f_fstypename, "ufs")) )
                return posixLockingStyle;
@@ -609,14 +661,40 @@
   if(!strcmp(fsInfo.f_fstypename, "smbfs"))
     return flockLockingStyle;
   
+  if(!strcmp(fsInfo.f_fstypename, "afs"))
+    return flockLockingStyle;
+
   if(!strcmp(fsInfo.f_fstypename, "msdos"))
     return dotlockLockingStyle;
   
   if(!strcmp(fsInfo.f_fstypename, "webdav"))
     return unsupportedLockingStyle;
+#else /* HAVE_STATFS_F_FSTYPENAME */
+# ifdef HAVE_STATFS_F_TYPE
+  switch(fsInfo.f_type) {
+    case 0x4d44:     // DOS/FAT
+      return dotlockLockingStyle;
+      
+    case 0x6969:     // NFS
+    case 0x564c:     // Netware NCPFS
+      return sqlite3TestLockingStyle(filePath, fd);
+
+    case 0x517B:     // SMBFS
+    case 0x0000:     // AFS or unknown
+      return flockLockingStyle;
+      
+    case 0x00011954: // UFS
+    case 0x58465342: // XFS
+    case 0x137D:     // ext1fs
+    case 0xEF51:     // ext2fs
+    case 0xEF53:     // ext2fs
+      return posixLockingStyle;
+  }
+# endif /* HAVE_STATFS_F_TYPE */
+#endif /* HAVE_STATFS_F_FSTYPENAME */
+#endif /*  SQLITE_FIXED_LOCKING_STYLE */
   
   return sqlite3TestLockingStyle(filePath, fd);  
-#endif // SQLITE_FIXED_LOCKING_STYLE
 }
 
 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
@@ -1696,6 +1774,8 @@
 
 
 #ifdef SQLITE_ENABLE_LOCKING_STYLE
+
+#ifdef HAVE_FSCTL
 #pragma mark AFP Support
 
 /*
@@ -2009,7 +2089,7 @@
   *pId = 0;
   return SQLITE_OK;
 }
-
+#endif /* HAVE_FSCTL */
 
 #pragma mark flock() style locking
 
@@ -2363,6 +2443,8 @@
 };
 
 #ifdef SQLITE_ENABLE_LOCKING_STYLE
+
+#ifdef HAVE_FSCTL
 /*
  ** This vector defines all the methods that can operate on an OsFile
  ** for unix with AFP style file locking.
@@ -2383,6 +2465,7 @@
     unixLockState,
     afpUnixCheckReservedLock,
 };
+#endif /* HAVE_FSCTL */
 
 /*
  ** This vector defines all the methods that can operate on an OsFile
@@ -2473,6 +2556,13 @@
   int rc;
 
   lockingStyle = sqlite3DetectLockingStyle(zFilename, h);
+
+  if ( lockingStyle == posixLockingStyle ) {
+    // downgrade to flock() if byte-range locks appear to work strangely
+    if (!testProcessLockingBehavior())
+      lockingStyle = flockLockingStyle;
+  }
+
   if ( lockingStyle == posixLockingStyle ) {
     sqlite3OsEnterMutex();
     rc = findLockInfo(h, &f.pLock, &f.pOpen);
@@ -2508,6 +2598,7 @@
   }else{
     *pNew = f;
     switch(lockingStyle) {
+#ifdef HAVE_FSCTL
       case afpLockingStyle:
         /* afp locking uses the file path so it needs to be included in
         ** the afpLockingContext */
@@ -2520,6 +2611,7 @@
                zFilename);
         srandomdev();
         break;
+#endif /* HAVE_FSCTL */
       case flockLockingStyle:
         /* flock locking doesn't need additional lockingContext information */
         pNew->pMethod = &sqlite3FlockLockingUnixIoMethod;
@@ -2638,10 +2730,10 @@
   ** that we always use the same random number sequence.  This makes the
   ** tests repeatable.
   */
-  memset(zBuf, 0, 256);
 #if !defined(SQLITE_TEST)
   {
     int pid, fd;
+  memset(zBuf, 0, 256);
     fd = open("/dev/urandom", O_RDONLY);
     if( fd<0 ){
       time_t t;

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to