mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 08:08:53 -05:00
CONFIG REWRITE should honor umask settings. (#8371)
Fixes a regression introduced due to a new (safer) way of rewriting configuration files. In the past the file was simply overwritten (same inode), but now Redis creates a new temporary file and later renames it over the old one. The temp file typically gets created with 0600 permissions so we later fchmod it to fix that. Unlike open with O_CREAT, fchmod doesn't consider umask so we have to do that explicitly. Fixes #8369
This commit is contained in:
parent
ac5f21d613
commit
b548ffabbe
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user