You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jo...@apache.org on 2008/12/09 14:11:46 UTC

svn commit: r724682 - in /httpd/httpd/trunk: include/ap_socache.h modules/cache/mod_socache_dbm.c modules/cache/mod_socache_shmcb.c

Author: jorton
Date: Tue Dec  9 05:11:45 2008
New Revision: 724682

URL: http://svn.apache.org/viewvc?rev=724682&view=rev
Log:
Reduce config overhead for use of socache interface by allowing
default paths to be used if none are configured:

* include/ap_socache.h (ap_socache_provider_t::create):
  Allow arg to be NULL to force use of defaults.
  (ap_socache_provider_t::init): Rename 'namespace' parameter to
  'cname' and restrict to allow use in filesystem paths.
  
* modules/cache/mod_socache_dbm.c (socache_dbm_create, 
  socache_dbm_init),
  modules/cache/mod_socache_shmcb.c (socache_shmcb_create, 
  socache_shmcb_init): 
  Default to use of runtimedir-relative paths if no
  explicit path is configured.

Modified:
    httpd/httpd/trunk/include/ap_socache.h
    httpd/httpd/trunk/modules/cache/mod_socache_dbm.c
    httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c

Modified: httpd/httpd/trunk/include/ap_socache.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_socache.h?rev=724682&r1=724681&r2=724682&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_socache.h (original)
+++ httpd/httpd/trunk/include/ap_socache.h Tue Dec  9 05:11:45 2008
@@ -67,7 +67,8 @@
      * passed as the first argument to subsequent invocations.
      *
      * @param instance Output parameter to which instance object is written.
-     * @param arg Used-specified configuration string
+     * @param arg Used-specified configuration string.  May be NULL to
+     *        force use of defaults.
      * @param tmp Pool to be used for any temporary allocations
      * @param p Pool to be use for any allocations lasting as long as 
      * the created instance
@@ -76,18 +77,22 @@
     const char *(*create)(ap_socache_instance_t **instance, const char *arg, 
                           apr_pool_t *tmp, apr_pool_t *p);
 
-    /* Initialize the cache.  NAMESPACE must given a unique string
-     * prefix for use with memcached; if hints is non-NULL, it gives a
-     * set of hints for the provider.  Return APR error code. 
-
+    /* Initialize the cache.  The cname must be of maximum length 16
+     * characters, and uniquely identifies the consumer of the cache
+     * within the server; using the module name is recommended, e.g.
+     * "mod_ssl-sess".  This string may be used within a filesystem
+     * path so use of only alphanumeric [a-z0-9_-] characters is
+     * recommended.  If hints is non-NULL, it gives a set of hints for
+     * the provider.  Return APR error code.
+     *
      * @param instance The cache instance
-     * @param namespace A unique string identifying the consumer of this API
+     * @param cname A unique string identifying the consumer of this API
      * @param hints Optional hints argument describing expected cache use
      * @param s Server structure to which the cache is associated
      * @param pool Pool for long-lived allocations
      * @return APR status value indicating success.
      */
