Blame SOURCES/autofs-5.1.5-use-local_getmntent_r-for-unlink_mount_tree.patch

c8d72b
autofs-5.1.5 - use local_getmntent_r() for unlink_mount_tree()
c8d72b
c8d72b
From: Ian Kent <raven@themaw.net>
c8d72b
c8d72b
Now that unlink_mount_tree() is located in a single location and
c8d72b
only one function is used for this, change it to use our local
c8d72b
getmntent_r() function so that if glibc is changed to support the
c8d72b
autofs "ignore" hint automount(8) won't be affected.
c8d72b
c8d72b
Signed-off-by: Ian Kent <raven@themaw.net>
c8d72b
---
c8d72b
 CHANGELOG         |    1 +
c8d72b
 daemon/direct.c   |   24 ++++++------------------
c8d72b
 daemon/indirect.c |   17 ++++++-----------
c8d72b
 include/mounts.h  |    2 +-
c8d72b
 lib/mounts.c      |   45 ++++++++++++++++++++++++++++++++++-----------
c8d72b
 5 files changed, 48 insertions(+), 41 deletions(-)
c8d72b
c8d72b
--- autofs-5.0.7.orig/CHANGELOG
c8d72b
+++ autofs-5.0.7/CHANGELOG
c8d72b
@@ -346,6 +346,7 @@
c8d72b
 - don't use tree_is_mounted() for mounted checks.
c8d72b
 - use single unlink_umount_tree() for both direct and indirect mounts.
c8d72b
 - move unlink_mount_tree() to lib/mounts.c.
c8d72b
+- use local_getmntent_r() for unlink_mount_tree().
c8d72b
 
c8d72b
 25/07/2012 autofs-5.0.7
c8d72b
 =======================
