apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gordon Henriksen <gordonhenrik...@me.com>
Subject Re: apr_file_* weirdness on Mac OS X
Date Fri, 03 Oct 2008 14:24:17 GMT
On 2008-10-03, at 02:40, Tim Bray wrote:

> I'm developing a module which accepts a large number of POST  
> requests, receives the request bodies, and persists them into  
> ordinary files in the filesystem.  On OS X, there are occasions  
> where the file is (rarely) transiently not there.  The idiom looks  
> like this
> Same code running in -X single-threaded mode, no problem.  Same code  
> on Solaris, no problem.  (Well, yes, there are other weird Solaris  
> problems with mutexes, but we'll get to those).

Sounds like a race. I'd suggest you replace this:

>    status = apr_file_open(&fp, tempname, APR_FOPEN_WRITE |  
>                           PERMS, pool);


apr_status_t status;
do {
   ... generate random filename ...
   status = apr_file_open(..., APR_FOPEN_WRITE|APR_FOPEN_CREATE| 
} while (APR_IS_EEXIST(status));

in order to hedge against another thread operating on the same  
filename concurrently. apr_file_mktemp will handle this detail  
transparently for you.

— Gordon

View raw message