From 99799f94bd83e6e3821bed79cef8571670c3f021 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 20 Nov 2012 14:03:09 +0000 Subject: only rename(2) after chmod(2) has succeed report error if chmod(2) fails Reported by: jh --- libutil/gr_util.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libutil/gr_util.c b/libutil/gr_util.c index 8d0490b..be34395 100644 --- a/libutil/gr_util.c +++ b/libutil/gr_util.c @@ -318,14 +318,10 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr) int gr_mkdb(void) { - int ret; - - ret = rename(tempname, group_file); - - if (ret == 0) - chmod(group_file, 0644); + if (chmod(tempname, 0644) != 0) + return (-1); - return (ret); + return (rename(tempname, group_file)); } /* -- cgit v1.2.3-56-ge451