From 429045514512b2791a0297f08c7024c389d41981 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Fri, 14 Mar 2014 17:07:52 -0400 Subject: [PATCH] Sentinel: Notify user when config can't be saved --- src/sentinel.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/sentinel.c b/src/sentinel.c index c7739de8b..be1591c98 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -1562,19 +1562,22 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) { void sentinelFlushConfig(void) { int fd; int saved_hz = server.hz; + int rewrite_status; server.hz = REDIS_DEFAULT_HZ; - if (rewriteConfig(server.configfile) != -1) { - /* Rewrite succeded, fsync it. */ - if ((fd = open(server.configfile,O_RDONLY)) != -1) { - fsync(fd); - close(fd); - } - } else { - redisLog(REDIS_WARNING,"WARNING: Sentinel was not able to save the new configuration on disk!!!: %s", strerror(errno)); - } + rewrite_status = rewriteConfig(server.configfile); server.hz = saved_hz; + + if (rewrite_status == -1) goto werr; + if ((fd = open(server.configfile,O_RDONLY)) == -1) goto werr; + if (fsync(fd) == -1) goto werr; + if (close(fd) == EOF) goto werr; + return; + +werr: + if (fd != -1) close(fd); + redisLog(REDIS_WARNING,"WARNING: Sentinel was not able to save the new configuration on disk!!!: %s", strerror(errno)); } /* ====================== hiredis connection handling ======================= */