$OpenBSD: patch-src_history_cpp,v 1.1 2021/11/25 17:56:44 solene Exp $

Backport commit 3ed8a57bc59c931e890c60df38222f4532d09b66

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.

Index: src/history.cpp
--- src/history.cpp.orig
+++ src/history.cpp
@@ -1321,7 +1321,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<impl_wrapper_t>(std::move(name))) {}
 
