Skip to content

Commit

Permalink
Set the right flags when Shared is selected.
Browse files Browse the repository at this point in the history
`exclusive` selects between `LOCK_EX` and `LOCK_SH` but if it is `false`
`LOCK_SH` is never set on the flags. This could've worked if `LOCK_SH`
is `0` but at least on GNU/Linux on amd64 with glibc, `LOCK_SH` is `1`.

We never use `Shared` in the Dune codebase but in case we would, it
better works otherwise it would create issues that are hard to debug.

Discovered by @emillon as we were investigating the semantics of write
locks.

Signed-off-by: Marek Kubica <[email protected]>
  • Loading branch information
Leonidas-from-XIV committed Nov 10, 2023
1 parent 39e6c72 commit 29d349a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dune_util/dune_flock.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ CAMLprim value dune_flock_lock(value v_fd, value v_block, value v_exclusive) {
int flags = 0;
if (Bool_val(v_exclusive)) {
flags |= LOCK_EX;
} else {
flags |= LOCK_SH;
}
if (!Bool_val(v_block)) {
flags |= LOCK_NB;
Expand Down

0 comments on commit 29d349a

Please sign in to comment.