apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Ruppert ...@myarm.com>
Subject apr_proc_mutex_* API using with different processes (not parent/child) does not work on Linux
Date Tue, 27 Aug 2013 21:20:02 GMT

I want to use the apr_proc_mutex_* API to synchronize processes. But if 
I want to use a APR_LOCK_FLOCK mutex the second process will fail to 
open the mutex with a File exists error. This is due to the fact the 
file is opened with the flags:

If I remove the APR_FOPEN_EXCL it works. So it seems to me that 
apr_proc_mutex_* API only works on Linux for parent/child processes 
which uses the apr_proc_mutex_child_init() function within the forked 
child process!? Current documentation says nothing about that.

static apr_status_t proc_mutex_flock_create(apr_proc_mutex_t *new_mutex,
                                             const char *fname)
     int rv;

     if (fname) {
         new_mutex->fname = apr_pstrdup(new_mutex->pool, fname);
         rv = apr_file_open(&new_mutex->interproc, new_mutex->fname,
                            APR_FOPEN_CREATE | APR_FOPEN_WRITE | 
                            APR_UREAD | APR_UWRITE,
     else {

Attached you will find a simple test program if started twice with the 
same lock file one of the two processes will terminate with a "file 
exists" error:

./procmutex mylock&
./procmutex mylock&

Any ideas to solve this problem? Does anyone rely on the fact the passed 
file need to be non-existing???


View raw message