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); } ----- Original Message ----- From: "Ramprasad A Padmanabhan" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "Michael Fowler" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, September 04, 2002 2:49 AM Subject: Re: locking a file in linux > Michael Fowler wrote: > > On Mon, Sep 02, 2002 at 03:56:22PM +0530, Ramprasad A Padmanabhan wrote: > > > >>Hi All, > >> I am writing an web application where multiple users may write into > >>the same file concurrently. Also there is a probability that there may > >>be an admin who has opened up the file in 'vi' and editing the file. > >> > >> I want to avoid this concurrent multiple opens. > >>I tried a range on perl modules like IO::LockedFile, File::Flock; > >>LockFile::Simple etc but all these do not enforce any lock and worst > >>they lock a file even if it is already open in vi > > > > > > As has been mentioned elsewhere on this thread, all of these modules provide > > only advisory locking. This means that each process that wishes to modify > > the file must first lock it with the same method. > > > > This will not cause a problem with your application, because you can add the > > locked ability to it. It will, however, cause a problem with your admin > > editing the file directly. One solution is to force the admin to run their > > editor in a wrapper. For example, you can provide the admin with a simple > > script, say "edit-db-file", that locks the file just as your web application > > does, and then invokes his preferred editor (in $ENV{VISUAL} or > > $ENV{EDITOR}). You'll have to educate your admin (assuming he or she needs > > it) that this is the only method with which they are to edit the file, and > > that they must make their edits quickly. The quickly part is so that the > > web application, and by extension the user of that application, doesn't have > > to wait forever to edit the file, or receive an error after the lock times > > out. > > > > Really, though, why is the admin editing this file directly? Can you not > > provide some sort of web interface for the admin as well? That way the > > admin can't screw up with the lock, and errors in the file itself are less > > likely. > > > > > > Michael > > -- > > Administrator www.shoebox.net > > Programmer, System Administrator www.gallanttech.com > > -- > > Thanx All > But I will still like to have kernel enforced mandatory locking on > the file Can you tell me how to do it > > > -- > 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]