Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
519822bc
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
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,体验更适合开发者的 AI 搜索 >>
提交
519822bc
编写于
11月 21, 2019
作者:
M
Madelyn Olson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added a flag for strings that are stored as NULL
上级
803d765d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
20 deletion
+36
-20
src/config.c
src/config.c
+36
-20
未找到文件。
src/config.c
浏览文件 @
519822bc
...
...
@@ -115,6 +115,9 @@ typedef struct boolConfigData {
typedef
struct
stringConfigData
{
char
**
config
;
/* The pointer to the server config this value is stored in */
const
char
*
default_value
;
/* The default value of the config on rewrite */
int
convert_empty_to_null
;
/* A boolean indicating if empty strings should
be stored as a NULL value. */
}
stringConfigData
;
typedef
struct
enumConfigData
{
...
...
@@ -145,7 +148,7 @@ typedef struct numericConfigData {
}
numericConfigData
;
typedef
union
typeData
{
boolConfigData
yesno
;
boolConfigData
bool
;
stringConfigData
string
;
enumConfigData
enumd
;
numericConfigData
numeric
;
...
...
@@ -166,7 +169,7 @@ typedef struct standardConfig {
const
char
*
name
;
/* The user visible name of this config */
const
char
*
alias
;
/* An alias that can also be used for this config */
const
int
modifiable
;
/* Can this value be updated by CONFIG SET? */
typeInterface
interface
;
/* The function points that define the type interface */
typeInterface
interface
;
/* The function point
er
s that define the type interface */
typeData
data
;
/* The type specific data exposed used by the interface */
}
standardConfig
;
...
...
@@ -1840,9 +1843,6 @@ int rewriteConfig(char *path) {
#define LOADBUF_SIZE 256
static
char
loadbuf
[
LOADBUF_SIZE
];
#define MEMORY_CONFIG 1
#define INTEGER_CONFIG 0
#define MODIFIABLE_CONFIG 1
#define IMMUTABLE_CONFIG 0
...
...
@@ -1876,7 +1876,7 @@ static int boolConfigLoad(typeData data, sds *argv, int argc, char **err) {
*
err
=
"wrong number of arguments"
;
return
0
;
}
if
((
*
(
data
.
yesno
.
config
)
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
if
((
*
(
data
.
bool
.
config
)
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
*
err
=
"argument must be 'yes' or 'no'"
;
return
0
;
}
...
...
@@ -1886,22 +1886,22 @@ static int boolConfigLoad(typeData data, sds *argv, int argc, char **err) {
static
int
boolConfigSet
(
typeData
data
,
sds
value
)
{
int
yn
=
yesnotoi
(
value
);
if
(
yn
==
-
1
)
return
0
;
*
(
data
.
yesno
.
config
)
=
yn
;
*
(
data
.
bool
.
config
)
=
yn
;
return
1
;
}
static
void
boolConfigGet
(
client
*
c
,
typeData
data
)
{
addReplyBulkCString
(
c
,
data
.
yesno
.
config
?
"yes"
:
"no"
);
addReplyBulkCString
(
c
,
data
.
bool
.
config
?
"yes"
:
"no"
);
}
static
void
boolConfigRewrite
(
typeData
data
,
const
char
*
name
,
struct
rewriteConfigState
*
state
)
{
rewriteConfigYesNoOption
(
state
,
name
,
*
(
data
.
yesno
.
config
),
data
.
yesno
.
default_value
);
rewriteConfigYesNoOption
(
state
,
name
,
*
(
data
.
bool
.
config
),
data
.
bool
.
default_value
);
}
#define createBoolConfig(name, alias, modifiable, config_addr, default) { \
embedCommonConfig(name, alias, modifiable) \
embedConfigInterface(boolConfigLoad, boolConfigSet, boolConfigGet, boolConfigRewrite) \
.data.
yesno
= { \
.data.
bool
= { \
.config = &(config_addr), \
.default_value = (default) \
} \
...
...
@@ -1914,13 +1914,21 @@ static int stringConfigLoad(typeData data, sds *argv, int argc, char **err) {
return
0
;
}
zfree
(
*
data
.
string
.
config
);
*
data
.
string
.
config
=
argv
[
1
][
0
]
?
zstrdup
(
argv
[
1
])
:
NULL
;
if
(
data
.
string
.
convert_empty_to_null
)
{
*
data
.
string
.
config
=
argv
[
1
][
0
]
?
zstrdup
(
argv
[
1
])
:
NULL
;
}
else
{
*
data
.
string
.
config
=
zstrdup
(
argv
[
1
]);
}
return
1
;
}
static
int
stringConfigSet
(
typeData
data
,
sds
value
)
{
zfree
(
*
data
.
string
.
config
);
*
data
.
string
.
config
=
value
?
zstrdup
(
value
)
:
NULL
;
if
(
data
.
string
.
convert_empty_to_null
)
{
*
data
.
string
.
config
=
value
[
0
]
?
zstrdup
(
value
)
:
NULL
;
}
else
{
*
data
.
string
.
config
=
zstrdup
(
value
);
}
return
1
;
}
...
...
@@ -1932,12 +1940,16 @@ static void stringConfigRewrite(typeData data, const char *name, struct rewriteC
rewriteConfigStringOption
(
state
,
name
,
*
(
data
.
string
.
config
),
data
.
string
.
default_value
);
}
#define createStringConfig(name, alias, modifiable, config_addr, default) { \
#define ALLOW_EMPTY_STRING 0
#define EMPTY_STRING_IS_NULL 1
#define createStringConfig(name, alias, modifiable, empty_to_null, config_addr, default) { \
embedCommonConfig(name, alias, modifiable) \
embedConfigInterface(stringConfigLoad, stringConfigSet, stringConfigGet, stringConfigRewrite) \
.data.string = { \
.config = &(config_addr), \
.default_value = (default), \
.convert_empty_to_null = (empty_to_null) \
} \
}
...
...
@@ -2057,6 +2069,7 @@ static int numericConfigSet(typeData data, sds value) {
ll
<
data
.
numeric
.
lower_bound
)
{
return
0
;
}
if
(
data
.
numeric
.
numeric_type
==
NUMERIC_TYPE_INT
)
{
*
(
data
.
numeric
.
config
.
i
)
=
(
int
)
ll
;
}
else
if
(
data
.
numeric
.
numeric_type
==
NUMERIC_TYPE_UNSIGNED_LONG
)
{
...
...
@@ -2107,6 +2120,9 @@ static void numericConfigRewrite(typeData data, const char *name, struct rewrite
}
}
#define INTEGER_CONFIG 0
#define MEMORY_CONFIG 1
#define embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory) { \
embedCommonConfig(name, alias, modifiable) \
embedConfigInterface(numericConfigLoad, numericConfigSet, numericConfigGet, numericConfigRewrite) \
...
...
@@ -2176,13 +2192,13 @@ standardConfig configs[] = {
createBoolConfig
(
"jemalloc-bg-thread"
,
NULL
,
MODIFIABLE_CONFIG
,
server
.
jemalloc_bg_thread
,
1
),
/* String Configs */
createStringConfig
(
"aclfile"
,
NULL
,
IMMUTABLE_CONFIG
,
server
.
acl_filename
,
CONFIG_DEFAULT_ACL_FILENAME
),
createStringConfig
(
"unixsocket"
,
NULL
,
IMMUTABLE_CONFIG
,
server
.
unixsocket
,
NULL
),
createStringConfig
(
"pidfile"
,
NULL
,
IMMUTABLE_CONFIG
,
server
.
pidfile
,
CONFIG_DEFAULT_PID_FILE
),
createStringConfig
(
"replica-announce-ip"
,
"slave-announce-ip"
,
MODIFIABLE_CONFIG
,
server
.
slave_announce_ip
,
CONFIG_DEFAULT_SLAVE_ANNOUNCE_IP
),
createStringConfig
(
"masteruser"
,
NULL
,
MODIFIABLE_CONFIG
,
server
.
masteruser
,
NULL
),
createStringConfig
(
"masterauth"
,
NULL
,
MODIFIABLE_CONFIG
,
server
.
masterauth
,
NULL
),
createStringConfig
(
"cluster-announce-ip"
,
NULL
,
MODIFIABLE_CONFIG
,
server
.
cluster_announce_ip
,
NULL
),
createStringConfig
(
"aclfile"
,
NULL
,
IMMUTABLE_CONFIG
,
ALLOW_EMPTY_STRING
,
server
.
acl_filename
,
CONFIG_DEFAULT_ACL_FILENAME
),
createStringConfig
(
"unixsocket"
,
NULL
,
IMMUTABLE_CONFIG
,
EMPTY_STRING_IS_NULL
,
server
.
unixsocket
,
NULL
),
createStringConfig
(
"pidfile"
,
NULL
,
IMMUTABLE_CONFIG
,
EMPTY_STRING_IS_NULL
,
server
.
pidfile
,
CONFIG_DEFAULT_PID_FILE
),
createStringConfig
(
"replica-announce-ip"
,
"slave-announce-ip"
,
MODIFIABLE_CONFIG
,
EMPTY_STRING_IS_NULL
,
server
.
slave_announce_ip
,
CONFIG_DEFAULT_SLAVE_ANNOUNCE_IP
),
createStringConfig
(
"masteruser"
,
NULL
,
MODIFIABLE_CONFIG
,
EMPTY_STRING_IS_NULL
,
server
.
masteruser
,
NULL
),
createStringConfig
(
"masterauth"
,
NULL
,
MODIFIABLE_CONFIG
,
EMPTY_STRING_IS_NULL
,
server
.
masterauth
,
NULL
),
createStringConfig
(
"cluster-announce-ip"
,
NULL
,
MODIFIABLE_CONFIG
,
EMPTY_STRING_IS_NULL
,
server
.
cluster_announce_ip
,
NULL
),
/* Enum Configs */
createEnumConfig
(
"supervised"
,
NULL
,
IMMUTABLE_CONFIG
,
supervised_mode_enum
,
server
.
supervised_mode
,
SUPERVISED_NONE
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录