]> granicus.if.org Git - apache/commitdiff
Change the CacheRoot processing to check for a required
authorPaul J. Reder <rederpj@apache.org>
Thu, 24 Oct 2002 15:47:31 +0000 (15:47 +0000)
committerPaul J. Reder <rederpj@apache.org>
Thu, 24 Oct 2002 15:47:31 +0000 (15:47 +0000)
value at config time. This saves a lot of wasted processing
if the mod_disk_cache module is loaded but no CacheRoot
was provided. This fix also adds code to log an error
and avoid useless pallocs and procesing when the computed
cache file name cannot be opened. This also updates the
docs accordingly.  [Paul J. Reder]

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97290 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/experimental/mod_disk_cache.c

diff --git a/CHANGES b/CHANGES
index f4b5fd7e5393f64af165da10ef610eb017c7c120..75dec3fac5350f61c4c693de3cc6fd50a1e51f51 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,13 @@
 Changes with Apache 2.0.44
 
+  *) Change the CacheRoot processing to check for a required
+     value at config time. This saves a lot of wasted processing
+     if the mod_disk_cache module is loaded but no CacheRoot
+     was provided. This fix also adds code to log an error
+     and avoid useless pallocs and procesing when the computed
+     cache file name cannot be opened. This also updates the
+     docs accordingly.  [Paul J. Reder]
+
   *) Introduce the EnableSendfile directive, allowing users of NFS 
      shares to disable sendfile mechanics when they either fail
      outright or provide intermitantly corrupted data.  PR 
index a3c002e7f3e3b31ac87868eb495c64dc01d74d9c..3ad36afe6ec8c321ba3698d6447e2428c6c95fb6 100644 (file)
@@ -349,16 +349,24 @@ static int create_entity(cache_handle_t *h, request_rec *r,
     rv = apr_file_mktemp(&tmpfile, dobj->tempfile,  
                          APR_CREATE | APR_READ | APR_WRITE | APR_EXCL, r->pool);
 
-    /* Populate the cache handle */
-    h->cache_obj = obj;
-    h->read_body = &read_body;
-    h->read_headers = &read_headers;
-    h->write_body = &write_body;
-    h->write_headers = &write_headers;
-    h->remove_entity = &remove_entity;
+    if (rv == APR_SUCCESS) {
+        /* Populate the cache handle */
+        h->cache_obj = obj;
+        h->read_body = &read_body;
+        h->read_headers = &read_headers;
+        h->write_body = &write_body;
+        h->write_headers = &write_headers;
+        h->remove_entity = &remove_entity;
 
-    ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
-                 "disk_cache: Caching URL %s",  key);
+        ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
+                     "disk_cache: Caching URL %s",  key);
+    }
+    else {
+        ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
+                     "disk_cache: Could not cache URL %s [%d]", key, rv);
+
+        return DECLINED;
+    }
 
     return OK;
 }
@@ -812,6 +820,22 @@ static const char
     */
     return NULL;
 }
+
+static int disk_cache_post_config(apr_pool_t *p, apr_pool_t *plog,
+                                  apr_pool_t *ptemp, server_rec *s)
+{
+    disk_cache_conf *conf = ap_get_module_config(s->module_config,
+                                                   &disk_cache_module);
+    if (conf->cache_root == NULL) {
+        ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s,
+                     "CacheRoot must be initialized for mod_disk_cache to function.");
+
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
+
+    return OK;
+}
+
 static const command_rec disk_cache_cmds[] =
 {
     AP_INIT_TAKE1("CacheRoot", set_cache_root, NULL, RSRC_CONF,
@@ -849,6 +873,7 @@ static void disk_cache_register_hook(apr_pool_t *p)
     cache_hook_create_entity(create_entity, NULL, NULL, APR_HOOK_MIDDLE);
     cache_hook_open_entity(open_entity,  NULL, NULL, APR_HOOK_MIDDLE);
 /*    cache_hook_remove_entity(remove_entity, NULL, NULL, APR_HOOK_MIDDLE); */
+    ap_hook_post_config(disk_cache_post_config, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
 module AP_MODULE_DECLARE_DATA disk_cache_module = {