On Mon, 18 Aug 2025 16:30:48 -0700 (PDT)
Jeremy Drake wrote:
> The commit adding OFD locks changed from comparing just the F_POSIX and
> F_LOCK flags to comparing the entire flags value in order to make sure
> the locks are of the same type.  However, the F_WAIT flag may or may not
> be set, and result in that comparison not matching.  Mask the F_WAIT
> flag when attempting to compare the types of the locks.
> 
> This fixes the "many_locks" stc.
> 
> Signed-off-by: Jeremy Drake <[email protected]>
> Fixes: a66ed519884d ("Cygwin: fcntl: implement Open File Description (OFD) 
> locks")
> ---
>  winsup/cygwin/flock.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/winsup/cygwin/flock.cc b/winsup/cygwin/flock.cc
> index e9f49a8900..e03caba27a 100644
> --- a/winsup/cygwin/flock.cc
> +++ b/winsup/cygwin/flock.cc
> @@ -1722,7 +1722,7 @@ lf_findoverlap (lockf_t *lf, lockf_t *lock, int type, 
> lockf_t ***prev,
>        /* We're "self" only if the semantics and the id matches.  OFD and 
> POSIX
>           locks potentially block each other.  This is true even for OFD and
>        POSIX locks created by the same process. */
> -      bool self = (lf->lf_flags == lock->lf_flags)
> +      bool self = ((lf->lf_flags & ~F_WAIT) == (lock->lf_flags & ~F_WAIT))
>                 && (lf->lf_id == lock->lf_id);
> 
>        if (bsd_flock || ((type & SELF) && !self) || ((type & OTHERS) && self))

The patch itself LGTM, however, I wonder why it is not necessary to compare
also 'lf_type' here. Or is it enough to compare only 'lf_id' by any chance?

-- 
Takashi Yano <[email protected]>

Reply via email to