From 728813a02a03cdab41bffc21d729fb394aef805c Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Wed, 2 Mar 2016 14:40:42 -0300 Subject: Import review D5409 --- lib/libutil/gr_util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/libutil/gr_util.c') diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index 80d9ee6..1acbadb 100644 --- a/lib/libutil/gr_util.c +++ b/lib/libutil/gr_util.c @@ -141,13 +141,13 @@ gr_tmp(int mfd) errno = ENAMETOOLONG; return (-1); } - if ((tfd = mkostemp(tempname, O_SYNC)) == -1) + if ((tfd = mkstemp(tempname)) == -1) return (-1); if (mfd != -1) { while ((nr = read(mfd, buf, sizeof(buf))) > 0) if (write(tfd, buf, (size_t)nr) != nr) break; - if (nr != 0) { + if (nr != 0 || fsync(tfd) != 0) { unlink(tempname); *tempname = '\0'; close(tfd); @@ -305,6 +305,8 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr) done: if (line != NULL) free(line); + if (fsync(tfd) != 0) + goto err; return (0); err: if (line != NULL) -- cgit v1.1