]> git.saurik.com Git - redis.git/commitdiff
Create swap file only if not exists
authorantirez <antirez@gmail.com>
Fri, 15 Jan 2010 19:02:18 +0000 (14:02 -0500)
committerantirez <antirez@gmail.com>
Fri, 15 Jan 2010 19:02:18 +0000 (14:02 -0500)
redis.c

diff --git a/redis.c b/redis.c
index 54ed0031392b5c8de2adf311a4c2f9482aed680f..9484b75a6278ce39eacdd5e9d658d20d186d2ac5 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -7035,9 +7035,13 @@ static void vmInit(void) {
 
     expandVmSwapFilename();
     redisLog(REDIS_NOTICE,"Using '%s' as swap file",server.vm_swap_file);
-    server.vm_fp = fopen(server.vm_swap_file,"r+b");
+    if ((server.vm_fp = fopen(server.vm_swap_file,"r+b")) == NULL) {
+        server.vm_fp = fopen(server.vm_swap_file,"w+b");
+    }
     if (server.vm_fp == NULL) {
-        redisLog(REDIS_WARNING,"Impossible to open the swap file. Exiting.");
+        redisLog(REDIS_WARNING,
+            "Impossible to open the swap file: %s. Exiting.",
+            strerror(errno));
         exit(1);
     }
     server.vm_fd = fileno(server.vm_fp);