diff --git a/src/config.c b/src/config.c index 2442ace8e..2f9721f58 100644 --- a/src/config.c +++ b/src/config.c @@ -1683,7 +1683,7 @@ int rewriteConfigOverwriteFile(char *configfile, sds content) { if (fsync(fd)) serverLog(LL_WARNING, "Could not sync tmp config file to disk (%s)", strerror(errno)); - else if (fchmod(fd, 0644) == -1) + else if (fchmod(fd, 0644 & ~server.umask) == -1) serverLog(LL_WARNING, "Could not chmod config file (%s)", strerror(errno)); else if (rename(tmp_conffile, configfile) == -1) serverLog(LL_WARNING, "Could not rename tmp config file (%s)", strerror(errno)); diff --git a/src/server.c b/src/server.c index 1b8bc0c42..dc661b6e2 100644 --- a/src/server.c +++ b/src/server.c @@ -5753,6 +5753,12 @@ int main(int argc, char **argv) { init_genrand64(((long long) tv.tv_sec * 1000000 + tv.tv_usec) ^ getpid()); crc64_init(); + /* Store umask value. Because umask(2) only offers a set-and-get API we have + * to reset it and restore it back. We do this early to avoid a potential + * race condition with threads that could be creating files or directories. + */ + umask(server.umask = umask(0777)); + uint8_t hashseed[16]; getRandomBytes(hashseed,sizeof(hashseed)); dictSetHashFunctionSeed(hashseed); diff --git a/src/server.h b/src/server.h index 0de7b3a1e..13144ce32 100644 --- a/src/server.h +++ b/src/server.h @@ -1124,6 +1124,7 @@ struct redisServer { int config_hz; /* Configured HZ value. May be different than the actual 'hz' field value if dynamic-hz is enabled. */ + mode_t umask; /* The umask value of the process on startup */ int hz; /* serverCron() calls frequency in hertz */ int in_fork_child; /* indication that this is a fork child */ redisDb *db;