From: Amos Jeffries Date: Tue, 5 May 2020 13:57:24 +0000 (+0000) Subject: Bug 5046: FreeBSD lacks open(2) O_DSYNC flag (#623) X-Git-Tag: SQUID_5_0_3~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1fba375ee69144379172653607c49408d85a9a86;p=thirdparty%2Fsquid.git Bug 5046: FreeBSD lacks open(2) O_DSYNC flag (#623) ext_session_acl built with TrivialDB uses O_DSYNC to ensure thread-safe manipulation of data within the TDB files in Squid multi-process environment. FreeBSD lacks this flag entirely. Use the O_SYNC flag as a backup, which apparently provides file-level synchronization. It is not clear whether this flag will prevent duplicate keys or record overwrites in the case of process write race collisions. NP: this appears to be FreeBSD specific. Other BSD either define O_DSYNC or lack support for these POSIX flags entirely. --- diff --git a/src/acl/external/session/ext_session_acl.cc b/src/acl/external/session/ext_session_acl.cc index 288d23649b..62cd96bb27 100644 --- a/src/acl/external/session/ext_session_acl.cc +++ b/src/acl/external/session/ext_session_acl.cc @@ -137,6 +137,10 @@ static void init_db(void) } } #elif USE_TRIVIALDB +#if _SQUID_FREEBSD_ && !defined(O_DSYNC) + // FreeBSD lacks O_DSYNC, O_SYNC is closest to correct behaviour +#define O_DSYNC O_SYNC +#endif db = tdb_open(db_path, 0, TDB_CLEAR_IF_FIRST, O_CREAT|O_DSYNC, 0666); #endif if (!db) {