]> git.saurik.com Git - redis.git/commitdiff
Exit with Fatal error at startup if the RDB file signature or version is wrong.
authorantirez <antirez@gmail.com>
Fri, 14 Oct 2011 14:59:32 +0000 (16:59 +0200)
committerantirez <antirez@gmail.com>
Fri, 14 Oct 2011 14:59:38 +0000 (16:59 +0200)
Ref: issue #103

src/rdb.c
src/redis.c

index 1cfcd0449af10f370b52da427d1af8ebf2397506..0bafd97c5638a0c1ea8ac8e6d1c66c61c4e48394 100644 (file)
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -947,19 +947,24 @@ int rdbLoad(char *filename) {
     rio rdb;
 
     fp = fopen(filename,"r");
-    if (!fp) return REDIS_ERR;
+    if (!fp) {
+        errno = ENOENT;
+        return REDIS_ERR;
+    }
     rioInitWithFile(&rdb,fp);
     if (rioRead(&rdb,buf,9) == 0) goto eoferr;
     buf[9] = '\0';
     if (memcmp(buf,"REDIS",5) != 0) {
         fclose(fp);
         redisLog(REDIS_WARNING,"Wrong signature trying to load DB from file");
+        errno = EINVAL;
         return REDIS_ERR;
     }
     rdbver = atoi(buf+5);
     if (rdbver < 1 || rdbver > 2) {
         fclose(fp);
         redisLog(REDIS_WARNING,"Can't handle RDB format version %d",rdbver);
+        errno = EINVAL;
         return REDIS_ERR;
     }
 
index 83aa3a824aa84f667bf9cb302a9f55f7da80bbe8..dd693f6c37e1ca759e3610fc34abf58bfb2964e9 100644 (file)
@@ -1802,8 +1802,13 @@ int main(int argc, char **argv) {
         if (loadAppendOnlyFile(server.appendfilename) == REDIS_OK)
             redisLog(REDIS_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000);
     } else {
-        if (rdbLoad(server.dbfilename) == REDIS_OK)
-            redisLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds",(float)(ustime()-start)/1000000);
+        if (rdbLoad(server.dbfilename) == REDIS_OK) {
+            redisLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds",
+                (float)(ustime()-start)/1000000);
+        } else if (errno != ENOENT) {
+            redisLog(REDIS_WARNING,"Fatal error loading the DB. Exiting.");
+            exit(1);
+        }
     }
     if (server.ipfd > 0)
         redisLog(REDIS_NOTICE,"The server is now ready to accept connections on port %d", server.port);