MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rewriteConfig

Function rewriteConfig

app/redis-6.2.6/src/config.c:1677–1722  ·  view source on GitHub ↗

Rewrite the configuration file at "path". * If the configuration file already exists, we try at best to retain comments * and overall structure. * * Configuration parameters that are at their default value, unless already * 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 current

Source from the content-addressed store, hash-verified

1675 *
1676 * On error -1 is returned and errno is set accordingly, otherwise 0. */
1677int rewriteConfig(char *path, int force_all) {
1678 struct rewriteConfigState *state;
1679 sds newcontent;
1680 int retval;
1681
1682 /* Step 1: read the old config into our rewrite state. */
1683 if ((state = rewriteConfigReadOldFile(path)) == NULL) return -1;
1684 if (force_all) state->force_all = 1;
1685
1686 /* Step 2: rewrite every single option, replacing or appending it inside
1687 * the rewrite state. */
1688
1689 /* Iterate the configs that are standard */
1690 for (standardConfig *config = configs; config->name != NULL; config++) {
1691 config->interface.rewrite(config->data, config->name, state);
1692 }
1693
1694 rewriteConfigBindOption(state);
1695 rewriteConfigOctalOption(state,"unixsocketperm",server.unixsocketperm,CONFIG_DEFAULT_UNIX_SOCKET_PERM);
1696 rewriteConfigStringOption(state,"logfile",server.logfile,CONFIG_DEFAULT_LOGFILE);
1697 rewriteConfigSaveOption(state);
1698 rewriteConfigUserOption(state);
1699 rewriteConfigDirOption(state);
1700 rewriteConfigSlaveofOption(state,"replicaof");
1701 rewriteConfigStringOption(state,"cluster-config-file",server.cluster_configfile,CONFIG_DEFAULT_CLUSTER_CONFIG_FILE);
1702 rewriteConfigNotifykeyspaceeventsOption(state);
1703 rewriteConfigClientoutputbufferlimitOption(state);
1704 rewriteConfigOOMScoreAdjValuesOption(state);
1705
1706 /* Rewrite Sentinel config if in Sentinel mode. */
1707 if (server.sentinel_mode) rewriteConfigSentinelOption(state);
1708
1709 /* Step 3: remove all the orphaned lines in the old file, that is, lines
1710 * that were used by a config option and are no longer used, like in case
1711 * of multiple "save" options or duplicated options. */
1712 rewriteConfigRemoveOrphaned(state);
1713
1714 /* Step 4: generate a new configuration file from the modified state
1715 * and write it into the original file. */
1716 newcontent = rewriteConfigGetContentFromState(state);
1717 retval = rewriteConfigOverwriteFile(server.configfile,newcontent);
1718
1719 sdsfree(newcontent);
1720 rewriteConfigReleaseState(state);
1721 return retval;
1722}
1723
1724/*-----------------------------------------------------------------------------
1725 * Configs that fit one of the major types and require no special handling

Callers 4

configCommandFunction · 0.85
sentinelFlushConfigFunction · 0.85
restartServerFunction · 0.85
debugCommandFunction · 0.85

Tested by

no test coverage detected