On Tuesday 01 December 2009 08:51, Michael Abbott wrote:
> Why does `mount -a` repeatedly mount over mount points that are already 
> mounted?  Non-busybox mount doesn't appear to do this, and I'm finding 
> this behaviour to be quite a nuisance.

Please let me know whether this patch helps.
--
vda
--- busybox.3/util-linux/mount.c	Fri Dec  4 03:32:51 2009
+++ busybox.t3/util-linux/mount.c	Sat Dec  5 04:19:18 2009
@@ -1960,6 +1964,7 @@
 
 		// If we're mounting all
 		} else {
+			struct mntent *mp;
 			// No, mount -a won't mount anything,
 			// even user mounts, for mere humans
 			if (nonroot)
@@ -1987,10 +1992,23 @@
 			// NFS mounts want this to be xrealloc-able
 			mtcur->mnt_opts = xstrdup(mtcur->mnt_opts);
 
-			// Mount this thing
-			if (singlemount(mtcur, 1)) {
-				// Count number of failed mounts
-				rc++;
+			// If nothing is mounted on this directory...
+			// (otherwise repeated "mount -a" mounts everything again)
+			mp = find_mount_point(mtcur->mnt_dir, /*subdir_too:*/ 0);
+			// We do not check fsname match of found mount point -
+			// "/" may have fsname of "/dev/root" while fstab
+			// says "/dev/something_else".
+			if (mp) {
+				bb_error_msg("according to %s, "
+					"%s is already mounted on %s",
+					bb_path_mtab_file,
+					mp->mnt_fsname, mp->mnt_dir);
+			} else {
+				// ...mount this thing
+				if (singlemount(mtcur, /*ignore_busy:*/ 1)) {
+					// Count number of failed mounts
+					rc++;
+				}
 			}
 			free(mtcur->mnt_opts);
 		}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to