[Patch]: Create Global Privilege
Pierre A. Humblet
Fri Dec 5 13:03:00 GMT 2003
At 12:14 PM 12/5/2003 +0100, Corinna Vinschen wrote:
>What is the advantage of using lseek(SEEK_END) and using that value
>for fcntl(F_SETLK, SEEK_SET) over just using fcntl(F_SETLK, SEEK_END)?
>Especially since lseek(SEEK_END) is then called afterwards anyway.
fcntl(F_SETLK, SEEK_END) is extremely risky on Windows because you
don't know what region was actually locked, and an unlock must
correspond *exactly* to a previous lock.
Somebody else could write to the file between the time fcntl finds
how long it is and the moment it locks it. The unlock you make after
you write will then fail.
>What is the advantage of using a finite loop with fcntl(F_SETLK) over
>using fcntl(F_SETLKW) just once? This seems potentially less secure
>than F_SETLKW and also less secure than the former Mutex solution.
The only reason is that F_SETLKW doesn't work on 9X so you need
a loop there anyway. But thinking more about it, we should have both
F_SETLKW and a loop. On NT the loop will never kick in. On 9x F_SETLKW
works like F_SETLK and the loop is useful. The loop could also be made
More information about the Cygwin-patches