Unix Programming - Setting Mandatory locking

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2005 > Setting Mandatory locking





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Setting Mandatory locking
grid

2005-04-21, 2:54 am

Hi,
I was reading APUE (by Rich Stevens),and tried an example mentioned
for using the chmod(2) sys call.It was mentioned that if I remove the
group execute bit(S_IXGRP) from the file mode and added S_ISGID flag,
this imples mandatory locking, and I should see a "l" at the place of
the group execute bit for the file.But I ran the following program on
both Linux & Solaris , and I dont see whats expected.
------
int main()
{
struct stat statbuf;

if(stat("st.c",&statbuf) < 0 ){
perror("stat");
exit(-1);
}
if(chmod("st.c",(statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0){
perror("chmod");
exit(-1);
}
return 0;
}

After running the executable , I get the following output when I list
the file :
$ ls -l st.c
-rw-r-Sr-- 1 ropanda svrtech 126 Apr 5 07:25 st.c

I just see the set-groupID bit set for the file.Am I doing something
wrong here or the rules have changed ?

TIA
Andrei Voropaev

2005-04-21, 7:52 am

On 2005-04-21, grid <prohit99@gmail.com> wrote:
> Hi,
> I was reading APUE (by Rich Stevens),and tried an example mentioned
> for using the chmod(2) sys call.It was mentioned that if I remove the
> group execute bit(S_IXGRP) from the file mode and added S_ISGID flag,
> this imples mandatory locking, and I should see a "l" at the place of
> the group execute bit for the file.But I ran the following program on
> both Linux & Solaris , and I dont see whats expected.
> ------
> int main()
> {
> struct stat statbuf;
>
> if(stat("st.c",&statbuf) < 0 ){
> perror("stat");
> exit(-1);
> }
> if(chmod("st.c",(statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0){
> perror("chmod");
> exit(-1);
> }
> return 0;
> }
>
> After running the executable , I get the following output when I list
> the file :
> $ ls -l st.c
> -rw-r-Sr-- 1 ropanda svrtech 126 Apr 5 07:25 st.c
>
> I just see the set-groupID bit set for the file.Am I doing something
> wrong here or the rules have changed ?


On Linux in 'info ls' I read

The permissions listed are similar to symbolic mode specifications
(*note Symbolic Modes:. But `ls' combines multiple bits into the
third character of each set of permissions as follows:
`s'
If the setuid or setgid bit and the corresponding executable
bit are both set.

`S'
If the setuid or setgid bit is set but the corresponding
executable bit is not set.

`t'
If the sticky bit and the other-executable bit are both set.

`T'
If the sticky bit is set but the other-executable bit is not
set.

`x'
If the executable bit is set and none of the above apply.

`-'
Otherwise.

So, there's no 'l' flag in this description. Only 'S', which you see in
the output. So I guess, this is system specific.

--
Minds, like parachutes, function best when open
SM Ryan

2005-04-21, 7:52 am

grid <prohit99@gmail.com> wrote:
# Hi,
# I was reading APUE (by Rich Stevens),and tried an example mentioned
# for using the chmod(2) sys call.It was mentioned that if I remove the
# group execute bit(S_IXGRP) from the file mode and added S_ISGID flag,
# this imples mandatory locking, and I should see a "l" at the place of
# the group execute bit for the file.But I ran the following program on
# both Linux & Solaris , and I dont see whats expected.

Not all unices support mandatory locking. You'll need to check if it's
at all possible on the specific system you're using and then how to do
it on your specific system. Advisory locking will be available.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Wow. A sailboat.
Michael Kerrisk

2005-04-22, 7:53 am

On Thu, 21 Apr 2005 12:02:42 -0000, SM Ryan
<wyrmwif@tango-sierra-oscar-foxtrot-tango.fake.org> wrote:

>grid <prohit99@gmail.com> wrote:
># Hi,
># I was reading APUE (by Rich Stevens),and tried an example mentioned
># for using the chmod(2) sys call.It was mentioned that if I remove the
># group execute bit(S_IXGRP) from the file mode and added S_ISGID flag,
># this imples mandatory locking, and I should see a "l" at the place of
># the group execute bit for the file.But I ran the following program on
># both Linux & Solaris , and I dont see whats expected.
>
>Not all unices support mandatory locking.


True, but it is supported on both Linux and Solaris.

> You'll need to check if it's
>at all possible on the specific system you're using and then how to do
>it on your specific system.


On Linux you'll need to specify "mount -o mand" when mounting the file
system (as well as g+s,g-x on the relevant files).

> Advisory locking will be available.


Yes. SUSv3 requires it.

Cheers,

Michael
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com