summaryrefslogtreecommitdiff
path: root/c_src/filebuffer.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/filebuffer.c
parent375d3e03b800f1cbfefe8e522132e713f7889236 (diff)
Lock permdb database files with flock
Diffstat (limited to 'c_src/filebuffer.c')
-rw-r--r--c_src/filebuffer.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/c_src/filebuffer.c b/c_src/filebuffer.c
index 8285695..87b9859 100644
--- a/c_src/filebuffer.c
+++ b/c_src/filebuffer.c
@@ -177,7 +177,7 @@ bf_read(buffered_file *file, uint64_t offset, size_t length, char **error)
}
buffered_file *
-bf_open(const char *path, int flags, const char *name)
+bf_open(const char *path, int flags, const char *name, int lock)
{
buffered_file *file = malloc(sizeof(buffered_file));
@@ -187,6 +187,16 @@ bf_open(const char *path, int flags, const char *name)
return NULL;
}
+ if (lock) {
+ int ret;
+
+ ret = flock(file->fd, LOCK_EX|LOCK_NB);
+ if (ret == -1) {
+ warn("flock %s", path);
+ return NULL;
+ }
+ }
+
file->name = name;
off_t datafile_filesize = lseek(file->fd, 0, SEEK_END);