The msync manpage reports that msync *must* be called before munmap. Failure to do...
authorSimo Sorce <idra@samba.org>
Wed, 3 Sep 2008 14:44:09 +0000 (10:44 -0400)
committerStefan Metzmacher <metze@samba.org>
Sun, 14 Sep 2008 17:19:55 +0000 (19:19 +0200)
(cherry picked from commit 74c8575b3f3b90ea21ae6aa7ccd95947838af956)
(This used to be commit 8fd54bb55f0c23bd025d1719abcbe75c6a2ea8ac)

source4/lib/tdb/common/io.c
source4/lib/tdb/common/transaction.c

index 172ab69d8c9e69ae7f160071567c4d885ac7848c..4ec18de48e043cd1e764dd9053922fc257d9404c 100644 (file)
@@ -189,7 +189,13 @@ int tdb_munmap(struct tdb_context *tdb)
 
 #ifdef HAVE_MMAP
        if (tdb->map_ptr) {
-               int ret = munmap(tdb->map_ptr, tdb->map_size);
+               int ret;
+
+               ret = msync(tdb->map_ptr, tdb->map_size, MS_SYNC);
+               if (ret != 0)
+                       return ret;
+
+               ret = munmap(tdb->map_ptr, tdb->map_size);
                if (ret != 0)
                        return ret;
        }
index 4e2127be64484cbcb5faee1a6e5682c08425f26a..7acda640c8d32338de6e8651971d5f848740aae6 100644 (file)
@@ -563,7 +563,7 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t
                TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: fsync failed\n"));
                return -1;
        }
-#ifdef MS_SYNC
+#ifdef HAVE_MMAP
        if (tdb->map_ptr) {
                tdb_off_t moffset = offset & ~(tdb->page_size-1);
                if (msync(moffset + (char *)tdb->map_ptr,