mirror of https://mirror.osredm.com/root/redis.git
chdir to dir before fopen logfile in loadServerConfigFromString() (#6741)
Open the log file only after parsing the entire config file, so that it's location isn't dependent on the order of configs (`dir` and `logfile`). Also solves the problem of creating multiple log files if the `logfile` directive appears many times in the config file.
This commit is contained in:
parent
561c69c285
commit
4c52aa9faa
27
src/config.c
27
src/config.c
|
@ -492,21 +492,8 @@ void loadServerConfigFromString(char *config) {
|
||||||
goto loaderr;
|
goto loaderr;
|
||||||
}
|
}
|
||||||
} else if (!strcasecmp(argv[0],"logfile") && argc == 2) {
|
} else if (!strcasecmp(argv[0],"logfile") && argc == 2) {
|
||||||
FILE *logfp;
|
|
||||||
|
|
||||||
zfree(server.logfile);
|
zfree(server.logfile);
|
||||||
server.logfile = zstrdup(argv[1]);
|
server.logfile = zstrdup(argv[1]);
|
||||||
if (server.logfile[0] != '\0') {
|
|
||||||
/* Test if we are able to open the file. The server will not
|
|
||||||
* be able to abort just for this problem later... */
|
|
||||||
logfp = fopen(server.logfile,"a");
|
|
||||||
if (logfp == NULL) {
|
|
||||||
err = sdscatprintf(sdsempty(),
|
|
||||||
"Can't open the log file: %s", strerror(errno));
|
|
||||||
goto loaderr;
|
|
||||||
}
|
|
||||||
fclose(logfp);
|
|
||||||
}
|
|
||||||
} else if (!strcasecmp(argv[0],"include") && argc == 2) {
|
} else if (!strcasecmp(argv[0],"include") && argc == 2) {
|
||||||
loadServerConfig(argv[1], 0, NULL);
|
loadServerConfig(argv[1], 0, NULL);
|
||||||
} else if ((!strcasecmp(argv[0],"slaveof") ||
|
} else if ((!strcasecmp(argv[0],"slaveof") ||
|
||||||
|
@ -615,6 +602,20 @@ void loadServerConfigFromString(char *config) {
|
||||||
sdsfreesplitres(argv,argc);
|
sdsfreesplitres(argv,argc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (server.logfile[0] != '\0') {
|
||||||
|
FILE *logfp;
|
||||||
|
|
||||||
|
/* Test if we are able to open the file. The server will not
|
||||||
|
* be able to abort just for this problem later... */
|
||||||
|
logfp = fopen(server.logfile,"a");
|
||||||
|
if (logfp == NULL) {
|
||||||
|
err = sdscatprintf(sdsempty(),
|
||||||
|
"Can't open the log file: %s", strerror(errno));
|
||||||
|
goto loaderr;
|
||||||
|
}
|
||||||
|
fclose(logfp);
|
||||||
|
}
|
||||||
|
|
||||||
/* Sanity checks. */
|
/* Sanity checks. */
|
||||||
if (server.cluster_enabled && server.masterhost) {
|
if (server.cluster_enabled && server.masterhost) {
|
||||||
linenum = slaveof_linenum;
|
linenum = slaveof_linenum;
|
||||||
|
|
Loading…
Reference in New Issue