"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/config.c" between
redis-6.0.7.tar.gz and redis-6.0.8.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

config.c  (redis-6.0.7):config.c  (redis-6.0.8)
skipping to change at line 1057 skipping to change at line 1057
}; };
/* The config rewrite state. */ /* The config rewrite state. */
struct rewriteConfigState { struct rewriteConfigState {
dict *option_to_line; /* Option -> list of config file lines map */ dict *option_to_line; /* Option -> list of config file lines map */
dict *rewritten; /* Dictionary of already processed options */ dict *rewritten; /* Dictionary of already processed options */
int numlines; /* Number of lines in current config */ int numlines; /* Number of lines in current config */
sds *lines; /* Current lines as an array of sds strings */ sds *lines; /* Current lines as an array of sds strings */
int has_tail; /* True if we already added directives that were int has_tail; /* True if we already added directives that were
not present in the original config file. */ not present in the original config file. */
int force_all; /* True if we want all keywords to be force
written. Currently only used for testing. */
}; };
/* Append the new line to the current configuration state. */ /* Append the new line to the current configuration state. */
void rewriteConfigAppendLine(struct rewriteConfigState *state, sds line) { void rewriteConfigAppendLine(struct rewriteConfigState *state, sds line) {
state->lines = zrealloc(state->lines, sizeof(char*) * (state->numlines+1)); state->lines = zrealloc(state->lines, sizeof(char*) * (state->numlines+1));
state->lines[state->numlines++] = line; state->lines[state->numlines++] = line;
} }
/* Populate the option -> list of line numbers map. */ /* Populate the option -> list of line numbers map. */
void rewriteConfigAddLineNumberToOption(struct rewriteConfigState *state, sds op tion, int linenum) { void rewriteConfigAddLineNumberToOption(struct rewriteConfigState *state, sds op tion, int linenum) {
skipping to change at line 1103 skipping to change at line 1105
if (fp == NULL && errno != ENOENT) return NULL; if (fp == NULL && errno != ENOENT) return NULL;
char buf[CONFIG_MAX_LINE+1]; char buf[CONFIG_MAX_LINE+1];
int linenum = -1; int linenum = -1;
struct rewriteConfigState *state = zmalloc(sizeof(*state)); struct rewriteConfigState *state = zmalloc(sizeof(*state));
state->option_to_line = dictCreate(&optionToLineDictType,NULL); state->option_to_line = dictCreate(&optionToLineDictType,NULL);
state->rewritten = dictCreate(&optionSetDictType,NULL); state->rewritten = dictCreate(&optionSetDictType,NULL);
state->numlines = 0; state->numlines = 0;
state->lines = NULL; state->lines = NULL;
state->has_tail = 0; state->has_tail = 0;
state->force_all = 0;
if (fp == NULL) return state; if (fp == NULL) return state;
/* Read the old file line by line, populate the state. */ /* Read the old file line by line, populate the state. */
while(fgets(buf,CONFIG_MAX_LINE+1,fp) != NULL) { while(fgets(buf,CONFIG_MAX_LINE+1,fp) != NULL) {
int argc; int argc;
sds *argv; sds *argv;
sds line = sdstrim(sdsnew(buf),"\r\n\t "); sds line = sdstrim(sdsnew(buf),"\r\n\t ");
linenum++; /* Zero based, so we init at -1 */ linenum++; /* Zero based, so we init at -1 */
skipping to change at line 1181 skipping to change at line 1184
* by CONFIG REWRITE. * by CONFIG REWRITE.
* *
* "line" is either used, or freed, so the caller does not need to free it * "line" is either used, or freed, so the caller does not need to free it
* in any way. */ * in any way. */
void rewriteConfigRewriteLine(struct rewriteConfigState *state, const char *opti on, sds line, int force) { void rewriteConfigRewriteLine(struct rewriteConfigState *state, const char *opti on, sds line, int force) {
sds o = sdsnew(option); sds o = sdsnew(option);
list *l = dictFetchValue(state->option_to_line,o); list *l = dictFetchValue(state->option_to_line,o);
rewriteConfigMarkAsProcessed(state,option); rewriteConfigMarkAsProcessed(state,option);
if (!l && !force) { if (!l && !force && !state->force_all) {
/* Option not used previously, and we are not forced to use it. */ /* Option not used previously, and we are not forced to use it. */
sdsfree(line); sdsfree(line);
sdsfree(o); sdsfree(o);
return; return;
} }
if (l) { if (l) {
listNode *ln = listFirst(l); listNode *ln = listFirst(l);
int linenum = (long) ln->value; int linenum = (long) ln->value;
skipping to change at line 1424 skipping to change at line 1427
} }
} }
/* Rewrite the oom-score-adj-values option. */ /* Rewrite the oom-score-adj-values option. */
void rewriteConfigOOMScoreAdjValuesOption(struct rewriteConfigState *state) { void rewriteConfigOOMScoreAdjValuesOption(struct rewriteConfigState *state) {
int force = 0; int force = 0;
int j; int j;
char *option = "oom-score-adj-values"; char *option = "oom-score-adj-values";
sds line; sds line;
line = sdsempty(); line = sdsnew(option);
line = sdscatlen(line, " ", 1);
for (j = 0; j < CONFIG_OOM_COUNT; j++) { for (j = 0; j < CONFIG_OOM_COUNT; j++) {
if (server.oom_score_adj_values[j] != configOOMScoreAdjValuesDefaults[j] ) if (server.oom_score_adj_values[j] != configOOMScoreAdjValuesDefaults[j] )
force = 1; force = 1;
line = sdscatprintf(line, "%d", server.oom_score_adj_values[j]); line = sdscatprintf(line, "%d", server.oom_score_adj_values[j]);
if (j+1 != CONFIG_OOM_COUNT) if (j+1 != CONFIG_OOM_COUNT)
line = sdscatlen(line, " ", 1); line = sdscatlen(line, " ", 1);
} }
rewriteConfigRewriteLine(state,option,line,force); rewriteConfigRewriteLine(state,option,line,force);
} }
skipping to change at line 1604 skipping to change at line 1608
close(fd); close(fd);
return retval; return retval;
} }
/* Rewrite the configuration file at "path". /* Rewrite the configuration file at "path".
* If the configuration file already exists, we try at best to retain comments * If the configuration file already exists, we try at best to retain comments
* and overall structure. * and overall structure.
* *
* Configuration parameters that are at their default value, unless already * Configuration parameters that are at their default value, unless already
* explicitly included in the old configuration file, are not rewritten. * explicitly included in the old configuration file, are not rewritten.
* The force_all flag overrides this behavior and forces everything to be
* written. This is currently only used for testing purposes.
* *
* On error -1 is returned and errno is set accordingly, otherwise 0. */ * On error -1 is returned and errno is set accordingly, otherwise 0. */
int rewriteConfig(char *path) { int rewriteConfig(char *path, int force_all) {
struct rewriteConfigState *state; struct rewriteConfigState *state;
sds newcontent; sds newcontent;
int retval; int retval;
/* Step 1: read the old config into our rewrite state. */ /* Step 1: read the old config into our rewrite state. */
if ((state = rewriteConfigReadOldFile(path)) == NULL) return -1; if ((state = rewriteConfigReadOldFile(path)) == NULL) return -1;
if (force_all) state->force_all = 1;
/* Step 2: rewrite every single option, replacing or appending it inside /* Step 2: rewrite every single option, replacing or appending it inside
* the rewrite state. */ * the rewrite state. */
/* Iterate the configs that are standard */ /* Iterate the configs that are standard */
for (standardConfig *config = configs; config->name != NULL; config++) { for (standardConfig *config = configs; config->name != NULL; config++) {
config->interface.rewrite(config->data, config->name, state); config->interface.rewrite(config->data, config->name, state);
} }
rewriteConfigBindOption(state); rewriteConfigBindOption(state);
skipping to change at line 2406 skipping to change at line 2413
configGetCommand(c); configGetCommand(c);
} else if (!strcasecmp(c->argv[1]->ptr,"resetstat") && c->argc == 2) { } else if (!strcasecmp(c->argv[1]->ptr,"resetstat") && c->argc == 2) {
resetServerStats(); resetServerStats();
resetCommandTableStats(); resetCommandTableStats();
addReply(c,shared.ok); addReply(c,shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr,"rewrite") && c->argc == 2) { } else if (!strcasecmp(c->argv[1]->ptr,"rewrite") && c->argc == 2) {
if (server.configfile == NULL) { if (server.configfile == NULL) {
addReplyError(c,"The server is running without a config file"); addReplyError(c,"The server is running without a config file");
return; return;
} }
if (rewriteConfig(server.configfile) == -1) { if (rewriteConfig(server.configfile, 0) == -1) {
serverLog(LL_WARNING,"CONFIG REWRITE failed: %s", strerror(errno)); serverLog(LL_WARNING,"CONFIG REWRITE failed: %s", strerror(errno));
addReplyErrorFormat(c,"Rewriting config file: %s", strerror(errno)); addReplyErrorFormat(c,"Rewriting config file: %s", strerror(errno));
} else { } else {
serverLog(LL_WARNING,"CONFIG REWRITE executed with success."); serverLog(LL_WARNING,"CONFIG REWRITE executed with success.");
addReply(c,shared.ok); addReply(c,shared.ok);
} }
} else { } else {
addReplySubcommandSyntaxError(c); addReplySubcommandSyntaxError(c);
return; return;
} }
 End of changes. 8 change blocks. 
4 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)