That patch had two bugs.  In _mutex we had already toggled the init
as completed so that flag test was bad, let's just look for mc->pMutex.
The other bug was the string scope created by apr_server_root_relative,
this updated patch keeps the resulting name in the global pool and
trashes the other temp strings with the cmd->temp_pool.

I've committed these patches to httpd-2.1 so they are well documented
and easy to retrieve and test.

Bill

At 05:03 PM 3/27/2003, William A. Rowe, Jr. wrote:
>We do have a problem across platforms;
>
>we skip the code in the ssl_cmd_SSLMutex after the first go around.
>The old code used mc->pPool as a permanent pool for the szMutexFile,
>but my previous patch used cfg->pool.  So this new patch uses the
>full-blown cmd->server->process->pool so the pstrdup'ed name hangs
>around for us.
>
>That's not my biggest problem - see the patch to ssl_mutex_init - it
>turns out we were creating a new mutex on every graceful restart,
>if I read things correctly.  So *no* platforms had a persistent mutex
>for the lifetime of the server.  Verified against 2.0.44 as well, this has
>been around a while.  The new patch creates the mutex itself in the
>s->process->pool as well so it's truly persistent.
>
>This patch is now tested on Win32, users on other platforms are asked
>to test this code.  Comments?
>
>Bill 
Index: modules/ssl/ssl_engine_mutex.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/ssl/ssl_engine_mutex.c,v
retrieving revision 1.20
retrieving revision 1.22
diff -u -r1.20 -r1.22
--- modules/ssl/ssl_engine_mutex.c      26 Mar 2003 22:31:56 -0000      1.20
+++ modules/ssl/ssl_engine_mutex.c      27 Mar 2003 23:51:22 -0000      1.22
@@ -73,8 +73,12 @@
     if (mc->nMutexMode == SSL_MUTEXMODE_NONE) 
         return TRUE;
 
+    if (mc->pMutex) {
+        return TRUE;
+    }
     if ((rv = apr_global_mutex_create(&mc->pMutex, mc->szMutexFile,
-                                mc->nMutexMech, p)) != APR_SUCCESS) {
+                                      mc->nMutexMech, s->process->pool))
+            != APR_SUCCESS) {
         if (mc->szMutexFile)
             ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                          "Cannot create SSLMutex with file `%s'",
Index: modules/ssl/ssl_engine_config.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/ssl/ssl_engine_config.c,v
retrieving revision 1.73
retrieving revision 1.75
diff -u -r1.73 -r1.75
--- modules/ssl/ssl_engine_config.c     23 Feb 2003 17:12:43 -0000      1.73
+++ modules/ssl/ssl_engine_config.c     28 Mar 2003 00:00:13 -0000      1.75
@@ -368,11 +368,20 @@
 
 const char *ssl_cmd_SSLMutex(cmd_parms *cmd,
                              void *dcfg,
-                             const char *arg)
+                             const char *arg_)
 {
     const char *err;
     SSLModConfigRec *mc = myModConfig(cmd->server);
-
+    /* Split arg_ into meth and file */
+    char *meth = apr_pstrdup(cmd->temp_pool, arg_);
+    char *file = strchr(meth, ':');
+    if (file) {
+        *(file++) = '\0';
+        if (!*file) {
+            file = NULL;
+        }
+    }
+    
     if ((err = ap_check_cmd_context(cmd, GLOBAL_ONLY))) {
         return err;
     }
@@ -380,97 +389,87 @@
     if (ssl_config_global_isfixed(mc)) {
         return NULL;
     }
-
-    if (strcEQ(arg, "none") || strcEQ(arg, "no")) {
+    if (!strcasecmp(meth, "none") || !strcasecmp(meth, "no")) {
         mc->nMutexMode  = SSL_MUTEXMODE_NONE;
+        return NULL;
     }
+
+    /* APR determines temporary filename unless overridden below,
+     * we presume file indicates an szMutexFile is a file path
+     * unless the method sets szMutexFile=file and NULLs file
+     */
+    mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    mc->szMutexFile = NULL;
+
     /* NOTE: previously, 'yes' implied 'sem' */
-    else if (strcEQ(arg, "default") || strcEQ(arg, "yes")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    if (!strcasecmp(meth, "default") || !strcasecmp(meth, "yes")) {
         mc->nMutexMech = APR_LOCK_DEFAULT;
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
     }
 #if APR_HAS_FLOCK_SERIALIZE
-    else if (strlen(arg) > 6 && strcEQn(arg, "flock:", 6)) {
-        const char *file = ap_server_root_relative(cmd->pool, arg+6);
-        if (!file) {
-            return apr_pstrcat(cmd->pool, "Invalid SSLMutex flock: path ", 
-                               arg+6, NULL);
-        }
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "flock") && file) {
         mc->nMutexMech = APR_LOCK_FLOCK;
-        mc->szMutexFile = apr_psprintf(mc->pPool, "%s.%lu",
-                                       file, (unsigned long)getpid());
     }
 #endif
 #if APR_HAS_FCNTL_SERIALIZE
-    else if (strlen(arg) > 6 && strcEQn(arg, "fcntl:", 6)) {
-        const char *file = ap_server_root_relative(cmd->pool, arg+6);
-        if (!file) {
-            return apr_pstrcat(cmd->pool, "Invalid SSLMutex fcntl: path ", 
-                               arg+6, NULL);
-        }
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "fcntl") && file) {
         mc->nMutexMech = APR_LOCK_FCNTL;
-        mc->szMutexFile = apr_psprintf(mc->pPool, "%s.%lu",
-                                       file, (unsigned long)getpid());
     }
 #endif
 #if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
-    else if (strcEQ(arg, "sysvsem")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "sysvsem") && file) {
         mc->nMutexMech = APR_LOCK_SYSVSEM;
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
     }
 #endif
 #if APR_HAS_POSIXSEM_SERIALIZE
