Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
7a5d3d91
R
redis
项目概览
hanoi2005
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
7a5d3d91
编写于
5月 09, 2013
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Obtain absoute path of configuration file, expose it in INFO.
上级
d8dd70c2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
2 deletion
+59
-2
src/redis.c
src/redis.c
+58
-2
src/redis.h
src/redis.h
+1
-0
未找到文件。
src/redis.c
浏览文件 @
7a5d3d91
...
...
@@ -1163,6 +1163,7 @@ void createSharedObjects(void) {
void
initServerConfig
()
{
getRandomHexChars
(
server
.
runid
,
REDIS_RUN_ID_SIZE
);
server
.
configfile
=
NULL
;
server
.
hz
=
REDIS_DEFAULT_HZ
;
server
.
runid
[
REDIS_RUN_ID_SIZE
]
=
'\0'
;
server
.
arch_bits
=
(
sizeof
(
long
)
==
8
)
?
64
:
32
;
...
...
@@ -2006,7 +2007,8 @@ sds genRedisInfoString(char *section) {
"uptime_in_seconds:%ld
\r\n
"
"uptime_in_days:%ld
\r\n
"
"hz:%d
\r\n
"
"lru_clock:%ld
\r\n
"
,
"lru_clock:%ld
\r\n
"
"config_file:%s
\r\n
"
,
REDIS_VERSION
,
redisGitSHA1
(),
strtol
(
redisGitDirty
(),
NULL
,
10
)
>
0
,
...
...
@@ -2026,7 +2028,8 @@ sds genRedisInfoString(char *section) {
uptime
,
uptime
/
(
3600
*
24
),
server
.
hz
,
(
unsigned
long
)
server
.
lruclock
);
(
unsigned
long
)
server
.
lruclock
,
server
.
configfile
?
server
.
configfile
:
""
);
}
/* Clients */
...
...
@@ -2689,6 +2692,58 @@ void redisSetProcTitle(char *title) {
#endif
}
/* Given the filename, return the absolute path as an SDS string, or NULL
* if it fails for some reason. Note that "filename" may be an absolute path
* already, this will be detected and handled correctly.
*
* The function does not try to normalize everything, but only the obvious
* case of one or more "../" appearning at the start of "filename"
* relative path. */
sds
getAbsolutePath
(
char
*
filename
)
{
char
cwd
[
1024
];
sds
abspath
;
sds
relpath
=
sdsnew
(
filename
);
relpath
=
sdstrim
(
relpath
,
"
\r\n\t
"
);
if
(
relpath
[
0
]
==
'/'
)
return
relpath
;
/* Path is already absolute. */
/* If path is relative, join cwd and relative path. */
if
(
getcwd
(
cwd
,
sizeof
(
cwd
))
==
NULL
)
{
sdsfree
(
relpath
);
return
NULL
;
}
abspath
=
sdsnew
(
cwd
);
if
(
sdslen
(
abspath
)
&&
abspath
[
sdslen
(
abspath
)
-
1
]
!=
'/'
)
abspath
=
sdscat
(
abspath
,
"/"
);
/* At this point we have the current path always ending with "/", and
* the trimmed relative path. Try to normalize the obvious case of
* trailing ../ elements at the start of the path.
*
* For every "../" we find in the filename, we remove it and also remove
* the last element of the cwd, unless the current cwd is "/". */
while
(
sdslen
(
relpath
)
>=
3
&&
relpath
[
0
]
==
'.'
&&
relpath
[
1
]
==
'.'
&&
relpath
[
2
]
==
'/'
)
{
relpath
=
sdsrange
(
relpath
,
3
,
-
1
);
if
(
sdslen
(
abspath
)
>
1
)
{
char
*
p
=
abspath
+
sdslen
(
abspath
)
-
2
;
int
trimlen
=
1
;
while
(
*
p
!=
'/'
)
{
p
--
;
trimlen
++
;
}
abspath
=
sdsrange
(
abspath
,
0
,
-
(
trimlen
+
1
));
}
}
/* Finally glue the two parts together. */
abspath
=
sdscatsds
(
abspath
,
relpath
);
sdsfree
(
relpath
);
return
abspath
;
}
int
main
(
int
argc
,
char
**
argv
)
{
struct
timeval
tv
;
...
...
@@ -2756,6 +2811,7 @@ int main(int argc, char **argv) {
resetServerSaveParams
();
loadServerConfig
(
configfile
,
options
);
sdsfree
(
options
);
if
(
configfile
)
server
.
configfile
=
getAbsolutePath
(
configfile
);
}
else
{
redisLog
(
REDIS_WARNING
,
"Warning: no config file specified, using the default config. In order to specify a config file use %s /path/to/%s.conf"
,
argv
[
0
],
server
.
sentinel_mode
?
"sentinel"
:
"redis"
);
}
...
...
src/redis.h
浏览文件 @
7a5d3d91
...
...
@@ -519,6 +519,7 @@ typedef struct redisOpArray {
struct
redisServer
{
/* General */
char
*
configfile
;
/* Absolute config file path, or NULL */
int
hz
;
/* serverCron() calls frequency in hertz */
redisDb
*
db
;
dict
*
commands
;
/* Command table */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录