* Problem using mandatory locks (other apps can read/delete etc)
@ 2002-04-10 17:08 E. Abbink
2002-04-11 11:37 ` Denis Vlasenko
0 siblings, 1 reply; 5+ messages in thread
From: E. Abbink @ 2002-04-10 17:08 UTC (permalink / raw)
To: linux-kernel
Hi,
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
It's not possible to cat to the file or cp another file over it (as
expected). For my application I want a locked file to be completely
locked/protected from other processes.
If I retry the same without setting the +s-x bits the cp & cat succeed,
so something special is being done in the first case.
According to all docs (i can find) mandatory locks should block both the
read and write system calls (i cant find anything in it regarding unlink
though...). In my case however it seems as if only write calls are
blocked but not read calls?
If anyone could shed any light on this it would be much appreciated.
Esger
system details:
linux 2.4.17 partially suse & xfs patched kernel
filesystem is reiserfs
i386 dual pIII450
test app code:
int main ()
{
int fd ;
fd = open ("image.jpg", O_RDWR) ;
if (fd == -1)
{
printf ("error %d while opening file\n", errno) ;
exit (1) ;
}
struct flock lock ;
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) ;
if (err == -1)
{
printf ("error %d while locking file\n", errno) ;
exit (1) ;
}
else
printf ("file locked\n") ;
while (1)
sleep (1) ;
}
--
NeoMail - Webmail that doesn't suck... as much.
http://neomail.sourceforge.net
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Problem using mandatory locks (other apps can read/delete etc)
2002-04-10 17:08 Problem using mandatory locks (other apps can read/delete etc) E. Abbink
@ 2002-04-11 11:37 ` Denis Vlasenko
2002-04-11 15:42 ` Alex Riesen
0 siblings, 1 reply; 5+ messages in thread
From: Denis Vlasenko @ 2002-04-11 11:37 UTC (permalink / raw)
To: esger, linux-kernel
On 10 April 2002 15:08, E. Abbink wrote:
> 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]
> 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) ;
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Problem using mandatory locks (other apps can read/delete etc)
2002-04-11 11:37 ` Denis Vlasenko
@ 2002-04-11 15:42 ` Alex Riesen
0 siblings, 0 replies; 5+ messages in thread
From: Alex Riesen @ 2002-04-11 15:42 UTC (permalink / raw)
To: esger; +Cc: Denis Vlasenko, linux-kernel
On Thu, Apr 11, 2002 at 09:37:37AM -0200, Denis Vlasenko wrote:
> On 10 April 2002 15:08, E. Abbink wrote:
> > 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]
>
> > 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) ;
>
> 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?
That's advisory write lock. Question is: why open call to read the file
succeeded?
>
> Probably someone else would comment on why rm is working, though...
Why not? Apparently he has write permission on the directory which contain
the file, and is the owner of that file.
By the way, where are you changing file permissions to +s-x?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Problem using mandatory locks (other apps can read/delete etc)
@ 2002-04-11 9:35 E. Abbink
0 siblings, 0 replies; 5+ messages in thread
From: E. Abbink @ 2002-04-11 9:35 UTC (permalink / raw)
To: vda; +Cc: linux-kernel
> On 10 April 2002 15:08, E. Abbink wrote:
> > 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]
>
> > 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) ;
>
> 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
--
NeoMail - Webmail that doesn't suck... as much.
http://neomail.sourceforge.net
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Problem using mandatory locks (other apps can read/delete etc)
@ 2002-04-12 9:22 E. Abbink
0 siblings, 0 replies; 5+ messages in thread
From: E. Abbink @ 2002-04-12 9:22 UTC (permalink / raw)
To: Alexander.Riesen; +Cc: linux-kernel
> On Thu, Apr 11, 2002 at 09:37:37AM -0200, Denis Vlasenko wrote:
> > On 10 April 2002 15:08, E. Abbink wrote:
> > > 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]
> >
> > > 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) ;
> >
> > 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?
>
> That's advisory write lock. Question is: why open call to read the file
> succeeded?
Normally it's an advisory lock, but if you do the appropriate actions
(mounting the fs with mand and setting the +s-x modebits, see
Documentation/mandatory.txt) the file becomes a mandatory lock candidate
and fcntl will/should mandatory lock it.
>
> >
> > Probably someone else would comment on why rm is working, though...
>
> Why not? Apparently he has write permission on the directory which contain
> the file, and is the owner of that file.
>
> By the way, where are you changing file permissions to +s-x?
>
by hand before the program is run.
>
>
>
--
NeoMail - Webmail that doesn't suck... as much.
http://neomail.sourceforge.net
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-04-12 8:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-10 17:08 Problem using mandatory locks (other apps can read/delete etc) E. Abbink
2002-04-11 11:37 ` Denis Vlasenko
2002-04-11 15:42 ` Alex Riesen
2002-04-11 9:35 E. Abbink
2002-04-12 9:22 E. Abbink
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®