Just wanted to let you know that I found the problem. I had an error in
my code where I was accidentally trying to put a read lock on a file
where I had not properly closed the write lock. This condition occurred
in error handling code and it was hard to find.
Anyway I was happy to learn that if you assign a file handle to a
lexical variable:
i.e.
my $FileHandle = Symbol::gensym();
open $FileHandle, $strOpenChar . $strFileName or eval{$blnError = 1};
then when the scope of that variable ends, be it in mod_perl or
elsewhere, the file is unlocked and closed even if you forget to do so.
Thanks for your help,
Justin
-----Original Message-----
From: Robert Landrum [mailto:[EMAIL PROTECTED]
Sent: Friday, April 13, 2007 3:16 PM
To: Justin Luster
Cc: 'Dondi M. Stroma'; [email protected]
Subject: Re: Lock Files - File is permanently locked
Justin Luster wrote:
> Here is an example of a call to OpenFile(). You will notice that I'm
> additionally locking the file itself as well as the lock file (I
figured
> it would not hurt to have both methods):
>
> my $LockFileHandle = authlib::FileLock("udata_" . $strRespNum .
> "_lck.cgi", 1);
>
> #Read restart question name
> my ($DataFileHandle, $blnError) = authlib::OpenFile($strDataFileName,
> "update", 1, 1);
>
> authlib::LockMe($DataFileHandle, 1);
>
> authlib::RestartQNameWrite($DataFileHandle, $strRestartQName);
>
> close $DataFileHandle;
>
> close authlib::FileUnLock($LockFileHandle);
Seems like an awful lot of code...
open(DATAFILE,">$strDataFileName") or die;
flock(DATAFILE,LOCK_EX);
seek(DATAFILE,0,0);
eval {
authlib::RestartQNameWrite(\*DATAFILE,$strRestartQName);
};
flock(DATAFILE,LOCK_UN);
close(DATAFILE);
if($@) {
die $@;
}
Code like that has never failed me on Solaris or Linux. I don't write
W32 code, so maybe it's more complicated than that.
Also,
> close authlib::FileUnLock($LockFileHandle);
That seems like an error waiting to happen, since FileUnLock doesn't
return a file handle.
Rob