summaryrefslogtreecommitdiff
path: root/src/rdb.c
diff options
context:
space:
mode:
authorBinbin <binloveplay1314@qq.com>2022-08-04 15:47:37 +0800
committerGitHub <noreply@github.com>2022-08-04 10:47:37 +0300
commit4505eb18213c8da31c6dd39ba7cd36d3d01141a5 (patch)
tree4cbf4047cac3d13ff1b17145fb358a7bc6627702 /src/rdb.c
parent6686c6d774fcf71fffbaeff798c997ab3eff80de (diff)
downloadredis-4505eb18213c8da31c6dd39ba7cd36d3d01141a5.tar.gz
errno cleanup around rdbLoad (#11042)
This is an addition to #11039, which cleans up rdbLoad* related errno. Remove the errno print from the outer message (may be invalid since errno may have been overwritten). Our aim should be the code that detects the error and knows which system call triggered it, is the one to print errno, and not the code way up above (in some cases a result of a logical error and not a system one). Remove the code to update errno in rdbLoadRioWithLoadingCtx, signature check and the rdb version check, in these cases, we do print the error message. The caller dose not have the specific logic for handling EINVAL. Small fix around rdb-preamble AOF: A truncated RDB is considered a failure, not handled the same as a truncated AOF file.
Diffstat (limited to 'src/rdb.c')
-rw-r--r--src/rdb.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/rdb.c b/src/rdb.c
index fea5f4121..993a123c0 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -2889,7 +2889,7 @@ int rdbLoadRio(rio *rdb, int rdbflags, rdbSaveInfo *rsi) {
/* Load an RDB file from the rio stream 'rdb'. On success C_OK is returned,
- * otherwise C_ERR is returned and 'errno' is set accordingly.
+ * otherwise C_ERR is returned.
* The rdb_loading_ctx argument holds objects to which the rdb will be loaded to,
* currently it only allow to set db object and functionLibCtx to which the data
* will be loaded (in the future it might contains more such objects). */
@@ -2907,13 +2907,11 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin
buf[9] = '\0';
if (memcmp(buf,"REDIS",5) != 0) {
serverLog(LL_WARNING,"Wrong signature trying to load DB from file");
- errno = EINVAL;
return C_ERR;
}
rdbver = atoi(buf+5);
if (rdbver < 1 || rdbver > RDB_VERSION) {
serverLog(LL_WARNING,"Can't handle RDB format version %d",rdbver);
- errno = EINVAL;
return C_ERR;
}
@@ -3254,9 +3252,10 @@ int rdbLoad(char *filename, rdbSaveInfo *rsi, int rdbflags) {
fp = fopen(filename, "r");
if (fp == NULL) {
- retval = (errno == ENOENT) ? RDB_NOT_EXIST : RDB_FAILED;
+ if (errno == ENOENT) return RDB_NOT_EXIST;
+
serverLog(LL_WARNING,"Fatal error: can't open the RDB file %s for reading: %s", filename, strerror(errno));
- return retval;
+ return RDB_FAILED;
}
if (fstat(fileno(fp), &sb) == -1)