Return-Path: X-Original-To: apmail-apr-dev-archive@www.apache.org Delivered-To: apmail-apr-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4479510244 for ; Tue, 27 Aug 2013 21:20:25 +0000 (UTC) Received: (qmail 78953 invoked by uid 500); 27 Aug 2013 21:20:25 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 78842 invoked by uid 500); 27 Aug 2013 21:20:24 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 78834 invoked by uid 99); 27 Aug 2013 21:20:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Aug 2013 21:20:23 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [77.75.251.205] (HELO server1044-han.de-nserver.de) (77.75.251.205) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Aug 2013 21:20:17 +0000 Received: (qmail 18214 invoked from network); 27 Aug 2013 23:19:57 +0200 X-Fcrdns: Yes Received: from p5DC03D9A.dip0.t-ipconnect.de (HELO [192.168.0.6]) (93.192.61.154) (smtp-auth username stefan.ruppert@myarm.com, mechanism plain) by server1044-han.de-nserver.de (qpsmtpd/0.92) with (AES256-SHA encrypted) ESMTPSA; Tue, 27 Aug 2013 23:19:57 +0200 Message-ID: <521D1802.9080601@myarm.com> Date: Tue, 27 Aug 2013 23:20:02 +0200 From: Stefan Ruppert User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 MIME-Version: 1.0 To: APR Developer List Subject: apr_proc_mutex_* API using with different processes (not parent/child) does not work on Linux Content-Type: multipart/mixed; boundary="------------000509070707030901090906" X-User-Auth: Auth by stefan.ruppert@myarm.com through 93.192.61.154 X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. --------------000509070707030901090906 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Hi, 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: APR_FOPEN_CREATE | APR_FOPEN_WRITE | APR_FOPEN_EXCL 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_FOPEN_EXCL, APR_UREAD | APR_UWRITE, new_mutex->pool); } 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??? Regards, Stefan --------------000509070707030901090906 Content-Type: text/x-csrc; name="procmutex.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="procmutex.c" #include "apr-1/apr_proc_mutex.h" #include "apr-1/apr_time.h" #include #include #include int main(int argc, char *argv[]) { apr_status_t rc; apr_proc_mutex_t* lock; apr_pool_t *pool; int i=0; apr_initialize(); if(apr_pool_create(&pool, NULL) != APR_SUCCESS) exit(1); if((rc = apr_proc_mutex_create(&lock, argv[1], APR_LOCK_FLOCK, pool)) != APR_SUCCESS) { fprintf(stderr, "error: %d\n", rc); exit(2); } do { ++i; apr_proc_mutex_lock(lock); fprintf(stderr, "after lock: %d\n", (int)getpid()); apr_sleep(1000*1000); fprintf(stderr, "before unlock: %d\n", (int)getpid()); fprintf(stderr, "\n"); apr_proc_mutex_unlock(lock); apr_sleep(500*1000); } while(i < 100); return 0; } --------------000509070707030901090906--