From: Ian Kent Date: Thu, 14 Dec 2006 11:34:52 +0000 (+0900) Subject: nfs-utils - mtab locking needed on add as well as update X-Git-Tag: nfs-utils-1-0-11~39 X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=commitdiff_plain;h=a0e8627a9265725f4ece39516d5b40ea2e7cc8ac 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. --- 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; }