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

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