From: Paul J. Reder Date: Thu, 24 Oct 2002 15:47:31 +0000 (+0000) Subject: Change the CacheRoot processing to check for a required X-Git-Tag: 2.0.44~230 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ccb3fa0ac746baf634a6d9e0d7f7716a0c06292c;p=apache 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] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97290 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index f4b5fd7e53..75dec3fac5 100644 --- 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 diff --git a/modules/experimental/mod_disk_cache.c b/modules/experimental/mod_disk_cache.c index a3c002e7f3..3ad36afe6e 100644 --- a/modules/experimental/mod_disk_cache.c +++ b/modules/experimental/mod_disk_cache.c @@ -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 = {