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

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