Blob Blame History Raw
autofs-5.1.6 - fix unlink mounts umount order

From: Ian Kent <raven@themaw.net>

The recent changes to mount table handling to support the "ignore"
autofs pseudo option resulted in the incorrect umount order being used
in the unlink_mount_tree() function.

To fix this change unlink_mount_tree() to use the existing get_mnt_list()
function to construct a correctly ordered list for the umounts.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG    |    1 +
 lib/mounts.c |   39 +++++++++------------------------------
 2 files changed, 10 insertions(+), 30 deletions(-)

--- autofs-5.0.7.orig/CHANGELOG
+++ autofs-5.0.7/CHANGELOG
@@ -356,6 +356,7 @@
 - fix quoted string length calc in expandsunent().
 - fix autofs mount options construction.
 - fix direct mount unlink_mount_tree() path.
+- fix unlink mounts umount order.
 
 25/07/2012 autofs-5.0.7
 =======================
--- autofs-5.0.7.orig/lib/mounts.c
+++ autofs-5.0.7/lib/mounts.c
@@ -952,42 +952,21 @@ local_getmntent_r(FILE *tab, struct mnte
 
 int unlink_mount_tree(struct autofs_point *ap, const char *mp)
 {
-	FILE *tab;
-	struct mntent *mnt;
-	struct mntent mnt_wrk;
-	char buf[PATH_MAX * 3];
-	unsigned int mp_len = strlen(mp);
+	struct mnt_list *mnts, *mnt;
 	int rv, ret = 1;
 
-	tab = open_fopen_r(_PROC_MOUNTS);
-	if (!tab) {
-		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
-		logerr("fopen: %s", estr);
+	mnts = get_mnt_list(mp, 1);
+	if (!mnts)
 		return 0;
-	}
-
-	while ((mnt = local_getmntent_r(tab, &mnt_wrk, buf, PATH_MAX * 3))) {
-		unsigned int mnt_dir_len;
-		int is_autofs;
-
-		if (strncmp(mnt->mnt_dir, mp, mp_len))
-			continue;
-
-		mnt_dir_len = strlen(mnt->mnt_dir);
-		is_autofs = !strcmp(mnt->mnt_type, "autofs");
-
-		if (mnt_dir_len == mp_len && !is_autofs) {
-			ret = 0;
-			break;
-		}
 
-		if (is_autofs)
-			rv = umount2(mnt->mnt_dir, MNT_DETACH);
+	for (mnt = mnts; mnt; mnt = mnt->next) {
+		if (mnt->flags | MNTS_AUTOFS)
+			rv = umount2(mnt->mp, MNT_DETACH);
 		else
-			rv = spawn_umount(ap->logopt, "-l", mnt->mnt_dir, NULL);
+			rv = spawn_umount(ap->logopt, "-l", mnt->mp, NULL);
 		if (rv == -1) {
 			debug(ap->logopt,
-			      "can't unlink %s from mount tree", mnt->mnt_dir);
+			      "can't unlink %s from mount tree", mnt->mp);
 
 			switch (errno) {
 			case EINVAL:
@@ -1003,7 +982,7 @@ int unlink_mount_tree(struct autofs_poin
 			}
 		}
 	}
-	fclose(tab);
+	free_mnt_list(mnts);
 
 	return ret;
 }