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

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