From 9630ded313d593c318ac220ace165319283a74fe Mon Sep 17 00:00:00 2001 From: Pavel Melkozerov Date: Wed, 24 Nov 2021 17:01:39 +0300 Subject: [PATCH] fix fob bad log messages in rdbSave (#9842) (#9843) logs message prints wrong file is failed to open temporary file logs have error occurred in getcwd (uses same errno to report error) Co-authored-by: Pavel Melkozerov --- src/aof.c | 3 ++- src/rdb.c | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/aof.c b/src/aof.c index 69c4d8681..a85399ab0 100644 --- a/src/aof.c +++ b/src/aof.c @@ -292,6 +292,7 @@ int startAppendOnly(void) { newfd = open(server.aof_filename,O_WRONLY|O_APPEND|O_CREAT,0644); serverAssert(server.aof_state == AOF_OFF); if (newfd == -1) { + char *str_err = strerror(errno); char *cwdp = getcwd(cwd,MAXPATHLEN); serverLog(LL_WARNING, @@ -299,7 +300,7 @@ int startAppendOnly(void) { "append only file %s (in server root dir %s): %s", server.aof_filename, cwdp ? cwdp : "unknown", - strerror(errno)); + str_err); return C_ERR; } if (hasActiveChildProcess() && server.child_type != CHILD_TYPE_AOF) { diff --git a/src/rdb.c b/src/rdb.c index f3ea05317..64780bbb5 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -1372,13 +1372,14 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) { snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid()); fp = fopen(tmpfile,"w"); if (!fp) { + char *str_err = strerror(errno); char *cwdp = getcwd(cwd,MAXPATHLEN); serverLog(LL_WARNING, - "Failed opening the RDB file %s (in server root dir %s) " + "Failed opening the temp RDB file %s (in server root dir %s) " "for saving: %s", - filename, + tmpfile, cwdp ? cwdp : "unknown", - strerror(errno)); + str_err); return C_ERR; } @@ -1402,6 +1403,7 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) { /* Use RENAME to make sure the DB file is changed atomically only * if the generate DB file is ok. */ if (rename(tmpfile,filename) == -1) { + char *str_err = strerror(errno); char *cwdp = getcwd(cwd,MAXPATHLEN); serverLog(LL_WARNING, "Error moving temp DB file %s on the final " @@ -1409,7 +1411,7 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) { tmpfile, filename, cwdp ? cwdp : "unknown", - strerror(errno)); + str_err); unlink(tmpfile); stopSaving(0); return C_ERR;