Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
a461376c
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a461376c
编写于
5月 14, 2013
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CONFIG REWRITE: remove orphaned lines.
上级
8cf0b666
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
43 addition
and
1 deletion
+43
-1
src/config.c
src/config.c
+43
-1
未找到文件。
src/config.c
浏览文件 @
a461376c
...
...
@@ -1218,6 +1218,7 @@ void rewriteConfigBytesOption(struct rewriteConfigState *state, char *option, lo
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
/* Rewrite a yes/no option. */
void
rewriteConfigYesNoOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
int
value
,
int
defvalue
)
{
int
force
=
value
!=
defvalue
;
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %s"
,
option
,
...
...
@@ -1226,6 +1227,7 @@ void rewriteConfigYesNoOption(struct rewriteConfigState *state, char *option, in
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
/* Rewrite a string option. */
void
rewriteConfigStringOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
char
*
value
,
char
*
defvalue
)
{
int
force
=
1
;
sds
line
;
...
...
@@ -1244,6 +1246,7 @@ void rewriteConfigStringOption(struct rewriteConfigState *state, char *option, c
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
)
{
int
force
=
value
!=
defvalue
;
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %lld"
,
option
,
value
);
...
...
@@ -1251,6 +1254,7 @@ void rewriteConfigNumericalOption(struct rewriteConfigState *state, char *option
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
/* Rewrite a octal option. */
void
rewriteConfigOctalOption
(
struct
rewriteConfigState
*
state
,
char
*
option
,
int
value
,
int
defvalue
)
{
int
force
=
value
!=
defvalue
;
sds
line
=
sdscatprintf
(
sdsempty
(),
"%s %o"
,
option
,
value
);
...
...
@@ -1258,6 +1262,9 @@ void rewriteConfigOctalOption(struct rewriteConfigState *state, char *option, in
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
,
...)
{
va_list
ap
;
char
*
enum_name
,
*
matching_name
;
...
...
@@ -1281,6 +1288,7 @@ void rewriteConfigEnumOption(struct rewriteConfigState *state, char *option, int
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
/* Rewrite the syslog-fability option. */
void
rewriteConfigSyslogfacilityOption
(
struct
rewriteConfigState
*
state
)
{
int
value
=
server
.
syslog_facility
,
j
;
int
force
=
value
!=
LOG_LOCAL0
;
...
...
@@ -1297,6 +1305,7 @@ void rewriteConfigSyslogfacilityOption(struct rewriteConfigState *state) {
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
/* Rewrite the save option. */
void
rewriteConfigSaveOption
(
struct
rewriteConfigState
*
state
)
{
int
j
;
sds
line
;
...
...
@@ -1311,6 +1320,7 @@ void rewriteConfigSaveOption(struct rewriteConfigState *state) {
}
}
/* Rewrite the dir option, always using absolute paths.*/
void
rewriteConfigDirOption
(
struct
rewriteConfigState
*
state
)
{
char
cwd
[
1024
];
...
...
@@ -1318,6 +1328,7 @@ void rewriteConfigDirOption(struct rewriteConfigState *state) {
rewriteConfigStringOption
(
state
,
"dir"
,
cwd
,
NULL
);
}
/* Rewrite the slaveof option. */
void
rewriteConfigSlaveofOption
(
struct
rewriteConfigState
*
state
)
{
char
*
option
=
"slaveof"
;
sds
line
;
...
...
@@ -1330,6 +1341,7 @@ void rewriteConfigSlaveofOption(struct rewriteConfigState *state) {
rewriteConfigRewriteLine
(
state
,
option
,
line
,
1
);
}
/* Rewrite the appendonly option. */
void
rewriteConfigAppendonlyOption
(
struct
rewriteConfigState
*
state
)
{
int
force
=
server
.
aof_state
!=
REDIS_AOF_OFF
;
char
*
option
=
"appendonly"
;
...
...
@@ -1340,6 +1352,7 @@ void rewriteConfigAppendonlyOption(struct rewriteConfigState *state) {
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
/* Rewrite the notify-keyspace-events option. */
void
rewriteConfigNotifykeyspaceeventsOption
(
struct
rewriteConfigState
*
state
)
{
int
force
=
server
.
notify_keyspace_events
!=
0
;
char
*
option
=
"notify-keyspace-events"
;
...
...
@@ -1351,6 +1364,7 @@ void rewriteConfigNotifykeyspaceeventsOption(struct rewriteConfigState *state) {
rewriteConfigRewriteLine
(
state
,
option
,
line
,
force
);
}
/* Rewrite the client-output-buffer-limit option. */
void
rewriteConfigClientoutputbufferlimitOption
(
struct
rewriteConfigState
*
state
)
{
int
j
;
char
*
option
=
"client-output-buffer-limit"
;
...
...
@@ -1394,12 +1408,40 @@ sds rewriteConfigGetContentFromState(struct rewriteConfigState *state) {
return
content
;
}
/* Free the configuration rewrite state. */
void
rewriteConfigReleaseState
(
struct
rewriteConfigState
*
state
)
{
sdsfreesplitres
(
state
->
lines
,
state
->
numlines
);
dictRelease
(
state
->
option_to_line
);
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".
* If the configuration file already exists, we try at best to retain comments
* and overall structure.
...
...
@@ -1497,7 +1539,7 @@ int rewriteConfig(char *path) {
/* 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
* of multiple "save" options or duplicated options. */
//
rewriteConfigRemoveOrphaned(state);
rewriteConfigRemoveOrphaned
(
state
);
/* Step 4: generate a new configuration file from the modified state
* and write it into the original file. */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录