Menu

#2 Absence of local *_FH in File::NFSLock::new causes errors

open
nobody
None
5
2007-06-11
2007-06-11
No

The following code includes a recursive call to File::NFSLock::new. However,
there is no localization of _FH handle within the new function :

188 ### If there was at least one stale lock discovered...
189 if (@dead) {
190 # Lock lock_file to avoid a race condition.
191 local $LOCK_EXTENSION = ".shared";
192 my $lock = new File::NFSLock {
193 file => $self->{lock_file},
194 lock_type => LOCK_EX,
195 blocking_timeout => 62,
196 stale_lock_timeout => 60,
197 };
198
199 ### Rescan in case lock contents were modified between time stale lock
200 ### was discovered and lockfile lock was acquired.
201 seek (_FH, 0, 0);

Therefore, if the recursive call to the new succeeds, the _FH handle that was
opened within the recursive call is closed. The result is the following error:

seek() on closed filehandle _FH at /opt/perl/5.8.5/lib/site_perl/5.8.5/File/NFSLock.pm line 201.
readline() on closed filehandle _FH at /opt/perl/5.8.5/lib/site_perl/5.8.5/File/NFSLock.pm line 203.

The fix will be add a local declaration:

local *_FH;

before the open in the new function:

161 ### If lock exists and is readable, see who is mooching on the lock
162
163 if ( -e $self->{lock_file} &&
164 open (_FH,"+<$self->{lock_file}") ){
165

The above error results causes the (@dead) part of the code not functioning
as expected - thus not recovering from stale locks.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.