Problem using mandatory locks (other apps can read/delete etc)
Quoted 26 lines · E. Abbink
Quoted 12 lines
I'm trying to solve a problem using mandatory locks but am having some difficulty in doing so. (if there's a more appropriate place for discussing this please ignore the rest of this post. pointers to that place would be appreciated ;) )
my problem:
when I lock a file with a mandatory write lock (ie. fcntl, +s-x bits and mand mount option. for code see below) it is still possible:
- for me to rm the file in question
- for the file to be read by an other process[snip]
Quoted 7 lines
lock.l_type = F_WRLCK ; <================ lock.l_whence = SEEK_SET ; lock.l_start = 0 ; lock.l_len = 0 ; lock.l_pid = 0 ; // ignored int err = fcntl (fd, F_SETLK, &lock) ;
Quoted 7 lines
I know nothing about file locking in Unix, but it looks like you requested write lock, i.e. forbid writing to a file. Why are you surprised that reads are allowed?
Probably someone else would comment on why rm is working, though... --
vda
as i understand it what is called a "write" lock is actually an exclusive lock (ie both read/write). Also, afaik, you cant set both a read & write lock through fcntl which supports that assumption.
Esger
Signature · 2 lines
NeoMail - Webmail that doesn't suck... as much. http://neomail.sourceforge.net