summaryrefslogtreecommitdiff
path: root/c_src/permdb.c
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2016-06-10 15:36:29 +0200
committerLinus Nordberg <linus@nordu.net>2016-07-11 15:11:13 +0200
commit5ba76d616a2f5924e8ad7fdeb806f5bfa0c82e94 (patch)
tree83d6f2178edb43c05dacc358e8a07d60e914fc2d /c_src/permdb.c
parent375d3e03b800f1cbfefe8e522132e713f7889236 (diff)
Lock permdb database files with flock
Diffstat (limited to 'c_src/permdb.c')
-rw-r--r--c_src/permdb.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/c_src/permdb.c b/c_src/permdb.c
index db4498f..ef25be5 100644
--- a/c_src/permdb.c
+++ b/c_src/permdb.c
@@ -432,14 +432,27 @@ permdb_alloc(const char *dbpath)
}
permdb_object *state = malloc(sizeof(permdb_object));
- state->datafile = bf_open(dbpath, O_RDWR|O_CREAT, "datafile");
- state->indexfile = bf_open(idxpath, O_RDWR|O_CREAT, "indexfile");
-
- free(idxpath);
state->nodecache = NULL;
state->dirtynodes = NULL;
state->error = NULL;
+
+ state->datafile = bf_open(dbpath, O_RDWR|O_CREAT, "datafile", 1);
+ if (state->datafile == NULL) {
+ permdb_free(state);
+ free(idxpath);
+ return NULL;
+ }
+
+ state->indexfile = bf_open(idxpath, O_RDWR|O_CREAT, "indexfile", 1);
+ if (state->indexfile == NULL) {
+ permdb_free(state);
+ free(idxpath);
+ return NULL;
+ }
+
+ free(idxpath);
+
if (bf_total_length(state->datafile) == 0
&& bf_total_length(state->indexfile) == 0) {
dprintf(WRITE, (stderr, "writing header\n"));