
This patch provides a configure option to disable the use of a lock
file when calling mount from autofs. It also adds a patch to the
"patches" directory that needs to be used for mount to (hopefuully)
prevent /etc/mtab corruption when rapidly mounting filesystems
when autofs does not use locking.

To disable the locking add the configure option --disable-mount-locking.

diff -Nurp autofs-4.1.4.orig/configure autofs-4.1.4/configure
--- autofs-4.1.4.orig/configure	2005-04-06 23:24:37.000000000 +0800
+++ autofs-4.1.4/configure	2005-10-23 11:33:44.000000000 +0800
@@ -842,6 +842,7 @@ Optional Features:
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
 --disable-ext-env          disable search in environment for substitution variable
+--disable-mount-locking          disable use of locking when spawning mount command
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -4308,6 +4309,23 @@ _ACEOF
 fi
 
 #
+# Disable use of locking when spawning mount command
+#
+# Check whether --enable-mount-locking or --disable-mount-locking was given.
+if test "${enable_mount_locking+set}" = set; then
+  enableval="$enable_mount_locking"
+
+else
+  enableval=yes
+fi;
+if test x$enable_mount_locking = xyes -o x$enableval = xyes; then
+	cat >>confdefs.h <<\_ACEOF
+#define ENABLE_MOUNT_LOCKING 1
+_ACEOF
+
+fi
+
+#
 # Write Makefile.conf and include/config.h
 #
           ac_config_headers="$ac_config_headers include/config.h"
diff -Nurp autofs-4.1.4.orig/configure.in autofs-4.1.4/configure.in
--- autofs-4.1.4.orig/configure.in	2005-04-06 23:24:37.000000000 +0800
+++ autofs-4.1.4/configure.in	2005-10-23 11:33:35.000000000 +0800
@@ -167,6 +167,16 @@ if test x$enable_ext_env = xyes; then
 fi
 
 #
+# Disable use of locking when spawning mount command
+#
+AC_ARG_ENABLE(mount-locking,
+--disable-mount-locking          disable use of locking when spawning mount command,,
+	enableval=yes)
+if test x$enable_mount_locking = xyes -o x$enableval = xyes; then
+	AC_DEFINE(ENABLE_MOUNT_LOCKING, 1)
+fi
+
+#
 # Write Makefile.conf and include/config.h
 #
 AC_CONFIG_HEADER(include/config.h)
diff -Nurp autofs-4.1.4.orig/daemon/spawn.c autofs-4.1.4/daemon/spawn.c
--- autofs-4.1.4.orig/daemon/spawn.c	2005-02-10 20:56:53.000000000 +0800
+++ autofs-4.1.4/daemon/spawn.c	2005-10-23 10:51:10.000000000 +0800
@@ -322,6 +322,7 @@ int spawnl(int logpri, const char *prog,
 	return do_spawn(logpri, 0, prog, (const char **) argv);
 }
 
+#ifdef ENABLE_MOUNT_LOCKING
 int spawnll(int logpri, const char *prog, ...)
 {
 	va_list arg;
@@ -342,3 +343,4 @@ int spawnll(int logpri, const char *prog
 
 	return do_spawn(logpri, 1, prog, (const char **) argv);
 }
+#endif
diff -Nurp autofs-4.1.4.orig/include/automount.h autofs-4.1.4/include/automount.h
--- autofs-4.1.4.orig/include/automount.h	2005-01-26 21:03:02.000000000 +0800
+++ autofs-4.1.4/include/automount.h	2005-10-23 10:51:10.000000000 +0800
@@ -121,9 +121,13 @@ extern struct autofs_point ap; 
 
 int aquire_lock(void);
 void release_lock(void);
-int spawnll(int logpri, const char *prog, ...);
 int spawnl(int logpri, const char *prog, ...);
-int spawnv(int logpri, const char *prog, const char *const *argv);
+#ifdef ENABLE_MOUNT_LOCKING
+int spawnll(int logpri, const char *prog, ...);
+#else
+#define spawnll	spawnl
+#endif
+int spawnv(int ogpri, const char *prog, const char *const *argv);
 void reset_signals(void);
 void ignore_signals(void);
 void discard_pending(int sig);
diff -Nurp autofs-4.1.4.orig/include/config.h.in autofs-4.1.4/include/config.h.in
--- autofs-4.1.4.orig/include/config.h.in	2004-02-03 23:23:21.000000000 +0800
+++ autofs-4.1.4/include/config.h.in	2005-10-23 10:51:10.000000000 +0800
@@ -25,3 +25,5 @@
 #undef HAVE_SLOPPY_MOUNT
 
 #undef ENABLE_EXT_ENV
+
+#undef ENABLE_MOUNT_LOCKING
diff -Nurp autofs-4.1.4.orig/patches/util-linux-2.12a-flock.patch autofs-4.1.4/patches/util-linux-2.12a-flock.patch
--- autofs-4.1.4.orig/patches/util-linux-2.12a-flock.patch	1970-01-01 08:00:00.000000000 +0800
+++ autofs-4.1.4/patches/util-linux-2.12a-flock.patch	2005-10-23 10:51:10.000000000 +0800
@@ -0,0 +1,30 @@
+--- util-linux-2.12a/mount/fstab.c.flock	2005-09-17 01:36:03.000000000 +0800
++++ util-linux-2.12a/mount/fstab.c	2005-09-17 01:41:12.000000000 +0800
+@@ -488,7 +488,7 @@ lock_mtab (void) {
+ 				}
+ 				/* proceed anyway */
+ 			}
+-			we_created_lockfile = 1;
++			we_created_lockfile = fd;
+ 		} else {
+ 			static int tries = 0;
+ 
+@@ -510,9 +510,8 @@ lock_mtab (void) {
+ 					     MOUNTED_LOCK);
+ 				sleep(1);
+ 			}
++			close(fd);
+ 		}
+-
+-		close(fd);
+ 	}
+ }
+ 
+@@ -520,6 +519,7 @@ lock_mtab (void) {
+ void
+ unlock_mtab (void) {
+ 	if (we_created_lockfile) {
++		close(we_created_lockfile);
+ 		unlink (MOUNTED_LOCK);
+ 		we_created_lockfile = 0;
+ 	}
diff -Nurp autofs-4.1.4.orig/patches/util-linux-2.12q-flock.patch autofs-4.1.4/patches/util-linux-2.12q-flock.patch
--- autofs-4.1.4.orig/patches/util-linux-2.12q-flock.patch	1970-01-01 08:00:00.000000000 +0800
+++ autofs-4.1.4/patches/util-linux-2.12q-flock.patch	2005-10-23 10:51:10.000000000 +0800
@@ -0,0 +1,29 @@
+--- util-linux-2.12q/mount/fstab.c.flock	2005-09-17 01:10:37.000000000 +0800
++++ util-linux-2.12q/mount/fstab.c	2005-09-17 01:16:51.000000000 +0800
+@@ -417,6 +417,7 @@
+ unlock_mtab (void) {
+ 	if (we_created_lockfile) {
+ 		unlink (MOUNTED_LOCK);
++		close(we_created_lock_file);
+ 		we_created_lockfile = 0;
+ 	}
+ }
+@@ -528,6 +529,7 @@
+ 				}
+ 				/* proceed anyway */
+ 			}
++			we_created_lock_file = fd;
+ 		} else {
+ 			static int tries = 0;
+ 
+@@ -549,9 +551,8 @@
+ 					     MOUNTED_LOCK);
+ 				sleep(1);
+ 			}
++			close(fd);
+ 		}
+-
+-		close(fd);
+ 	}
+ }
+ 
