]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache: create env if not exists
authorMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 12 Nov 2014 18:13:24 +0000 (19:13 +0100)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 12 Nov 2014 18:13:24 +0000 (19:13 +0100)
lib/cache.c
lib/context.c

index 40d1a83e42c84a68bd4ec63d7643e3c8d499362e..4195455a1fde88340ca75c39290399f56779f55f 100644 (file)
@@ -1,5 +1,8 @@
 #include <assert.h>
 #include <time.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
 
 #include <lmdb.h>
 #include <libknot/internal/mempattern.h>
@@ -28,6 +31,11 @@ struct kr_txn
 
 /*                       MDB access                                           */
 
+static int create_env_dir(const char *path)
+{
+    return mkdir(path, 0770);
+}
+
 static int dbase_open(struct kr_cache *cache, const char *handle)
 {
        int ret = mdb_env_create(&cache->env);
@@ -35,6 +43,12 @@ static int dbase_open(struct kr_cache *cache, const char *handle)
                return ret;
        }
 
+    ret = create_env_dir(handle);
+    if (ret != 0) {
+        mdb_env_close(cache->env);
+        return ret;
+    }
+
        ret = mdb_env_open(cache->env, handle, 0, 0644);
        if (ret != 0) {
                mdb_env_close(cache->env);
index 11932edbd100733e57ea6e473f043525417cb064..3486a2a240288b030bd7eee2b1c64daf1433574e 100644 (file)
@@ -16,7 +16,7 @@ int kr_context_init(struct kr_context *ctx, mm_ctx_t *mm)
 
        ctx->cache = kr_cache_open("/tmp/kresolved", 0, mm);
        if (ctx->cache == NULL) {
-               fprintf(stderr, "Cache directory '/tmp/kresolved' not exists.\n");
+               fprintf(stderr, "Cache directory '/tmp/kresolved' not exists, exitting.\n");
                assert(ctx->cache);
        }