Blame SOURCES/autofs-5.0.8-use-open-instead-of-access.patch

304803
autofs-5.0.8 - use open(2) instead of access(2)
304803
304803
From: Ian Kent <ikent@redhat.com>
304803
304803
The access(2) system call has been used to trigger dependednt automounts
304803
in the target path when mounting. But access(2) no longer triggers the
304803
dependednt mounts.
304803
304803
So use open(2) with flag O_DIRECTORY which will trigger these mounts.
304803
---
304803
 CHANGELOG      |    1 +
304803
 daemon/spawn.c |   30 ++++++++++++++++++------------
304803
 2 files changed, 19 insertions(+), 12 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -104,6 +104,7 @@
304803
 - fix variable substitution description.
304803
 - fix incorrect append options description in README.v5-release.
304803
 - fix mistake in assignment.
304803
+- use open(2) instead of access(2) to trigger dependent mounts.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/daemon/spawn.c
304803
+++ autofs-5.0.7/daemon/spawn.c
304803
@@ -32,7 +32,7 @@ static pthread_mutex_t spawn_mutex = PTH
304803
 
304803
 #define SPAWN_OPT_NONE		0x0000
304803
 #define SPAWN_OPT_LOCK		0x0001
304803
-#define SPAWN_OPT_ACCESS	0x0002
304803
+#define SPAWN_OPT_OPEN		0x0002
304803
 
304803
 #define MTAB_LOCK_RETRIES	3
304803
 
304803
@@ -126,7 +126,7 @@ static int do_spawn(unsigned logopt, uns
304803
 	int errp, errn;
304803
 	int cancel_state;
304803
 	unsigned int use_lock = options & SPAWN_OPT_LOCK;
304803
-	unsigned int use_access = options & SPAWN_OPT_ACCESS;
304803
+	unsigned int use_open = options & SPAWN_OPT_OPEN;
304803
 	sigset_t allsigs, tmpsig, oldsig;
304803
 	struct thread_stdenv_vars *tsv;
304803
 	pid_t euid = 0;
304803
@@ -166,6 +166,8 @@ static int do_spawn(unsigned logopt, uns
304803
 		/* what to mount must always be second last */
304803
 		while (*pargv++)
304803
 			loc++;
304803
+		if (loc <= 3)
304803
+			goto done;
304803
 		loc -= 2;
304803
 
304803
 		/*
304803
@@ -176,7 +178,9 @@ static int do_spawn(unsigned logopt, uns
304803
 		 *
304803
 		 * I hope host names are never allowed "/" as first char
304803
 		 */
304803
-		if (use_access && *(argv[loc]) == '/') {
304803
+		if (use_open && *(argv[loc]) == '/') {
304803
+			int fd;
304803
+
304803
 			pid_t pgrp = getpgrp();
304803
 
304803
 			/*
304803
@@ -192,19 +196,21 @@ static int do_spawn(unsigned logopt, uns
304803
 			/*
304803
 			 * Trigger the recursive mount.
304803
 			 *
304803
-			 * Ignore the access(2) return code as there may be
304803
+			 * Ignore the open(2) return code as there may be
304803
 			 * multiple waiters for this mount and we need to
304803
-			 * let the  VFS handle access returns to each
304803
-			 * individual waiter.
304803
+			 * let the VFS handle returns to each individual
304803
+			 * waiter.
304803
 			 */
304803
-			access(argv[loc], F_OK);
304803
+			fd = open(argv[loc], O_DIRECTORY);
304803
+			if (fd != -1)
304803
+				close(fd);
304803
 
304803
 			seteuid(0);
304803
 			setegid(0);
304803
 			if (pgrp >= 0)
304803
 				setpgid(0, pgrp);
304803
 		}
304803
-
304803
+done:
304803
 		execv(prog, (char *const *) argv);
304803
 		_exit(255);	/* execv() failed */
304803
 	} else {
304803
@@ -327,7 +333,7 @@ int spawn_mount(unsigned logopt, ...)
304803
 #ifdef ENABLE_MOUNT_LOCKING
304803
 	options = SPAWN_OPT_LOCK;
304803
 #else
304803
-	options = SPAWN_OPT_ACCESS;
304803
+	options = SPAWN_OPT_OPEN;
304803
 #endif
304803
 
304803
 	va_start(arg, logopt);
304803
@@ -360,7 +366,7 @@ int spawn_mount(unsigned logopt, ...)
304803
 		p = argv + 2;
304803
 	}
304803
 	while ((*p = va_arg(arg, char *))) {
304803
-		if (options == SPAWN_OPT_ACCESS && !strcmp(*p, "-t")) {
304803
+		if (options == SPAWN_OPT_OPEN && !strcmp(*p, "-t")) {
304803
 			*(++p) = va_arg(arg, char *);
304803
 			if (!*p)
304803
 				break;
304803
@@ -429,7 +435,7 @@ int spawn_mount(unsigned logopt, ...)
304803
 
304803
 /*
304803
  * For bind mounts that depend on the target being mounted (possibly
304803
- * itself an automount) we attempt to mount the target using an access
304803
+ * itself an automount) we attempt to mount the target using an open(2)
304803
  * call. For this to work the location must be the second last arg.
304803
  *
304803
  * NOTE: If mount locking is enabled this type of recursive mount cannot
304803
@@ -455,7 +461,7 @@ int spawn_bind_mount(unsigned logopt, ..
304803
 #ifdef ENABLE_MOUNT_LOCKING
304803
 	options = SPAWN_OPT_LOCK;
304803
 #else
304803
-	options = SPAWN_OPT_ACCESS;
304803
+	options = SPAWN_OPT_OPEN;
304803
 #endif
304803
 
304803
 	/*