aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil/gr_util.c
diff options
context:
space:
mode:
authorRenato Botelho <garga@FreeBSD.org>2015-07-02 17:30:59 +0000
committerRenato Botelho <garga@FreeBSD.org>2015-07-02 17:30:59 +0000
commitd32a66b2a22df44ec11073b9d7b7cf9c130511cb (patch)
tree117a7f93582c746c2d9f1203b60edb19ede05ae6 /lib/libutil/gr_util.c
parentd2676f552ed4a98882a6f96a528dea48eee6999e (diff)
Notes
Diffstat (limited to 'lib/libutil/gr_util.c')
-rw-r--r--lib/libutil/gr_util.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c
index b0b0b36f0818..93b3eb2f92fc 100644
--- a/lib/libutil/gr_util.c
+++ b/lib/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);
}
/*