Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
78f94d90
Commit
78f94d90
authored
May 14, 2013
by
antirez
Browse files
CONFIG REWRITE: remove orphaned lines.
parent
ee721f1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/config.c
View file @
78f94d90
...
@@ -1241,6 +1241,7 @@ void rewriteConfigBytesOption(struct rewriteConfigState *state, char *option, lo
...
@@ -1241,6 +1241,7 @@ void rewriteConfigBytesOption(struct rewriteConfigState *state, char *option, lo
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite a yes/no option. */
void
rewriteConfigYesNoOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
int
value
,
int
defvalue
)
{
void
rewriteConfigYesNoOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
int
value
,
int
defvalue
)
{
int
force
=
value
!=
defvalue
;
int
force
=
value
!=
defvalue
;
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %s"
,
option
,
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %s"
,
option
,
...
@@ -1249,6 +1250,7 @@ void rewriteConfigYesNoOption(struct rewriteConfigState *state, char *option, in
...
@@ -1249,6 +1250,7 @@ void rewriteConfigYesNoOption(struct rewriteConfigState *state, char *option, in
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite a string option. */
void
rewriteConfigStringOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
char
*
value
,
char
*
defvalue
)
{
void
rewriteConfigStringOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
char
*
value
,
char
*
defvalue
)
{
int
force
=
1
;
int
force
=
1
;
sds
line
;
sds
line
;
...
@@ -1267,6 +1269,7 @@ void rewriteConfigStringOption(struct rewriteConfigState *state, char *option, c
...
@@ -1267,6 +1269,7 @@ void rewriteConfigStringOption(struct rewriteConfigState *state, char *option, c
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite a numerical (long long range) option. */
void
rewriteConfigNumericalOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
long
long
value
,
long
long
defvalue
)
{
void
rewriteConfigNumericalOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
long
long
value
,
long
long
defvalue
)
{
int
force
=
value
!=
defvalue
;
int
force
=
value
!=
defvalue
;
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %lld"
,
option
,
value
);
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %lld"
,
option
,
value
);
...
@@ -1274,6 +1277,7 @@ void rewriteConfigNumericalOption(struct rewriteConfigState *state, char *option
...
@@ -1274,6 +1277,7 @@ void rewriteConfigNumericalOption(struct rewriteConfigState *state, char *option
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite a octal option. */
void
rewriteConfigOctalOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
int
value
,
int
defvalue
)
{
void
rewriteConfigOctalOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
int
value
,
int
defvalue
)
{
int
force
=
value
!=
defvalue
;
int
force
=
value
!=
defvalue
;
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %o"
,
option
,
value
);
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %o"
,
option
,
value
);
...
@@ -1281,6 +1285,9 @@ void rewriteConfigOctalOption(struct rewriteConfigState *state, char *option, in
...
@@ -1281,6 +1285,9 @@ void rewriteConfigOctalOption(struct rewriteConfigState *state, char *option, in
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite an enumeration option, after the "value" every enum/value pair
* is specified, terminated by NULL. After NULL the default value is
* specified. See how the function is used for more information. */
void
rewriteConfigEnumOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
int
value
,
...)
{
void
rewriteConfigEnumOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
int
value
,
...)
{
va_list
ap
;
va_list
ap
;
char
*
enum_name
,
*
matching_name
;
char
*
enum_name
,
*
matching_name
;
...
@@ -1304,6 +1311,7 @@ void rewriteConfigEnumOption(struct rewriteConfigState *state, char *option, int
...
@@ -1304,6 +1311,7 @@ void rewriteConfigEnumOption(struct rewriteConfigState *state, char *option, int
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite the syslog-fability option. */
void
rewriteConfigSyslogfacilityOption
(
struct
rewriteConfigState
*
state
)
{
void
rewriteConfigSyslogfacilityOption
(
struct
rewriteConfigState
*
state
)
{
int
value
=
server
.
syslog_facility
,
j
;
int
value
=
server
.
syslog_facility
,
j
;
int
force
=
value
!=
LOG_LOCAL0
;
int
force
=
value
!=
LOG_LOCAL0
;
...
@@ -1320,6 +1328,7 @@ void rewriteConfigSyslogfacilityOption(struct rewriteConfigState *state) {
...
@@ -1320,6 +1328,7 @@ void rewriteConfigSyslogfacilityOption(struct rewriteConfigState *state) {
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite the save option. */
void
rewriteConfigSaveOption
(
struct
rewriteConfigState
*
state
)
{
void
rewriteConfigSaveOption
(
struct
rewriteConfigState
*
state
)
{
int
j
;
int
j
;
sds
line
;
sds
line
;
...
@@ -1334,6 +1343,7 @@ void rewriteConfigSaveOption(struct rewriteConfigState *state) {
...
@@ -1334,6 +1343,7 @@ void rewriteConfigSaveOption(struct rewriteConfigState *state) {
}
}
}
}
/* Rewrite the dir option, always using absolute paths.*/
void
rewriteConfigDirOption
(
struct
rewriteConfigState
*
state
)
{
void
rewriteConfigDirOption
(
struct
rewriteConfigState
*
state
)
{
char
cwd
[
1024
];
char
cwd
[
1024
];
...
@@ -1341,6 +1351,7 @@ void rewriteConfigDirOption(struct rewriteConfigState *state) {
...
@@ -1341,6 +1351,7 @@ void rewriteConfigDirOption(struct rewriteConfigState *state) {
rewriteConfigStringOption
(
state
,
"dir"
,
cwd
,
NULL
);
rewriteConfigStringOption
(
state
,
"dir"
,
cwd
,
NULL
);
}
}
/* Rewrite the slaveof option. */
void
rewriteConfigSlaveofOption
(
struct
rewriteConfigState
*
state
)
{
void
rewriteConfigSlaveofOption
(
struct
rewriteConfigState
*
state
)
{
char
*
option
=
"slaveof"
;
char
*
option
=
"slaveof"
;
sds
line
;
sds
line
;
...
@@ -1353,6 +1364,7 @@ void rewriteConfigSlaveofOption(struct rewriteConfigState *state) {
...
@@ -1353,6 +1364,7 @@ void rewriteConfigSlaveofOption(struct rewriteConfigState *state) {
rewriteConfigRewriteLine
(
state
,
option
,
line
,
1
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
1
);
}
}
/* Rewrite the appendonly option. */
void
rewriteConfigAppendonlyOption
(
struct
rewriteConfigState
*
state
)
{
void
rewriteConfigAppendonlyOption
(
struct
rewriteConfigState
*
state
)
{
int
force
=
server
.
aof_state
!=
REDIS_AOF_OFF
;
int
force
=
server
.
aof_state
!=
REDIS_AOF_OFF
;
char
*
option
=
"appendonly"
;
char
*
option
=
"appendonly"
;
...
@@ -1363,6 +1375,7 @@ void rewriteConfigAppendonlyOption(struct rewriteConfigState *state) {
...
@@ -1363,6 +1375,7 @@ void rewriteConfigAppendonlyOption(struct rewriteConfigState *state) {
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite the notify-keyspace-events option. */
void
rewriteConfigNotifykeyspaceeventsOption
(
struct
rewriteConfigState
*
state
)
{
void
rewriteConfigNotifykeyspaceeventsOption
(
struct
rewriteConfigState
*
state
)
{
int
force
=
server
.
notify_keyspace_events
!=
0
;
int
force
=
server
.
notify_keyspace_events
!=
0
;
char
*
option
=
"notify-keyspace-events"
;
char
*
option
=
"notify-keyspace-events"
;
...
@@ -1374,6 +1387,7 @@ void rewriteConfigNotifykeyspaceeventsOption(struct rewriteConfigState *state) {
...
@@ -1374,6 +1387,7 @@ void rewriteConfigNotifykeyspaceeventsOption(struct rewriteConfigState *state) {
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
}
/* Rewrite the client-output-buffer-limit option. */
void
rewriteConfigClientoutputbufferlimitOption
(
struct
rewriteConfigState
*
state
)
{
void
rewriteConfigClientoutputbufferlimitOption
(
struct
rewriteConfigState
*
state
)
{
int
j
;
int
j
;
char
*
option
=
"client-output-buffer-limit"
;
char
*
option
=
"client-output-buffer-limit"
;
...
@@ -1417,12 +1431,40 @@ sds rewriteConfigGetContentFromState(struct rewriteConfigState *state) {
...
@@ -1417,12 +1431,40 @@ sds rewriteConfigGetContentFromState(struct rewriteConfigState *state) {
return
content
;
return
content
;
}
}
/* Free the configuration rewrite state. */
void
rewriteConfigReleaseState
(
struct
rewriteConfigState
*
state
)
{
void
rewriteConfigReleaseState
(
struct
rewriteConfigState
*
state
)
{
sdsfreesplitres
(
state
->
lines
,
state
->
numlines
);
sdsfreesplitres
(
state
->
lines
,
state
->
numlines
);
dictRelease
(
state
->
option_to_line
);
dictRelease
(
state
->
option_to_line
);
zfree
(
state
);
zfree
(
state
);
}
}
/* At the end of the rewrite process the state contains the remaining
* map between "option name" => "lines in the original config file".
* Lines used by the rewrite process were removed by the function
* rewriteConfigRewriteLine(), all the other lines are "orphaned" and
* should be replaced by empty lines.
*
* This function does just this, iterating all the option names and
* blanking all the lines still associated. */
void
rewriteConfigRemoveOrphaned
(
struct
rewriteConfigState
*
state
)
{
dictIterator
*
di
=
dictGetIterator
(
state
->
option_to_line
);
dictEntry
*
de
;
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
list
*
l
=
dictGetVal
(
de
);
while
(
listLength
(
l
))
{
listNode
*
ln
=
listFirst
(
l
);
int
linenum
=
(
long
)
ln
->
value
;
sdsfree
(
state
->
lines
[
linenum
]);
state
->
lines
[
linenum
]
=
sdsempty
();
listDelNode
(
l
,
ln
);
}
}
dictReleaseIterator
(
di
);
}
/* 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.
...
@@ -1520,7 +1562,7 @@ int rewriteConfig(char *path) {
...
@@ -1520,7 +1562,7 @@ int rewriteConfig(char *path) {
/* Step 3: remove all the orphaned lines in the old file, that is, lines
/* Step 3: remove all the orphaned lines in the old file, that is, lines
* that were used by a config option and are no longer used, like in case
* that were used by a config option and are no longer used, like in case
* of multiple "save" options or duplicated options. */
* of multiple "save" options or duplicated options. */
//
rewriteConfigRemoveOrphaned(state);
rewriteConfigRemoveOrphaned
(
state
);
/* Step 4: generate a new configuration file from the modified state
/* Step 4: generate a new configuration file from the modified state
* and write it into the original file. */
* and write it into the original file. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment