summaryrefslogtreecommitdiff
path: root/src/cluster.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cluster.c')
-rw-r--r--src/cluster.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 51e59cb7a..f5291c499 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -142,9 +142,15 @@ int clusterLoadConfig(char *filename) {
}
}
+ if (redis_fstat(fileno(fp),&sb) == -1) {
+ serverLog(LL_WARNING,
+ "Unable to obtain the cluster node config file stat %s: %s",
+ filename, strerror(errno));
+ exit(1);
+ }
/* Check if the file is zero-length: if so return C_ERR to signal
* we have to write the config. */
- if (fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) {
+ if (sb.st_size == 0) {
fclose(fp);
return C_ERR;
}
@@ -383,13 +389,14 @@ int clusterSaveConfig(int do_fsync) {
if ((fd = open(server.cluster_configfile,O_WRONLY|O_CREAT,0644))
== -1) goto err;
+ if (redis_fstat(fd,&sb) == -1) goto err;
+
/* Pad the new payload if the existing file length is greater. */
- if (fstat(fd,&sb) != -1) {
- if (sb.st_size > (off_t)content_size) {
- ci = sdsgrowzero(ci,sb.st_size);
- memset(ci+content_size,'\n',sb.st_size-content_size);
- }
+ if (sb.st_size > (off_t)content_size) {
+ ci = sdsgrowzero(ci,sb.st_size);
+ memset(ci+content_size,'\n',sb.st_size-content_size);
}
+
if (write(fd,ci,sdslen(ci)) != (ssize_t)sdslen(ci)) goto err;
if (do_fsync) {
server.cluster->todo_before_sleep &= ~CLUSTER_TODO_FSYNC_CONFIG;