summaryrefslogtreecommitdiffstats
path: root/pw/fileupd.c
diff options
context:
space:
mode:
authorDavid Nugent <davidn@FreeBSD.org>1999-02-23 07:15:11 +0000
committerDavid Nugent <davidn@FreeBSD.org>1999-02-23 07:15:11 +0000
commit9b902300660a81e65108ffaa5289722e09526d43 (patch)
tree4debe9fd3ea8e8f60b866076ba6adeeccdcf21f8 /pw/fileupd.c
parentb4807366e2f2f1d630c4f6afaf65ce9941db6c84 (diff)
downloadpw-darwin-9b902300660a81e65108ffaa5289722e09526d43.tar.gz
pw-darwin-9b902300660a81e65108ffaa5289722e09526d43.tar.zst
pw-darwin-9b902300660a81e65108ffaa5289722e09526d43.zip
1) Do not blindly ignore file update errors which may occur due to concurrent
updating 2) Add -V <etcdir>, which allows maintaining user/group database in alternate locations other than /etc.
Diffstat (limited to 'pw/fileupd.c')
-rw-r--r--pw/fileupd.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/pw/fileupd.c b/pw/fileupd.c
index fe46480..d76259b 100644
--- a/pw/fileupd.c
+++ b/pw/fileupd.c
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
- "$Id: fileupd.c,v 1.5 1997/10/10 06:23:31 charnier Exp $";
+ "$Id: fileupd.c,v 1.6 1998/07/16 17:18:24 nate Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -175,16 +175,11 @@ fileupdate(char const * filename, mode_t fmode, char const * newline, char const
* corrupted the original file
* Unfortunately, it will lose the inode
* and hence the lock.
- *
- * The implications of this is that this invocation of pw
- * won't have the file locked and concurrent copies
- * of pw, vipw etc could clobber what this one is doing.
- *
- * It should probably just return an error instead
- * of going on like nothing is wrong.
*/
- if (fflush(infp) == EOF || ferror(infp))
- rc = rename(file, filename) == 0;
+ if (fflush(infp) == EOF || ferror(infp)) {
+ rc = errno; /* Preserve errno for return */
+ rename(file, filename);
+ }
else
ftruncate(infd, ftell(infp));
}