From 26e5f3ff33e66d85296c61e7c671c26569f5d290 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 15 Feb 2016 16:14:56 +0100 Subject: [PATCH] Include full paths on RDB/AOF files errors. Close #3086. --- src/aof.c | 17 +++++++++++++++-- src/rdb.c | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/aof.c b/src/aof.c index f1a972c23..161f527c4 100644 --- a/src/aof.c +++ b/src/aof.c @@ -38,6 +38,7 @@ #include #include #include +#include void aofUpdateCurrentSize(void); void aofClosePipes(void); @@ -234,11 +235,20 @@ void stopAppendOnly(void) { /* Called when the user switches from "appendonly no" to "appendonly yes" * at runtime using the CONFIG command. */ int startAppendOnly(void) { + char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */ + server.aof_last_fsync = server.unixtime; server.aof_fd = open(server.aof_filename,O_WRONLY|O_APPEND|O_CREAT,0644); serverAssert(server.aof_state == AOF_OFF); if (server.aof_fd == -1) { - serverLog(LL_WARNING,"Redis needs to enable the AOF but can't open the append only file: %s",strerror(errno)); + char *cwdp = getcwd(cwd,MAXPATHLEN); + + serverLog(LL_WARNING, + "Redis needs to enable the AOF but can't open the " + "append only file %s (in server root dir %s): %s", + server.aof_filename, + cwdp ? cwdp : "unknown", + strerror(errno)); return C_ERR; } if (rewriteAppendOnlyFileBackground() == C_ERR) { @@ -1413,7 +1423,10 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) { latencyStartMonitor(latency); if (rename(tmpfile,server.aof_filename) == -1) { serverLog(LL_WARNING, - "Error trying to rename the temporary AOF file: %s", strerror(errno)); + "Error trying to rename the temporary AOF file %s into %s: %s", + tmpfile, + server.aof_filename, + strerror(errno)); close(newfd); if (oldfd != -1) close(oldfd); goto cleanup; diff --git a/src/rdb.c b/src/rdb.c index 8d3e9d173..1cc42576a 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -39,6 +39,7 @@ #include #include #include +#include #define RDB_LOAD_NONE 0 #define RDB_LOAD_ENC (1<<0) @@ -844,6 +845,7 @@ werr: /* Write error. */ /* Save the DB on disk. Return C_ERR on error, C_OK on success. */ int rdbSave(char *filename) { char tmpfile[256]; + char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */ FILE *fp; rio rdb; int error = 0; @@ -851,7 +853,12 @@ int rdbSave(char *filename) { snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid()); fp = fopen(tmpfile,"w"); if (!fp) { - serverLog(LL_WARNING, "Failed opening .rdb for saving: %s", + char *cwdp = getcwd(cwd,MAXPATHLEN); + serverLog(LL_WARNING, + "Failed opening the RDB file %s (in server root dir %s) " + "for saving: %s", + filename, + cwdp ? cwdp : "unknown", strerror(errno)); return C_ERR; } @@ -870,10 +877,18 @@ int rdbSave(char *filename) { /* Use RENAME to make sure the DB file is changed atomically only * if the generate DB file is ok. */ if (rename(tmpfile,filename) == -1) { - serverLog(LL_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno)); + char *cwdp = getcwd(cwd,MAXPATHLEN); + serverLog(LL_WARNING, + "Error moving temp DB file %s on the final " + "destination %s (in server root dir %s): %s", + tmpfile, + filename, + cwdp ? cwdp : "unknown", + strerror(errno)); unlink(tmpfile); return C_ERR; } + serverLog(LL_NOTICE,"DB saved on disk"); server.dirty = 0; server.lastsave = time(NULL);