From: Jim Jagielski Date: Mon, 27 Sep 2010 17:37:33 +0000 (+0000) Subject: Allow for non-persist of shared mem X-Git-Tag: 2.3.9~409 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91306794eaff1b053840cc4420b11985e9c0d4fc;p=apache Allow for non-persist of shared mem git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1001831 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/mod_slotmem_shm.xml b/docs/manual/mod/mod_slotmem_shm.xml index 4dad3f10b8..66678283bd 100644 --- a/docs/manual/mod/mod_slotmem_shm.xml +++ b/docs/manual/mod/mod_slotmem_shm.xml @@ -49,13 +49,15 @@
call the callback on all worker slots
apr_status_t create(ap_slotmem_instance_t **new, const char *name, apr_size_t item_size, unsigned int item_num, ap_slotmem_type_t type, apr_pool_t *pool)
-
create a new slotmem with each item size is item_size. name is the filename for the persistant store of +
create a new slotmem with each item size is item_size. name is the filename for the persistent store of the shared memory. Values are:
-
anonymous
+
"none"
+
Does not persist shared memory in file.
+
"anonymous"
$server_root/logs/anonymous.slotmem
-
:module_name.c
-
$server_root/logs/module_name.c.slotmem
+
":file-name"
+
$server_root/logs/file-name.slotmem
"absolute-file-name"
$absolute-file-name.slotmem
diff --git a/modules/slotmem/mod_slotmem_shm.c b/modules/slotmem/mod_slotmem_shm.c index 764bae8bba..e3c688fc57 100644 --- a/modules/slotmem/mod_slotmem_shm.c +++ b/modules/slotmem/mod_slotmem_shm.c @@ -106,10 +106,11 @@ static apr_status_t unixd_set_shm_perms(const char *fname) } /* - * Persiste the slotmem in a file + * Persist the slotmem in a file * slotmem name and file name. + * none : no persistent data * anonymous : $server_root/logs/anonymous.slotmem - * :module.c : $server_root/logs/module.c.slotmem + * :rel_name : $server_root/logs/rel_name.slotmem * abs_name : $abs_name.slotmem * */ @@ -117,7 +118,9 @@ static const char *store_filename(apr_pool_t *pool, const char *slotmemname) { const char *storename; const char *fname; - if (strcmp(slotmemname, "anonymous") == 0) + if (strcasecmp(slotmemname, "none") == 0) + return NULL; + else if (strcasecmp(slotmemname, "anonymous") == 0) fname = ap_server_root_relative(pool, "logs/anonymous"); else if (slotmemname[0] == ':') { const char *tmpname; @@ -140,20 +143,22 @@ static void store_slotmem(ap_slotmem_instance_t *slotmem) storename = store_filename(slotmem->gpool, slotmem->name); - rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, - APR_OS_DEFAULT, slotmem->gpool); - if (APR_STATUS_IS_EEXIST(rv)) { - apr_file_remove(storename, slotmem->gpool); + if (storename) { rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT, slotmem->gpool); + if (APR_STATUS_IS_EEXIST(rv)) { + apr_file_remove(storename, slotmem->gpool); + rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, + APR_OS_DEFAULT, slotmem->gpool); + } + if (rv != APR_SUCCESS) { + return; + } + nbytes = (slotmem->desc.size * slotmem->desc.num) + + (slotmem->desc.num * sizeof(char)); + apr_file_write(fp, slotmem->base, &nbytes); + apr_file_close(fp); } - if (rv != APR_SUCCESS) { - return; - } - nbytes = (slotmem->desc.size * slotmem->desc.num) + - (slotmem->desc.num * sizeof(char)); - apr_file_write(fp, slotmem->base, &nbytes); - apr_file_close(fp); } /* should be apr_status_t really */ @@ -166,21 +171,24 @@ static void restore_slotmem(void *ptr, const char *name, apr_size_t size, apr_status_t rv; storename = store_filename(pool, name); - rv = apr_file_open(&fp, storename, APR_READ | APR_WRITE, APR_OS_DEFAULT, - pool); - if (rv == APR_SUCCESS) { - apr_finfo_t fi; - if (apr_file_info_get(&fi, APR_FINFO_SIZE, fp) == APR_SUCCESS) { - if (fi.size == nbytes) { - apr_file_read(fp, ptr, &nbytes); - } - else { - apr_file_close(fp); - apr_file_remove(storename, pool); - return; + + if (storename) { + rv = apr_file_open(&fp, storename, APR_READ | APR_WRITE, APR_OS_DEFAULT, + pool); + if (rv == APR_SUCCESS) { + apr_finfo_t fi; + if (apr_file_info_get(&fi, APR_FINFO_SIZE, fp) == APR_SUCCESS) { + if (fi.size == nbytes) { + apr_file_read(fp, ptr, &nbytes); + } + else { + apr_file_close(fp); + apr_file_remove(storename, pool); + return; + } } + apr_file_close(fp); } - apr_file_close(fp); } }