summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Kent <raven@themaw.net>2006-12-14 20:34:52 +0900
committerNeil Brown <neilb@suse.de>2006-12-19 09:14:03 +1100
commita0e8627a9265725f4ece39516d5b40ea2e7cc8ac (patch)
tree9f558d6135b51b82c8c15d40ccb6d8d26db47beb
parentc52c3bae6e24afb631430161d6bcd318b4467600 (diff)
downloadnfs-utils-a0e8627a9265725f4ece39516d5b40ea2e7cc8ac.tar.gz
nfs-utils-a0e8627a9265725f4ece39516d5b40ea2e7cc8ac.tar.xz
nfs-utils-a0e8627a9265725f4ece39516d5b40ea2e7cc8ac.zip
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.
-rw-r--r--utils/mount/mount.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/utils/mount/mount.c b/utils/mount/mount.c
index ca87e3d..5e0e599 100644
--- a/utils/mount/mount.c
+++ b/utils/mount/mount.c
@@ -149,11 +149,7 @@ int add_mtab(char *fsname, char *mount_point, char *fstype, int flags, char *opt
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 @@ int add_mtab(char *fsname, char *mount_point, char *fstype, int flags, char *opt
}
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;
}