Skip to contentSkip to conversation

nfs-utils - mtab locking needed on add as well as update

PATCH New Ian Kent 1 participant 1 message Dec 14, 2006

Subsystems (2)
lore
Share & tools
lore

Ian Kent

author
#0 lore raw

PATCH 1/1 nfs-utils - mtab locking needed on add as well as update

Hi all,

I noticed some mtab corruption the other day when doing some autofs testing but thought nothing of it.

When investigating another issue I came across utils/mount.c:add_mtab which looks like it adds an entry to /etc/mtab without performing correct locking. Perhaps this is not needed when adding entries but I think it is.

Comments please?

---

utils/mount/mount.c renamed from utils/mount/mount.c.mtab-locking +6 -9
@@ -149,11 +149,7 @@
 	ment.mnt_freq = 0;
 	ment.mnt_passno= 0;
 
-	if ((fd = open(MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) == -1)	{
-		fprintf(stderr, "Can't get "MOUNTED"~ lock file");
-		return 1;
-	}
-        close(fd);
+	lock_mtab();
 
         if ((mtab = setmntent(MOUNTED, "a+")) == NULL) {
 		fprintf(stderr, "Can't open " MOUNTED);
@@ -161,21 +157,22 @@
 	}
 
         if (addmntent(mtab, &ment) == 1) {
+		endmntent(mtab);
+		unlock_mtab();
 		fprintf(stderr, "Can't write mount entry");
 		return 1;
 	}
 
         if (fchmod(fileno(mtab), 0644) == -1) {
+		endmntent(mtab);
+		unlock_mtab();
 		fprintf(stderr, "Can't set perms on " MOUNTED);
 		return 1;
 	}
 
 	endmntent(mtab);
 
-	if (unlink(MOUNTED"~") == -1) {
-		fprintf(stderr, "Can't remove "MOUNTED"~");
-		return 1;
-	}
+	unlock_mtab();
 
 	return 0;
 }

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs