Define default pidfile when creating pid

We want pidfile to be NULL on startup so we can detect if the user
set an explicit value versus only using the default value.

Closes #1967
Fixes #2076
This commit is contained in:
Matt Stancliff 2014-08-25 17:07:37 -04:00
parent fb538fb98e
commit 33bcd9e2d6

View File

@ -1433,7 +1433,7 @@ void initServerConfig(void) {
server.aof_flush_postponed_start = 0; server.aof_flush_postponed_start = 0;
server.aof_rewrite_incremental_fsync = REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC; server.aof_rewrite_incremental_fsync = REDIS_DEFAULT_AOF_REWRITE_INCREMENTAL_FSYNC;
server.aof_load_truncated = REDIS_DEFAULT_AOF_LOAD_TRUNCATED; server.aof_load_truncated = REDIS_DEFAULT_AOF_LOAD_TRUNCATED;
server.pidfile = zstrdup(REDIS_DEFAULT_PID_FILE); server.pidfile = NULL;
server.rdb_filename = zstrdup(REDIS_DEFAULT_RDB_FILENAME); server.rdb_filename = zstrdup(REDIS_DEFAULT_RDB_FILENAME);
server.aof_filename = zstrdup(REDIS_DEFAULT_AOF_FILENAME); server.aof_filename = zstrdup(REDIS_DEFAULT_AOF_FILENAME);
server.requirepass = NULL; server.requirepass = NULL;
@ -3393,6 +3393,10 @@ void linuxMemoryWarnings(void) {
#endif /* __linux__ */ #endif /* __linux__ */
void createPidFile(void) { void createPidFile(void) {
/* If pidfile requested, but no pidfile defined, use
* default pidfile path */
if (!server.pidfile) server.pidfile = zstrdup(REDIS_DEFAULT_PID_FILE);
/* Try to write the pid file in a best-effort way. */ /* Try to write the pid file in a best-effort way. */
FILE *fp = fopen(server.pidfile,"w"); FILE *fp = fopen(server.pidfile,"w");
if (fp) { if (fp) {