Hi,
 
I've read through some of the documentation on perl.apache.org about
file locking and mod_perl.  I believe that I'm following the advice
there but I'm still having problems.
 
I have individual data files that processes write to.  I've decided to
follow Dominus's advice
(http://perl.plover.com/yak/flock/samples/slide011.html ) to have an
extra lock file that is locked before writing to the actual data file.
 
I cannot reproduce the error consistently but from time to time one of
my lock files gets locked and stays locked.  I'm running Mod_Perl on a
Linux Machine.

(SERVER_SOFTWARE => Apache/1.3.27 (Unix) (Red-Hat/Linux)
FrontPage/5.0.2.2623 mod_python/2.7.8 Python/1.5.2 mod_ssl/2.8.12
OpenSSL/0.9.6b DAV/1.0.3 mod_perl/1.26 mod_webapp/1.2.0-dev)
 
As per the advice of perl.apache.org I'm using lexically scoped
variables (created with my ()) to create these lock files.  So I'm
confused as to why any lock would hang around.  Here is an example of
how I'm opening files:
 
sub OpenFile
{
my $FileHandle = Symbol::gensym();
 
open $FileHandle, $strOpenChar . $strFileName or eval{$blnError = 1};
 
return $FileHandle;
}
 
The $FileHandle is then explicitly closed in the calling code.  And even
if it is not, and I've made an error, once it goes out of scope the file
handle and the lock should be closed out.
 
Here is an example of my flock code:
 
sub LockMe
{
            my ($FileHandle, $blnExclusive) = @_;
 
            my $blnFlockSupported = 1;
 
            eval
            {
                        if ($blnExclusive) 
                        {
                                    #Lock for exclusive write access.
                                    flock $FileHandle, 2;
                        }
                        else
                        {
                                    #Lock it as a shared for multiple
readers, but it will not let a writer in.
                                    flock $FileHandle, 1;
                        }
            };
            if ($@) 
            {
                        $blnFlockSupported = 0;
                        $authlib::blnGlobalFlockSupported = 0;
            }
            
            #Another process might have changed the file position.
            seek $FileHandle, 0, 0;
 
            return $blnFlockSupported;
}
 
 
Does anyone know what might be happening?  We are only using
Apache::Registry in this instance.  I can't see how a lexically scoped
file handle that is being locked is not being unlocked once the process
ends.
 
Thanks for any help,
 
Justin

Reply via email to