> In a Registry script I open a file the first request and set a global
> variable flag.  Then for each request I just flock( FH, LOCK_SH ) and
> flock( FH, LOCK_UN).
> 
> The only problem I see is that if the lock isn't released I need to do 
> a graceful restart to get rid of that lock.  (But that would require a 
> bug in my program and I haven't put any in, yet.)

How about:
  sub cleanup {
    flock(FH, LOCK_UN);
  }

  $SIG{__DIE__} = sub { 
    cleanup();
    die($_[0]);
  };

  END { cleanup(); }

> If I open a file once and do many many LOCK_SH without LOCK_UN I don't
> think I'll be leaking, as it's on the same file handle.  Is this a 
> correct assumption?

You'll never been able to write to the file if you don't unlock a shared
lock.

You'll never been able to read from or write to the file if you don't
unlock an exclusive lock.

> A reason I don't do a LOCK_EX in the Registry script is that if I leak 
> a LOCK_EX lock then everything shuts down.

The above snippet should fix that, I think. Simple tests can verify if
it works or not.

> Plus those requests are served so much faster if I don't waste time 
> locking ;)

I don't see file locking taking up any mentionable amount of time,
unless the file is already locked. If the file is already locked and you
ignore the lock, it defies the the whole purpose of locking them in the
first place.

> Anyway, just looking for ideas.

Have you considered logging to a database?

ELB

--
Eric L. Brine  |  Chicken: The egg's way of making more eggs.
[EMAIL PROTECTED]  |  Do you always hit the nail on the thumb?
ICQ# 4629314   |  An optimist thinks thorn bushes have roses.

Reply via email to