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

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