c8d72b
--- autofs-5.0.7.orig/daemon/direct.c
c8d72b
+++ autofs-5.0.7/daemon/direct.c
c8d72b
@@ -285,8 +285,6 @@ int do_mount_autofs_direct(struct autofs
c8d72b
 		if (ret == 0)
c8d72b
 			return -1;
c8d72b
 	} else {
c8d72b
-		struct mnt_list *mnts;
c8d72b
-
c8d72b
 		if (ap->state == ST_READMAP && is_mounted(me->key, MNTS_ALL)) {
c8d72b
 			time_t tout = get_exp_timeout(ap, me->source);
c8d72b
 			int save_ioctlfd, ioctlfd;
c8d72b
@@ -312,22 +310,12 @@ int do_mount_autofs_direct(struct autofs
c8d72b
 			return 0;
c8d72b
 		}
c8d72b
 
c8d72b
-		mnts = get_mnt_list(me->key, 1);
c8d72b
-		if (mnts) {
c8d72b
-			/*
c8d72b
-			 * A return of 1 indicates we successfully unlinked
c8d72b
-			 * the mount tree if there was one. A return of 0
c8d72b
-			 * indicates we failed to unlink the mount tree so
c8d72b
-			 * we have to return a failure.
c8d72b
-			 */
c8d72b
-			ret = unlink_mount_tree(ap, mnts);
c8d72b
-			free_mnt_list(mnts);
c8d72b
-			if (!ret) {
c8d72b
-				error(ap->logopt,
c8d72b
-				      "already mounted as other than autofs "
c8d72b
-				      "or failed to unlink entry in tree");
c8d72b
-				return -1;
c8d72b
-			}
c8d72b
+		ret = unlink_mount_tree(ap, ap->path);
c8d72b
+		if (!ret) {
c8d72b
+			error(ap->logopt,
c8d72b
+			     "already mounted as other than autofs "
c8d72b
+			     "or failed to unlink entry in tree");
c8d72b
+			goto out_err;
c8d72b
 		}
c8d72b
 
c8d72b
 		if (me->ioctlfd != -1) {
c8d72b
--- autofs-5.0.7.orig/daemon/indirect.c
c8d72b
+++ autofs-5.0.7/daemon/indirect.c
c8d72b
@@ -50,7 +50,6 @@ static int do_mount_autofs_indirect(stru
c8d72b
 	const char *map_name = hosts_map_name;
c8d72b
 	const char *type;
c8d72b
 	struct stat st;
c8d72b
-	struct mnt_list *mnts;
c8d72b
 	int ret;
c8d72b
 
c8d72b
 	/* If the map is being shared the exp_timeout can't be inherited
c8d72b
@@ -69,16 +68,12 @@ static int do_mount_autofs_indirect(stru
c8d72b
 		if (ret == 0)
c8d72b
 			return -1;
c8d72b
 	} else {
c8d72b
-		mnts = get_mnt_list(ap->path, 1);
c8d72b
-		if (mnts) {
c8d72b
-			ret = unlink_mount_tree(ap, mnts);
c8d72b
-			free_mnt_list(mnts);
c8d72b
-			if (!ret) {
c8d72b
-				error(ap->logopt,
c8d72b
-				      "already mounted as other than autofs "
c8d72b
-				      "or failed to unlink entry in tree");
c8d72b
-				goto out_err;
c8d72b
-			}
c8d72b
+		ret = unlink_mount_tree(ap, ap->path);
c8d72b
+		if (!ret) {
c8d72b
+			error(ap->logopt,
c8d72b
+			      "already mounted as other than autofs "
c8d72b
+			      "or failed to unlink entry in tree");
c8d72b
+			goto out_err;
c8d72b
 		}
c8d72b
 	}
c8d72b
 
c8d72b
--- autofs-5.0.7.orig/include/mounts.h
c8d72b
+++ autofs-5.0.7/include/mounts.h
c8d72b
@@ -100,7 +100,7 @@ int ext_mount_add(struct list_head *, co
c8d72b
 int ext_mount_remove(struct list_head *, const char *);
c8d72b
 int ext_mount_inuse(const char *);
c8d72b
 struct mnt_list *get_mnt_list(const char *path, int include);
c8d72b
-int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts);
c8d72b
+int unlink_mount_tree(struct autofs_point *ap, const char *mp);
c8d72b
 void free_mnt_list(struct mnt_list *list);
c8d72b
 int is_mounted(const char *mp, unsigned int type);
c8d72b
 void tree_free_mnt_tree(struct mnt_list *tree);
c8d72b
--- autofs-5.0.7.orig/lib/mounts.c
c8d72b
+++ autofs-5.0.7/lib/mounts.c
c8d72b
@@ -882,21 +882,44 @@ local_getmntent_r(FILE *tab, struct mnte
c8d72b
 	return mnt;
c8d72b
 }
c8d72b
 
c8d72b
-int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts)
c8d72b
+int unlink_mount_tree(struct autofs_point *ap, const char *mp)
c8d72b
 {
c8d72b
-	struct mnt_list *this;
c8d72b
-	int rv, ret;
c8d72b
+	FILE *tab;
c8d72b
+	struct mntent *mnt;
c8d72b
+	struct mntent mnt_wrk;
c8d72b
+	char buf[PATH_MAX * 3];
c8d72b
+	unsigned int mp_len = strlen(mp);
c8d72b
+	int rv, ret = 1;
c8d72b
 
c8d72b
-	ret = 1;
c8d72b
-	this = mnts;
c8d72b
-	while (this) {
c8d72b
-		if (this->flags & MNTS_AUTOFS)
c8d72b
-			rv = umount2(this->mp, MNT_DETACH);
c8d72b
+	tab = open_fopen_r(_PROC_MOUNTS);
c8d72b
+	if (!tab) {
c8d72b
+		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
c8d72b
+		logerr("fopen: %s", estr);
c8d72b
+		return 0;
c8d72b
+	}
c8d72b
+
c8d72b
+	while ((mnt = local_getmntent_r(tab, &mnt_wrk, buf, PATH_MAX * 3))) {
c8d72b
+		unsigned int mnt_dir_len;
c8d72b
+		int is_autofs;
c8d72b
+
c8d72b
+		if (strncmp(mnt->mnt_dir, mp, mp_len))
c8d72b
+			continue;
c8d72b
+
c8d72b
+		mnt_dir_len = strlen(mnt->mnt_dir);
c8d72b
+		is_autofs = !strcmp(mnt->mnt_type, "autofs");
c8d72b
+
c8d72b
+		if (mnt_dir_len == mp_len && !is_autofs) {
c8d72b
+			ret = 0;
c8d72b
+			break;
c8d72b
+		}
c8d72b
+
c8d72b
+		if (is_autofs)
c8d72b
+			rv = umount2(mnt->mnt_dir, MNT_DETACH);
c8d72b
 		else
c8d72b
-			rv = spawn_umount(ap->logopt, "-l", this->mp, NULL);
c8d72b
+			rv = spawn_umount(ap->logopt, "-l", mnt->mnt_dir, NULL);
c8d72b
 		if (rv == -1) {
c8d72b
 			debug(ap->logopt,
c8d72b
-			      "can't unlink %s from mount tree", this->mp);
c8d72b
+			      "can't unlink %s from mount tree", mnt->mnt_dir);
c8d72b
 
c8d72b
 			switch (errno) {
c8d72b
 			case EINVAL:
c8d72b
@@ -911,8 +934,8 @@ int unlink_mount_tree(struct autofs_poin
c8d72b
 				break;
c8d72b
 			}
c8d72b
 		}
c8d72b
-		this = this->next;
c8d72b
 	}
c8d72b
+	fclose(tab);
c8d72b
 
c8d72b
 	return ret;
c8d72b
 }