This is an automated email from the ASF dual-hosted git repository. rnewson pushed a commit to branch flock in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit d8430da98d934d732c335866abd3f271e18f6d8a Author: Robert Newson <[email protected]> AuthorDate: Thu Sep 24 21:07:57 2026 +0100 take exclusive lock on all couch_cfiles --- src/couch/priv/couch_cfile/couch_cfile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/couch/priv/couch_cfile/couch_cfile.c b/src/couch/priv/couch_cfile/couch_cfile.c index c7e6f16f0..f780fe8a9 100644 --- a/src/couch/priv/couch_cfile/couch_cfile.c +++ b/src/couch/priv/couch_cfile/couch_cfile.c @@ -28,6 +28,7 @@ #include <sys/stat.h> #include <sys/uio.h> #include <unistd.h> +#include <sys/file.h> // erl_driver.h is for erl_errno_id() #include "erl_driver.h" @@ -234,7 +235,7 @@ int efile_datasync(int fd, posix_errno_t* res_errno) { static ERL_NIF_TERM dup_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { #ifdef COUCH_CFILE_SUPPORTED - int fd, newfd; + int fd, newfd, flock_res; handle_t* hdl; ErlNifRWLock *lock; ErlNifPid pid; @@ -257,6 +258,12 @@ static ERL_NIF_TERM dup_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) if (newfd < 0) { return err_tup(env, errno); } + + flock_res = flock(newfd, LOCK_EX); + if (flock_res == -1) { + return err_tup(env, errno); + } + // From here on close the new dup-ed file descriptors on any failure. lock = enif_rwlock_create("couch_cfile:rwlock");
