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

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