Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 238

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

diff -up autofs-5.0.1/include/automount.h.fix-offset-dir-create autofs-5.0.1/include/automount.h
--- autofs-5.0.1/include/automount.h.fix-offset-dir-create	2007-10-18 13:10:51.000000000 +0800
+++ autofs-5.0.1/include/automount.h	2007-10-18 13:19:26.000000000 +0800
@@ -470,7 +470,7 @@ void *expire_proc_direct(void *);
 int expire_offsets_direct(struct autofs_point *ap, struct mapent *me, int now);
 int mount_autofs_indirect(struct autofs_point *ap);
 int mount_autofs_direct(struct autofs_point *ap);
-int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, int is_autofs_fs);
+int mount_autofs_offset(struct autofs_point *ap, struct mapent *me);
 void submount_signal_parent(struct autofs_point *ap, unsigned int success);
 int umount_autofs(struct autofs_point *ap, int force);
 int umount_autofs_indirect(struct autofs_point *ap);
diff -up autofs-5.0.1/daemon/automount.c.fix-offset-dir-create autofs-5.0.1/daemon/automount.c
--- autofs-5.0.1/daemon/automount.c.fix-offset-dir-create	2007-10-18 13:10:51.000000000 +0800
+++ autofs-5.0.1/daemon/automount.c	2007-10-18 13:19:26.000000000 +0800
@@ -100,11 +100,14 @@ static int do_mkdir(const char *parent, 
 		status = statfs(parent, &fs);
 	if ((status != -1 && fs.f_type == AUTOFS_SUPER_MAGIC) ||
 	    contained_in_local_fs(path)) {
-		if (mkdir(path, mode) == -1)
+		if (mkdir(path, mode) == -1) {
+			errno = EACCES;
 			return 0;
+		}
 		return 1;
 	}
 
+	errno = EACCES;
 	return 0;
 }
 
