From commits-return-10822-apmail-apr-commits-archive=apr.apache.org@apr.apache.org Thu Sep 10 20:59:09 2009 Return-Path: Delivered-To: apmail-apr-commits-archive@www.apache.org Received: (qmail 36049 invoked from network); 10 Sep 2009 20:59:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Sep 2009 20:59:09 -0000 Received: (qmail 23614 invoked by uid 500); 10 Sep 2009 20:59:09 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 23550 invoked by uid 500); 10 Sep 2009 20:59:09 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 23538 invoked by uid 99); 10 Sep 2009 20:59:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2009 20:59:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2009 20:58:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 45E5523888E4; Thu, 10 Sep 2009 20:58:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r813586 - in /apr/apr/branches/1.4.x: CHANGES STATUS locks/unix/proc_mutex.c Date: Thu, 10 Sep 2009 20:58:35 -0000 To: commits@apr.apache.org From: jim@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090910205835.45E5523888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jim Date: Thu Sep 10 20:58:34 2009 New Revision: 813586 URL: http://svn.apache.org/viewvc?rev=813586&view=rev Log: Merge r811455, r813063 from trunk: Allow for passed locknames to be honored with posix-sems. Still maintain posix-sem naming conventions tho! just use it :) Reviewed/backported by: jim Modified: apr/apr/branches/1.4.x/CHANGES apr/apr/branches/1.4.x/STATUS apr/apr/branches/1.4.x/locks/unix/proc_mutex.c Modified: apr/apr/branches/1.4.x/CHANGES URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/CHANGES?rev=813586&r1=813585&r2=813586&view=diff ============================================================================== --- apr/apr/branches/1.4.x/CHANGES [utf-8] (original) +++ apr/apr/branches/1.4.x/CHANGES [utf-8] Thu Sep 10 20:58:34 2009 @@ -5,8 +5,11 @@ Fix overflow in pools and rmm, where size alignment was taking place. [Matt Lewis , Sander Striker] + *) Posix semaphores can now be named and used as named semaphores. + [Jim Jagielski] + *) Better handling of APR_OFF_T_FMT for Darwin 10 depending on -arch - setting of compiler [Jim Jagielski] + setting of compiler. [Jim Jagielski] *) Add comments describing the thread-safety properties of apr_pool_t. [Neil Conway nrc cs.berkeley.edu] Modified: apr/apr/branches/1.4.x/STATUS URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/STATUS?rev=813586&r1=813585&r2=813586&view=diff ============================================================================== --- apr/apr/branches/1.4.x/STATUS [utf-8] (original) +++ apr/apr/branches/1.4.x/STATUS [utf-8] Thu Sep 10 20:58:34 2009 @@ -64,13 +64,6 @@ CURRENT VOTES: - * unix/proc_mutex.c: Allow for Posix-sems to be actually named. - Trunk Version: - http://svn.apache.org/viewvc?view=rev&revision=811455 - http://svn.apache.org/viewvc?view=rev&revision=813063 - 1.4 Version: - trunk works - +1: jim CURRENT test/testall -v EXCEPTIONS: Modified: apr/apr/branches/1.4.x/locks/unix/proc_mutex.c URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/locks/unix/proc_mutex.c?rev=813586&r1=813585&r2=813586&view=diff ============================================================================== --- apr/apr/branches/1.4.x/locks/unix/proc_mutex.c (original) +++ apr/apr/branches/1.4.x/locks/unix/proc_mutex.c Thu Sep 10 20:58:34 2009 @@ -18,6 +18,7 @@ #include "apr_strings.h" #include "apr_arch_proc_mutex.h" #include "apr_arch_file_io.h" /* for apr_mkstemp() */ +#include "apr_md5.h" /* for apr_md5() */ APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex) { @@ -54,11 +55,10 @@ static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex, const char *fname) { + #define APR_POSIXSEM_NAME_MAX 30 + #define APR_POSIXSEM_NAME_MIN 13 sem_t *psem; - char semname[31]; - apr_time_t now; - unsigned long sec; - unsigned long usec; + char semname[APR_MD5_DIGESTSIZE * 2 + 2]; new_mutex->interproc = apr_palloc(new_mutex->pool, sizeof(*new_mutex->interproc)); @@ -69,28 +69,46 @@ * - be at most 14 chars * - be unique and not match anything on the filesystem * - * Because of this, we ignore fname, and try our - * own naming system. We tuck the name away, since it might - * be useful for debugging. to make this as robust as possible, - * we initially try something larger (and hopefully more unique) - * and gracefully fail down to the LCD above. + * Because of this, we use fname to generate an md5 hex checksum + * and use that as the name of the semaphore. If no filename was + * given, we create one based on the time. We tuck the name + * away, since it might be useful for debugging. + * + * To make this as robust as possible, we initially try something + * larger (and hopefully more unique) and gracefully fail down to the + * LCD above. * * NOTE: Darwin (Mac OS X) seems to be the most restrictive * implementation. Versions previous to Darwin 6.2 had the 14 * char limit, but later rev's allow up to 31 characters. * */ - now = apr_time_now(); - sec = apr_time_sec(now); - usec = apr_time_usec(now); - apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", sec, usec); + if (fname) { + unsigned char digest[APR_MD5_DIGESTSIZE]; /* note dependency on semname here */ + const char *hex = "0123456789abcdef"; + char *p = semname; + int i; + apr_md5(digest, fname, strlen(fname)); + *p++ = '/'; /* must start with /, right? */ + for (i = 0; i < sizeof(digest); i++) { + *p++ = hex[digest[i] >> 4]; + *p++ = hex[digest[i] & 0xF]; + } + semname[APR_POSIXSEM_NAME_MAX] = '\0'; + } else { + apr_time_t now; + unsigned long sec; + unsigned long usec; + now = apr_time_now(); + sec = apr_time_sec(now); + usec = apr_time_usec(now); + apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", sec, usec); + } psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1); if (psem == (sem_t *)SEM_FAILED) { if (errno == ENAMETOOLONG) { /* Oh well, good try */ - semname[13] = '\0'; - } else if (errno == EEXIST) { - apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", usec, sec); + semname[APR_POSIXSEM_NAME_MIN] = '\0'; } else { return errno; }