> On Thu, 29 Jun 2000, Stas Bekman wrote:
> 
> > When using file locking one must make sure, that if the script has been
> > stopped before the close() was called, to use an END block under Registry
> > or $r->register_cleanup() anywhere. See:
> > http://perl.apache.org/guide/debug.html#Handling_the_User_pressed_Stop_
> > http://perl.apache.org/guide/debug.html#Cleanup_Code
> > 
> > Otherwise you might get stuck with a stale lock, which will be never
> > removed unless the same process will call open() on the same filehandler.
> > And it'd be the same filehandler only if you use "open, IN ..." style, if
> > you use Symbol module or perl5.6 filehandler autovivification a new unique
> > filehandler will be created when the same code will run again.
> > 
> > So close() under mod_perl is not enough when locking is used.
> 
> Are you suggesting that more has to be done even if you use my $fh type
> opening? I'm not sure I believe you, if thats what you're suggesting - the
> second paragraph there seems to confuse things. If you use my $fh style
> opening (either the Symbol or 5.6 way) you need worry not about unlocking
> files or cleanup code for unlocking/closing files - it's all done by the
> garbage collector. (you should close your filehandles anyway though for
> the sake of cleanliness and not leaving around locks, but my point was
> merely the necessity of it).

Frank were talking about using globals. I forgot to stress this point. My
post is correct only when assuming that one uses globals.

so if you use 

  use vars ($fh)
  $fh = Symbol::gensym; # or Apache::Symbol
  open $fh, "foo" ...

it holds. Now thinking again about 5.6, I'm not sure about this:

  use vars ($fh)
  open $fh, "foo"...

is the auto-vivication of a unique filehandler works in this case? Or
only when one uses:

  open my $fh, "foo"...

if the latter is correct, my statement is incorrect regrading the perl5.6
autovivication, and only these two cases hold:

  # 1
  open IN, "foo" ....

  # 2
  use vars ($fh)
  $fh = Symbol::gensym; # or Apache::Symbol
  open $fh, "foo" ...

In both you should worry to add a cleanup code.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:[EMAIL PROTECTED]   http://perl.org     http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org



Reply via email to