diff -up autofs-5.0.1/daemon/direct.c.fix-offset-dir-create autofs-5.0.1/daemon/direct.c
--- autofs-5.0.1/daemon/direct.c.fix-offset-dir-create	2007-10-18 13:10:51.000000000 +0800
+++ autofs-5.0.1/daemon/direct.c	2007-10-18 13:19:26.000000000 +0800
@@ -604,6 +604,14 @@ int umount_autofs_offset(struct autofs_p
 		}
 		ioctlfd = me->ioctlfd;
 	} else {
+		/* offset isn't mounted, return success and try to recover */
+		if (!is_mounted(_PROC_MOUNTS, me->key, MNTS_AUTOFS)) {
+			debug(ap->logopt,
+			      "offset %s unexpectedly not mounted",
+			      me->key);
+			return 0;
+		}
+
 		ioctlfd = open(me->key, O_RDONLY);
 		if (ioctlfd != -1) {
 			if ((cl_flags = fcntl(ioctlfd, F_GETFD, 0)) != -1) {
@@ -689,11 +697,19 @@ force_umount:
 	} else
 		msg("umounted offset mount %s", me->key);
 
+	if (!rv && me->dir_created) {
+		if  (rmdir(me->key) == -1) {
+			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+			warn(ap->logopt, "failed to remove dir %s: %s",
+			     me->key, estr);
+		}
+	}
 	return rv;
 }
 
-int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, int is_autofs_fs)
+int mount_autofs_offset(struct autofs_point *ap, struct mapent *me)
 {
+	char buf[MAX_ERR_BUF];
 	struct mnt_params *mp;
 	time_t timeout = ap->exp_timeout;
 	struct stat st;
@@ -740,36 +756,38 @@ int mount_autofs_offset(struct autofs_po
 			return 0;
 	}
 
-	if (is_autofs_fs) {
-		/* In case the directory doesn't exist, try to mkdir it */
-		if (mkdir_path(me->key, 0555) < 0) {
-			if (errno != EEXIST) {
-				crit(ap->logopt,
-				     "failed to create mount directory %s %d",
-				     me->key, errno);
-				return -1;
-			}
+	/* In case the directory doesn't exist, try to mkdir it */
+	if (mkdir_path(me->key, 0555) < 0) {
+		if (errno == EEXIST) {
 			/* 
 			 * If we recieve an error, and it's EEXIST
 			 * we know the directory was not created.
 			 */
 			me->dir_created = 0;
+		} else if (errno == EACCES) {
+			/*
+			 * We require the mount point directory to exist when
+			 * installing multi-mount triggers into a host
+			 * filesystem.
+			 *
+			 * If it doesn't exist it is not a valid part of the
+			 * mount heirachy.
+			 */
+			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+			debug(ap->logopt,
+			     "can't create mount directory: %s, %s",
+			     me->key, estr);
+			return -1;
 		} else {
-			/* No errors so the directory was successfully created */
-			me->dir_created = 1;
+			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
+			crit(ap->logopt,
+			     "failed to create mount directory: %s, %s",
+			     me->key, estr);
+			return -1;
 		}
 	} else {
-		me->dir_created = 0;
-
-		/*
-		 * We require the mount point directory to exist when
-		 * installing multi-mount triggers into a host filesystem.
-		 *
-		 * If it doesn't exist it is not a valid part of the
-		 * mount heirachy so we silently succeed here.
-		 */
-		if (stat(me->key, &st) == -1 && errno == ENOENT)
-			return 0;
+		/* No errors so the directory was successfully created */
+		me->dir_created = 1;
 	}
 
 	debug(ap->logopt,
@@ -832,10 +850,8 @@ out_close:
 out_umount:
 	umount(me->key);
 out_err:
-	if (is_autofs_fs) {
-		if (stat(me->key, &st) == 0 && me->dir_created)
-			 rmdir_path(ap, me->key, st.st_dev);
-	}
+	if (stat(me->key, &st) == 0 && me->dir_created)
+		 rmdir_path(ap, me->key, st.st_dev);
 
 	return -1;
 }
diff -up autofs-5.0.1/lib/parse_subs.c.fix-offset-dir-create autofs-5.0.1/lib/parse_subs.c
--- autofs-5.0.1/lib/parse_subs.c.fix-offset-dir-create	2007-10-18 13:10:51.000000000 +0800
+++ autofs-5.0.1/lib/parse_subs.c	2007-10-18 13:21:51.000000000 +0800
@@ -388,10 +388,8 @@ int mount_multi_triggers(struct autofs_p
 	struct mapent *oe;
 	struct list_head *pos = NULL;
 	unsigned int fs_path_len;
-	struct statfs fs;
-	struct stat st;
-	unsigned int mounted, is_autofs_fs;
-	int ret, start;
+	unsigned int mounted;
+	int start;
 
 	fs_path_len = strlen(root) + strlen(base);
 	if (fs_path_len > PATH_MAX)
@@ -399,15 +397,6 @@ int mount_multi_triggers(struct autofs_p
 
 	strcpy(path, root);
 	strcat(path, base);
-	ret = statfs(path, &fs);
-	if (ret == -1) {
-		/* There's no mount yet - it must be autofs */
-		if (errno == ENOENT)
-			is_autofs_fs = 1;
-		else
-			return -1;
-	} else
-		is_autofs_fs = fs.f_type == AUTOFS_SUPER_MAGIC ? 1 : 0;
 
 	mounted = 0;
 	start = strlen(root);
@@ -424,20 +413,9 @@ int mount_multi_triggers(struct autofs_p
 		if (!oe)
 			goto cont;
 
-		/*
-		 * If the host filesystem is not an autofs fs
-		 * we require the mount point directory exist
-		 * and that permissions are OK.
-		 */
-		if (!is_autofs_fs) {
-			ret = stat(oe->key, &st);
-			if (ret == -1)
-				goto cont;
-		}
-
 		debug(ap->logopt, "mount offset %s", oe->key);
 
-		if (mount_autofs_offset(ap, oe, is_autofs_fs) < 0)
+		if (mount_autofs_offset(ap, oe) < 0)
 			warn(ap->logopt, "failed to mount offset");
 		else
 			mounted++;