summaryrefslogtreecommitdiff
path: root/shmem
diff options
context:
space:
mode:
authorMladen Turk <mturk@apache.org>2008-05-20 05:40:36 +0000
committerMladen Turk <mturk@apache.org>2008-05-20 05:40:36 +0000
commite02df568e47a7f664548936e0970f016b409818c (patch)
treefcd1063b2f96d360950193a44617172b2acb4de3 /shmem
parent5cf01c19cd9e43eb282c48961141729ee2277671 (diff)
downloadapr-e02df568e47a7f664548936e0970f016b409818c.tar.gz
Remove shm backed file on cleanup/remove for creator
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@658105 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'shmem')
-rw-r--r--shmem/win32/shm.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/shmem/win32/shm.c b/shmem/win32/shm.c
index 580421e33..da736aa62 100644
--- a/shmem/win32/shm.c
+++ b/shmem/win32/shm.c
@@ -18,6 +18,7 @@
#include "apr_errno.h"
#include "apr_file_io.h"
#include "apr_shm.h"
+#include "apr_strings.h"
#include "apr_arch_file_io.h"
#include "limits.h"
@@ -33,6 +34,7 @@ struct apr_shm_t {
apr_size_t size;
apr_size_t length;
HANDLE hMap;
+ const char *filename;
};
static apr_status_t shm_cleanup(void* shm)
@@ -44,11 +46,13 @@ static apr_status_t shm_cleanup(void* shm)
rv = apr_get_os_error();
}
if (!CloseHandle(m->hMap)) {
- return (rv != APR_SUCCESS) ? rv : apr_get_os_error();
+ rv = rv != APR_SUCCESS ? rv : apr_get_os_error();
+ }
+ if (m->filename) {
+ /* Remove file if file backed */
+ apr_status_t rc = apr_file_remove(m->filename, m->pool);
+ rv = rv != APR_SUCCESS ? rv : rc;
}
- /* ### Do we want to make a point of unlinking m->file here?
- * Need to add the fname to the apr_shm_t, in that case.
- */
return rv;
}
@@ -159,6 +163,7 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
(*m)->memblk->length = (*m)->length;
(*m)->memblk->size = (*m)->size;
+ (*m)->filename = file ? apr_pstrdup(pool, file) : NULL;
apr_pool_cleanup_register((*m)->pool, *m,
shm_cleanup, apr_pool_cleanup_null);
@@ -252,6 +257,8 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
(*m)->hMap = hMap;
(*m)->length = (*m)->memblk->length;
(*m)->usrmem = (char*)base + sizeof(memblock_t);
+ (*m)->filename = NULL;
+
apr_pool_cleanup_register((*m)->pool, *m,
shm_cleanup, apr_pool_cleanup_null);
return APR_SUCCESS;
@@ -301,6 +308,7 @@ APR_DECLARE(apr_status_t) apr_os_shm_put(apr_shm_t **m,
/* Real (*m)->mem->size could be recovered with VirtualQuery */
(*m)->size = (*m)->memblk->size;
(*m)->length = (*m)->memblk->length;
+ (*m)->filename = NULL;
apr_pool_cleanup_register((*m)->pool, *m,
shm_cleanup, apr_pool_cleanup_null);