-    apr_status_t (*init)(ap_socache_instance_t *instance, const char *namespace, 
+    apr_status_t (*init)(ap_socache_instance_t *instance, const char *cname, 
                          const struct ap_socache_hints *hints,
                          server_rec *s, apr_pool_t *pool);
 

Modified: httpd/httpd/trunk/modules/cache/mod_socache_dbm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_socache_dbm.c?rev=724682&r1=724681&r2=724682&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_socache_dbm.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_socache_dbm.c Tue Dec  9 05:11:45 2008
@@ -53,6 +53,8 @@
  */
 #define SSL_DBM_FILE_MODE ( APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD )
 
+#define DEFAULT_DBM_PREFIX DEFAULT_REL_RUNTIMEDIR "/socache-dbm-"
+
 /* ### this should use apr_dbm_usednames. */
 #if !defined(SSL_DBM_FILE_SUFFIX_DIR) && !defined(SSL_DBM_FILE_SUFFIX_PAG)
 #if defined(DBM_SUFFIX)
@@ -81,9 +83,11 @@
 
     *context = ctx = apr_pcalloc(p, sizeof *ctx);
 
-    ctx->data_file = ap_server_root_relative(p, arg);
-    if (!ctx->data_file) {
-        return apr_psprintf(tmp, "Invalid cache file path %s", arg);
+    if (arg && *arg) {
+        ctx->data_file = ap_server_root_relative(p, arg);
+        if (!ctx->data_file) {
+            return apr_psprintf(tmp, "Invalid cache file path %s", arg);
+        }
     }
 
     apr_pool_create(&ctx->pool, p);
@@ -101,9 +105,17 @@
 
     /* for the DBM we need the data file */
     if (ctx->data_file == NULL) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
-                     "SSLSessionCache required");
-        return APR_EINVAL;
+        const char *path = apr_pstrcat(p, DEFAULT_DBM_PREFIX, namespace,
+                                       NULL);
+
+        ctx->data_file = ap_server_root_relative(p, path);
+
+        if (ctx->data_file == NULL) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
+                         "could not use default path '%s' for DBM socache",
+                         path);
+            return APR_EINVAL;
+        }
     }
 
     /* open it once to create it and to make sure it _can_ be created */

Modified: httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c?rev=724682&r1=724681&r2=724682&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c (original)
+++ httpd/httpd/trunk/modules/cache/mod_socache_shmcb.c Tue Dec  9 05:11:45 2008
@@ -269,9 +269,15 @@
     /* Allocate the context. */
     *context = ctx = apr_pcalloc(p, sizeof *ctx);
     
-    ctx->data_file = path = ap_server_root_relative(p, arg);
     ctx->shm_size  = 1024*512; /* 512KB */
 
+    if (!arg || *arg == '\0') {
+        /* Use defaults. */
+        return NULL;
+    }
+    
+    ctx->data_file = path = ap_server_root_relative(p, arg);
+
     cp = strchr(path, '(');
     if (cp) {
         *cp++ = '\0';
@@ -301,6 +307,9 @@
     return NULL;
 }
 
+#define DEFAULT_SHMCB_PREFIX DEFAULT_REL_RUNTIMEDIR "/socache-shmcb-"
+#define DEFAULT_SHMCB_SUFFIX ".cache"
+
 static apr_status_t socache_shmcb_init(ap_socache_instance_t *ctx,
                                        const char *namespace, 
                                        const struct ap_socache_hints *hints,
@@ -315,14 +324,25 @@
 
     /* Create shared memory segment */
     if (ctx->data_file == NULL) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
-                     "SSLSessionCache required");
-        return APR_EINVAL;
+        const char *path = apr_pstrcat(p, DEFAULT_SHMCB_PREFIX, namespace, 
+                                       DEFAULT_SHMCB_SUFFIX, NULL);
+
+        ctx->data_file = ap_server_root_relative(p, path);
     }
 
     /* Use anonymous shm by default, fall back on name-based. */
     rv = apr_shm_create(&ctx->shm, ctx->shm_size, NULL, p);
     if (APR_STATUS_IS_ENOTIMPL(rv)) {
+        /* If anon shm isn't supported, fail if no named file was
+         * configured successfully; the ap_server_root_relative call
+         * above will return NULL for invalid paths. */
+        if (ctx->data_file == NULL) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
+                         "Could not use default path '%s' for shmcb socache",
+                         ctx->data_file);
+            return APR_EINVAL;
+        }
+
         /* For a name-based segment, remove it first in case of a
          * previous unclean shutdown. */
         apr_shm_remove(ctx->data_file, p);
@@ -332,8 +352,8 @@
 
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
-                     "could not allocate shared memory for shmcb "
-                     "session cache");
+                     "Could not allocate shared memory segment for shmcb "
+                     "socache");
         return rv;
     }