Blame SOURCES/autofs-5.0.9-amd-lookup-fix-lofs-mounting.patch

304803
autofs-5.0.9 - amd lookup fix lofs mounting
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
The kernel leaves mount type autofs alone because they are supposed
304803
to be autofs sub-mounts and they look after their own expiration. So
304803
mounts bound to an autofs submount won't ever be expired.
304803
---
304803
 daemon/spawn.c |   42 ++++++++++++++++++++++++++++++++++++++----
304803
 1 file changed, 38 insertions(+), 4 deletions(-)
304803
304803
diff --git a/daemon/spawn.c b/daemon/spawn.c
304803
index a6c8c34..bfb8cfc 100644
304803
--- a/daemon/spawn.c
304803
+++ b/daemon/spawn.c
304803
@@ -111,6 +111,12 @@ static int timed_read(int pipe, char *buf, size_t len, int time)
304803
 		return ret;
304803
 	}
304803
 
304803
+	if (pfd[0].fd == -1)
304803
+		return 0;
304803
+
304803
+	if ((pfd[0].revents & (POLLIN|POLLHUP)) == POLLHUP)
304803
+		return 0;
304803
+
304803
 	while ((ret = read(pipe, buf, len)) == -1 && errno == EINTR);
304803
 
304803
 	return ret;
304803
@@ -179,7 +185,8 @@ static int do_spawn(unsigned logopt, unsigned int wait,
304803
 		 * I hope host names are never allowed "/" as first char
304803
 		 */
304803
 		if (use_open && *(argv[loc]) == '/') {
304803
-			int fd;
304803
+			char **p;
304803
+			int is_bind, fd;
304803
 
304803
 			pid_t pgrp = getpgrp();
304803
 
304803
@@ -209,6 +216,33 @@ static int do_spawn(unsigned logopt, unsigned int wait,
304803
 			setegid(0);
304803
 			if (pgrp >= 0)
304803
 				setpgid(0, pgrp);
304803
+
304803
+			/*
304803
+			 * The kernel leaves mount type autofs alone because
304803
+			 * they are supposed to be autofs sub-mounts and they
304803
+			 * look after their own expiration. So mounts bound
304803
+			 * to an autofs submount won't ever be expired.
304803
+			 */
304803
+			is_bind = 0;
304803
+			p = (char **) argv;
304803
+			while (*p) {
304803
+				if (strcmp(*p, "--bind")) {
304803
+					p++;
304803
+					continue;
304803
+				}
304803
+				is_bind = 1;
304803
+				break;
304803
+			}
304803
+			if (!is_bind)
304803
+				goto done;
304803
+
304803
+			if (is_mounted(_PROC_MOUNTS, argv[loc], MNTS_AUTOFS)) {
304803
+				fprintf(stderr,
304803
+				     "error: can't bind to an autofs mount\n");
304803
+				close(STDOUT_FILENO);
304803
+				close(STDERR_FILENO);
304803
+				 _exit(EINVAL);
304803
+			}
304803
 		}
304803
 done:
304803
 		execv(prog, (char *const *) argv);
304803
@@ -384,7 +418,7 @@ int spawn_mount(unsigned logopt, ...)
304803
 
304803
 	while (retries--) {
304803
 		ret = do_spawn(logopt, wait, options, prog, (const char **) argv);
304803
-		if (ret & MTAB_NOTUPDATED) {
304803
+		if (ret == MTAB_NOTUPDATED) {
304803
 			struct timespec tm = {3, 0};
304803
 
304803
 			/*
304803
@@ -502,7 +536,7 @@ int spawn_bind_mount(unsigned logopt, ...)
304803
 
304803
 	while (retries--) {
304803
 		ret = do_spawn(logopt, -1, options, prog, (const char **) argv);
304803
-		if (ret & MTAB_NOTUPDATED) {
304803
+		if (ret == MTAB_NOTUPDATED) {
304803
 			struct timespec tm = {3, 0};
304803
 
304803
 			/*
304803
@@ -604,7 +638,7 @@ int spawn_umount(unsigned logopt, ...)
304803
 
304803
 	while (retries--) {
304803
 		ret = do_spawn(logopt, wait, options, prog, (const char **) argv);
304803
-		if (ret & MTAB_NOTUPDATED) {
304803
+		if (ret == MTAB_NOTUPDATED) {
304803
 			/*
304803
 			 * If the mount succeeded but the mtab was not
304803
 			 * updated, then retry the umount just to update