From 3ed8a57bc59c931e890c60df38222f4532d09b66 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 18 Sep 2021 13:40:09 -0700 Subject: [PATCH] Don't use mmap for history files on OpenBSD OpenBSD's mmap is famously unsychronized with file IO. In theory fsync and msync can be used to synchronize but I was unable to get it to work. Just don't use mmap for history on OpenBSD. This fixes the history merge tests. --- src/history.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/history.cpp b/src/history.cpp index f8f631302..2a36c1814 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -1319,7 +1319,15 @@ struct history_t::impl_wrapper_t { void history_impl_t::resolve_pending() { this->has_pending_item = false; } bool history_t::chaos_mode = false; + +/* OpenBSD's mmap is not synchronized with other file operations. In particular it appears we may + * write() a file, fsync() it, close it, mmap() it, and call msync(), and we still may not see the + * newly written data. Just don't try mmap here. */ +#if defined(__OpenBSD__) +bool history_t::never_mmap = true; +#else bool history_t::never_mmap = false; +#endif history_t::history_t(wcstring name) : wrap_(make_unique(std::move(name))) {}