apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Tikhonov <dmi...@netilla.com>
Subject Re: flock() does not work in Apache2 module.
Date Thu, 08 May 2003 18:06:00 GMT

On Thu, 8 May 2003, William A. Rowe, Jr. wrote:

> At 12:14 PM 5/8/2003, Dmitri Tikhonov wrote:
> >I've run into an interesting problem: my module needs to read
> >configuration from a file that is occasionally changed by another process.
> >I've created a test C program that reads configuration if it can obtain a
> >lock using flock(2) function:
> >
> >    if (-1 == flock(fd, LOCK_SH|LOCK_NB)) {
> Why not apr_file_lock?

Because on unix boxes, apr_file_lock will use fnctl, but I want just the
advisory lock.

> If not - why would you be asking here {dev@apr}?

I suspect that Apache libraries have something to do with flock not
working properly.

> >However, when I put the function into my module, flock() always gets the
> >lock, no matter what.  Question: has anyone seen this before?  is there
> >a side-effect of Apache environment that I'm not aware of?
> Ok, the answer (this applies to unix apr_file_lock too) ... unix flock is
> an advisory lock - it isn't enforced except between processes that choose
> to use it.
> So unless the other application that modifies that file chooses to use
> flock, you can't use flock to sync updates between two apps.

I know, and they both use flock.  The problem is that the other
application is written in Perl, and I don't want to use Apache::APR.

I could use some other locking scheme, such as a lock file (.lck), because
updates do not happen that often, but it wouldn't be as clean as I'd like.

  - Dmitri.

View raw message