You need to sign in or sign up before continuing.
Commit 5947f170 authored by antirez's avatar antirez
Browse files

Obtain absoute path of configuration file, expose it in INFO.

parent e9385752
...@@ -1199,6 +1199,7 @@ void createSharedObjects(void) { ...@@ -1199,6 +1199,7 @@ void createSharedObjects(void) {
void initServerConfig() { void initServerConfig() {
getRandomHexChars(server.runid,REDIS_RUN_ID_SIZE); getRandomHexChars(server.runid,REDIS_RUN_ID_SIZE);
server.configfile = NULL;
server.hz = REDIS_DEFAULT_HZ; server.hz = REDIS_DEFAULT_HZ;
server.runid[REDIS_RUN_ID_SIZE] = '\0'; server.runid[REDIS_RUN_ID_SIZE] = '\0';
server.arch_bits = (sizeof(long) == 8) ? 64 : 32; server.arch_bits = (sizeof(long) == 8) ? 64 : 32;
...@@ -2077,7 +2078,8 @@ sds genRedisInfoString(char *section) { ...@@ -2077,7 +2078,8 @@ sds genRedisInfoString(char *section) {
"uptime_in_seconds:%ld\r\n" "uptime_in_seconds:%ld\r\n"
"uptime_in_days:%ld\r\n" "uptime_in_days:%ld\r\n"
"hz:%d\r\n" "hz:%d\r\n"
"lru_clock:%ld\r\n", "lru_clock:%ld\r\n"
"config_file:%s\r\n",
REDIS_VERSION, REDIS_VERSION,
redisGitSHA1(), redisGitSHA1(),
strtol(redisGitDirty(),NULL,10) > 0, strtol(redisGitDirty(),NULL,10) > 0,
...@@ -2097,7 +2099,8 @@ sds genRedisInfoString(char *section) { ...@@ -2097,7 +2099,8 @@ sds genRedisInfoString(char *section) {
uptime, uptime,
uptime/(3600*24), uptime/(3600*24),
server.hz, server.hz,
(unsigned long) server.lruclock); (unsigned long) server.lruclock,
server.configfile ? server.configfile : "");
} }
/* Clients */ /* Clients */
...@@ -2772,6 +2775,58 @@ void redisSetProcTitle(char *title) { ...@@ -2772,6 +2775,58 @@ void redisSetProcTitle(char *title) {
#endif #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) { int main(int argc, char **argv) {
struct timeval tv; struct timeval tv;
...@@ -2839,6 +2894,7 @@ int main(int argc, char **argv) { ...@@ -2839,6 +2894,7 @@ int main(int argc, char **argv) {
resetServerSaveParams(); resetServerSaveParams();
loadServerConfig(configfile,options); loadServerConfig(configfile,options);
sdsfree(options); sdsfree(options);
if (configfile) server.configfile = getAbsolutePath(configfile);
} else { } 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"); 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");
} }
......
...@@ -672,6 +672,7 @@ typedef struct { ...@@ -672,6 +672,7 @@ typedef struct {
struct redisServer { struct redisServer {
/* General */ /* General */
char *configfile; /* Absolute config file path, or NULL */
int hz; /* serverCron() calls frequency in hertz */ int hz; /* serverCron() calls frequency in hertz */
redisDb *db; redisDb *db;
dict *commands; /* Command table */ dict *commands; /* Command table */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment