summaryrefslogtreecommitdiffstats
path: root/pw/fileupd.c
diff options
context:
space:
mode:
authorKen Smith <kensmith@FreeBSD.org>2004-03-08 20:31:37 +0000
committerKen Smith <kensmith@FreeBSD.org>2004-03-08 20:31:37 +0000
commitd922d6bbbb200681fda0a6d37742e400b0d4d587 (patch)
tree8eb7fa07170faf30fb7c8b95b2002e312d6cb611 /pw/fileupd.c
parent6d7976c0088abde23963a3cf0f10900fba6b4e05 (diff)
downloadpw-darwin-d922d6bbbb200681fda0a6d37742e400b0d4d587.tar.gz
pw-darwin-d922d6bbbb200681fda0a6d37742e400b0d4d587.tar.zst
pw-darwin-d922d6bbbb200681fda0a6d37742e400b0d4d587.zip
Shift file locking to source file instead of temp file. This fixes
data buffering issue that corrupts files if two pw(8)'s run at the same time as well as changing pw(8) so it uses the same locking mechanism as PAM, vipw(8), pwd_mkdb(8), etc. PR: bin/23501 Submitted by: Alex Kapranoff <alex (at) kapran (dot) bitmcnit (dot) bryansk (dot) su> Approved by: rwatson (mentor) MFC after: 5 days
Diffstat (limited to 'pw/fileupd.c')
-rw-r--r--pw/fileupd.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/pw/fileupd.c b/pw/fileupd.c
index a846513..b88f4fa 100644
--- a/pw/fileupd.c
+++ b/pw/fileupd.c
@@ -76,7 +76,7 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const
if (pfxlen <= 1)
rc = EINVAL;
else {
- int infd = open(filename, O_RDWR | O_CREAT, fmode);
+ int infd = open(filename, O_RDWR | O_CREAT | O_EXLOCK, fmode);
if (infd == -1)
rc = errno;
@@ -92,7 +92,7 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const
strcpy(file, filename);
strcat(file, ".new");
- outfd = open(file, O_RDWR | O_CREAT | O_TRUNC | O_EXLOCK, fmode);
+ outfd = open(file, O_RDWR | O_CREAT | O_TRUNC, fmode);
if (outfd == -1)
rc = errno;
else {
@@ -183,8 +183,6 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const
* to 'file'.
* This is a gross hack, but we may have
* corrupted the original file
- * Unfortunately, it will lose the inode
- * and hence the lock.
*/
if (fflush(infp) == EOF || ferror(infp))
rename(file, filename);