-    else if (strcEQ(arg, "posixsem")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "posixsem")) {
         mc->nMutexMech = APR_LOCK_POSIXSEM;
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
+        mc->szMutexFile = apr_pstrdup(cmd->server->process->pool, file);
+        file = NULL;
     }
 #endif
 #if APR_HAS_PROC_PTHREAD_SERIALIZE
-    else if (strcEQ(arg, "pthread")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
+    else if (!strcasecmp(meth, "pthread")) {
         mc->nMutexMech = APR_LOCK_PROC_PTHREAD;
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
     }
 #endif
-#if APR_HAS_FLOCK_SERIALIZE || APR_HAS_FCNTL_SERIALIZE
-    else if (strlen(arg) > 5 && strcEQn(arg, "file:", 5)) {
-        const char *file = ap_server_root_relative(cmd->pool, arg+5);
-        if (!file) {
-            return apr_pstrcat(cmd->pool, "Invalid SSLMutex file: path ", 
-                               arg+5, NULL);
-        }
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
 #if APR_HAS_FLOCK_SERIALIZE
+    else if (!strcasecmp(meth, "file") && file) {
         mc->nMutexMech  = APR_LOCK_FLOCK;
-#endif
-#if APR_HAS_FCNTL_SERIALIZE
+    }
+#elif APR_HAS_FCNTL_SERIALIZE
+    else if (!strcasecmp(meth, "file") && file) {
         mc->nMutexMech  = APR_LOCK_FCNTL;
-#endif
-        mc->szMutexFile =
-            apr_psprintf(mc->pPool, "%s.%lu",
-                         file, (unsigned long)getpid());
     }
 #endif
-#if (APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)) || 
APR_HAS_POSIXSEM_SERIALIZE
-    else if (strcEQ(arg, "sem")) {
-        mc->nMutexMode  = SSL_MUTEXMODE_USED;
 #if APR_HAS_SYSVSEM_SERIALIZE && !defined(PERCHILD_MPM)
+    else if (!strcasecmp(meth, "sem")) {
         mc->nMutexMech  = APR_LOCK_SYSVSEM;
-#endif
-#if APR_HAS_POSIXSEM_SERIALIZE
+    }
+#elif APR_HAS_POSIXSEM_SERIALIZE
+    else if (!strcasecmp(meth, "sem")) {
         mc->nMutexMech  = APR_LOCK_POSIXSEM;
-#endif
-        mc->szMutexFile = NULL; /* APR determines temporary filename */
+        /* Posix/SysV semaphores aren't file based, use the literal name 
+         * if provided and fall back on APR's default if not.
+         */
+        mc->szMutexFile = apr_pstrdup(cmd->server->process->pool, file);
+        file = NULL;
     }
 #endif
     else {
-        return apr_pstrcat(cmd->pool, "Invalid SSLMutex argument ", 
-                           arg, " (", ssl_valid_ssl_mutex_string, ")", NULL);
+        return apr_pstrcat(cmd->pool, "Invalid SSLMutex argument ", arg_,
+                           " (", ssl_valid_ssl_mutex_string, ")", NULL);
+    }
+
+    /* Unless the method above assumed responsibility for setting up
+     * mc->szMutexFile and NULLing out file, presume it is a file we
+     * are looking to use
+     */
+    if (file) {
+        mc->szMutexFile = ap_server_root_relative(cmd->server->process->pool, file);
+        if (!mc->szMutexFile) {
+            return apr_pstrcat(cmd->pool, "Invalid SSLMutex ", meth, 
+                               ": filepath ", file, NULL);
+        }
     }
 
     return NULL;


Reply via email to