diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tdb2/io.c | 9 | ||||
-rw-r--r-- | lib/tdb2/open.c | 3 | ||||
-rw-r--r-- | lib/tdb2/private.h | 4 |
3 files changed, 11 insertions, 5 deletions
diff --git a/lib/tdb2/io.c b/lib/tdb2/io.c index 4166cd4c67..d422d96326 100644 --- a/lib/tdb2/io.c +++ b/lib/tdb2/io.c @@ -42,16 +42,23 @@ void tdb_munmap(struct tdb_file *file) void tdb_mmap(struct tdb_context *tdb) { + int mmap_flags; + if (tdb->flags & TDB_INTERNAL) return; if (tdb->flags & TDB_NOMMAP) return; + if ((tdb->open_flags & O_ACCMODE) == O_RDONLY) + mmap_flags = PROT_READ; + else + mmap_flags = PROT_READ | PROT_WRITE; + /* size_t can be smaller than off_t. */ if ((size_t)tdb->file->map_size == tdb->file->map_size) { tdb->file->map_ptr = mmap(NULL, tdb->file->map_size, - tdb->mmap_flags, + mmap_flags, MAP_SHARED, tdb->file->fd, 0); } else tdb->file->map_ptr = MAP_FAILED; diff --git a/lib/tdb2/open.c b/lib/tdb2/open.c index bf901c7b35..2dd474cc81 100644 --- a/lib/tdb2/open.c +++ b/lib/tdb2/open.c @@ -369,6 +369,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, tdb->log_fn = NULL; tdb->transaction = NULL; tdb->access = NULL; + tdb->open_flags = open_flags; tdb->last_error = TDB_SUCCESS; tdb->file = NULL; tdb->lock_fn = tdb_fcntl_lock; @@ -416,11 +417,9 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, if ((open_flags & O_ACCMODE) == O_RDONLY) { tdb->read_only = true; - tdb->mmap_flags = PROT_READ; openlock = F_RDLCK; } else { tdb->read_only = false; - tdb->mmap_flags = PROT_READ | PROT_WRITE; openlock = F_WRLCK; } diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h index a43fa4ac56..f8985743dd 100644 --- a/lib/tdb2/private.h +++ b/lib/tdb2/private.h @@ -346,8 +346,8 @@ struct tdb_context { /* Operating read-only? (Opened O_RDONLY, or in traverse_read) */ bool read_only; - /* mmap read only? */ - int mmap_flags; + /* Open flags passed to tdb_open. */ + int open_flags; /* the flags passed to tdb_open, for tdb_reopen. */ uint32_t flags; |