[crux-devel] [PATCH] util-linux-ng / mount: mtab created multiple times with -a option

Jonas Kramer jkramer at nex.scrapping.cc
Tue Sep 30 21:11:13 UTC 2008


Ahoy,

some of us had the problem that the "mount -a" in /etc/rc printed
"warning: couldn't open /etc/mtab: ..." and that afterwards there were
lots of root-fs entries in /etc/mtab. I looked into the problem and
found that it is a bug in util-linux-ng 2.14.1, in the mount command. I
sent a patch to the util-linux-ng mailing list, but I don't know how
long it will take until the patch is in upstream and upstream is updated
in the CRUX ports, so I just forward the patch to this list. Feel free
to patch your own util-linux-ng ;) However, the warning doesn't go away,
since /etc/mtab really isn't there (it's deleted in /etc/rc for some
reason), but /etc/mtab isn't that messy anymore.

Regards,
Jonas Kramer

----- Forwarded message from Jonas Kramer <jkramer at nex.scrapping.cc> -----

Date: Tue, 30 Sep 2008 22:36:18 +0200
From: Jonas Kramer <jkramer at nex.scrapping.cc>
Subject: [PATCH] mount: mtab created multiple times with -a option
To: kzak at redhat.com
User-Agent: Mutt/1.5.18 (2008-05-17)

Ahoy.

Since util-linux-ng 2.14.1, the following problem occurs with mount.
When /etc/mtab does not exist and mount is called with -a, for every
mount point that is mounted a root-fs record is added to mtab. This is
because get_mtab_info() sets the flag mtab_does_not_exist to 1 when it
doesn't find /etc/mtab. However, if it actually finds /etc/mtab, the
variable is not reset to 0. So on every subsequent call to
get_mtab_info() (as it is the case when mounting several mount points
with the -a option), mount will think that /etc/mtab does not exist,
even if it was created in the meantime by mount itself. Additionally,
create_mtab() does open /etc/mtab with "a+" even though it is only
called when mount thinks that /etc/mtab does not exist. So for every
mount point that is mounted with -a, another root-fs entry is added to
/etc/mtab. The attached patch seems to fix that.

Regards,

Jonas Kramer
-- 

diff --git a/mount/fstab.c b/mount/fstab.c
index 895fd2c..eb38822 100644
--- a/mount/fstab.c
+++ b/mount/fstab.c
@@ -30,13 +30,20 @@ static int var_mtab_is_a_symlink = 0;
 
 static void
 get_mtab_info(void) {
-	struct stat mtab_stat;
-
 	if (!have_mtab_info) {
+		struct stat mtab_stat;
+
 		if (lstat(_PATH_MOUNTED, &mtab_stat))
 			var_mtab_does_not_exist = 1;
-		else if (S_ISLNK(mtab_stat.st_mode))
-			var_mtab_is_a_symlink = 1;
+		else {
+			var_mtab_does_not_exist = 0;
+
+			if (S_ISLNK(mtab_stat.st_mode))
+				var_mtab_is_a_symlink = 1;
+			else
+				var_mtab_is_a_symlink = 0;
+		}
+
 		have_mtab_info = 1;
 	}
 }




----- End forwarded message -----

-- 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.crux.nu/pipermail/crux-devel/attachments/20080930/54a43cf6/attachment.asc>


More information about the crux-devel mailing list