Thanx John, I have not tested it yet, but it looks right...will give it a
try 2nite.

Mark
----- Original Message -----
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 09, 2002 7:35 AM
Subject: Re: locking a file in linux


> Mark Goland wrote:
> >
> > This will do mandetory locking { which can also be done with "chmod +l
> > filename"}. If someone can rewrite this into perl , that  would be
great.
> >
> > /*
> >    write by Mark Goland use and enjoy keep the tag
> >    [EMAIL PROTECTED]
> > */
> >
> > #include <sys/types.h>
> > #include <sys/stat.h>
> > int main(int argc,char **argv){
> >
> > int mode;
> > struct stat buf;
> >
> > if( argc !=2 ){
> >  printf("%s [file_to_lock]\n",argv[0]);
> >  exit(1);
> > }
> >
> >   if (stat(argv[1], &buf) < 0) {
> >    perror("stat");
> >    exit (2);
> >   }
> >
> >   /* get currently set mode */
> >   mode = buf.st_mode;
> >   /* remove group execute permission from mode */
> >   mode &= ~(S_IEXEC>>3);
> >    /* set 'set group id bit' in mode */
> >   mode |= S_ISGID;
> >   if (chmod(argv[1], mode) < 0) {
> >    perror("chmod");
> >    exit(2);
> >   }
> > exit(0);
> > }
>
>
>
> #!/usr/bin/perl -w
> use strict;
> use Fcntl ':mode';
> use File::stat;
>
> unless ( @ARGV == 1 ) {
>     print "$0 [file_to_lock]\n";
>     exit 1;
> }
>
> unless ( my $buf = stat( $ARGV[0] ) ) {
>     warn "stat";
>     exit 2;
> }
>
> # get currently set mode
> my $mode = $buf->mode;
> # remove group execute permission from mode
> $mode &= ~( S_IEXEC >> 3 );
> # set 'set group id bit' in mode
> $mode |= S_ISGID;
> unless ( chmod( $mode, $ARGV[0] ) ) {
>     warn "chmod";
>     exit 2;
> }
> exit 0;
>
> __END__
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to