From 5ba76d616a2f5924e8ad7fdeb806f5bfa0c82e94 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Fri, 10 Jun 2016 15:36:29 +0200 Subject: Lock permdb database files with flock --- c_src/filebuffer.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'c_src/filebuffer.c') 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); -- cgit v1.1