summaryrefslogtreecommitdiffstats
path: root/libutil/gr_util.c
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2015-09-12 11:41:31 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2015-09-12 11:41:31 +0000
commitdfac825697674070ff717c02263d3aab9c9d62bd (patch)
treed0a9241fb6cc89559109f7e769218add7566865b /libutil/gr_util.c
parentcdfbaf3700b5e6732bc50f13b3e65ef7c576086c (diff)
parent9c04af5e0b95f4cebcc065c168ec58a4851b4764 (diff)
downloadpw-darwin-dfac825697674070ff717c02263d3aab9c9d62bd.tar.gz
pw-darwin-dfac825697674070ff717c02263d3aab9c9d62bd.zip
Merge from head
Diffstat (limited to 'libutil/gr_util.c')
-rw-r--r--libutil/gr_util.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/libutil/gr_util.c b/libutil/gr_util.c
index b0b0b36..93b3eb2 100644
--- a/libutil/gr_util.c
+++ b/libutil/gr_util.c
@@ -141,7 +141,7 @@ gr_tmp(int mfd)
errno = ENAMETOOLONG;
return (-1);
}
- if ((tfd = mkstemp(tempname)) == -1)
+ if ((tfd = mkostemp(tempname, O_SYNC)) == -1)
return (-1);
if (mfd != -1) {
while ((nr = read(mfd, buf, sizeof(buf))) > 0)
@@ -318,10 +318,28 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr)
int
gr_mkdb(void)
{
+ int fd;
+
if (chmod(tempname, 0644) != 0)
return (-1);
- return (rename(tempname, group_file));
+ if (rename(tempname, group_file) != 0)
+ return (-1);
+
+ /*
+ * Make sure new group file is safe on disk. To improve performance we
+ * will call fsync() to the directory where file lies
+ */
+ if ((fd = open(group_dir, O_RDONLY|O_DIRECTORY)) == -1)
+ return (-1);
+
+ if (fsync(fd) != 0) {
+ close(fd);
+ return (-1);
+ }
+
+ close(fd);
+ return(0);
}
/*