2003-05-06 17:20:42

by Mikhail Kruk

[permalink] [raw]
Subject: flock races causes E_NOLCK

Hello,
I'm having a problem with flock on 2.4.18 kernel.
The scenario is like this:

parent process:
open file
fcntl(file, FD_SETFD, 1) // set CLOEXEC bit
flock file
fork/exec child process
close file

child process
open the same file
flock this file
close file

This sometimes (often) results in child process being unable to do any
further locking with the error 37 (no locks available).
Removing fcntl and doing an explicit close of all open file desciprotrs in
the beginning of child leads to the same problem.

Here is a post from Pat Knight descirbing similar problem:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=linux.fsdevel.sxr8lna7wp.fsf%40eurologic.com&rnum=4&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3DRLIMIT_LOCKS%26btnG%3DGoogle%2BSearch

I can't directly map his problem onto mine, but it's pretty clear that
somehow (usigned) current->locks is decremented when it is 0.

For some reason, however, simplistic test program doens't hit this
condition, so I suspect my analysis is not 100% correct. I'm sure, though,
that current->locks is getting messed up somehow.