From: Marek VavruĊĦa Date: Wed, 12 Nov 2014 18:13:24 +0000 (+0100) Subject: cache: create env if not exists X-Git-Tag: v1.0.0-beta1~413 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3037dc0e5e697e45f886d5a507bd1b375804c21e;p=thirdparty%2Fknot-resolver.git cache: create env if not exists --- diff --git a/lib/cache.c b/lib/cache.c index 40d1a83e4..4195455a1 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -1,5 +1,8 @@ #include #include +#include +#include +#include #include #include @@ -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); diff --git a/lib/context.c b/lib/context.c index 11932edbd..3486a2a24 100644 --- a/lib/context.c +++ b/lib/context.c @@ -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); }