summaryrefslogtreecommitdiff
path: root/shmem
diff options
context:
space:
mode:
authorJeff Trawick <trawick@apache.org>2013-10-20 20:50:11 +0000
committerJeff Trawick <trawick@apache.org>2013-10-20 20:50:11 +0000
commitcc02ce9602561411fd5fb0f760bb1a1cbffa1270 (patch)
treeb2b6563d67c3462a0acc64c3246ad0d7d2ea6d39 /shmem
parent056b90bd99e44cbf3697d3a0e8135d84028e4efa (diff)
downloadapr-cc02ce9602561411fd5fb0f760bb1a1cbffa1270.tar.gz
Follow-up to r1531768:
Add apr_shm_create_ex() and apr_shm_attach_ex(), which provide the ability to select the Global or Local namespace on Windows. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1533979 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'shmem')
-rw-r--r--shmem/beos/shm.c17
-rw-r--r--shmem/os2/shm.c17
-rw-r--r--shmem/unix/shm.c17
-rw-r--r--shmem/win32/shm.c69
4 files changed, 105 insertions, 15 deletions
diff --git a/shmem/beos/shm.c b/shmem/beos/shm.c
index d6b888b08..db94dce32 100644
--- a/shmem/beos/shm.c
+++ b/shmem/beos/shm.c
@@ -71,6 +71,15 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *filename,
+ apr_pool_t *p,
+ apr_int32_t flags)
+{
+ return apr_shm_create(m, reqsize, filename, p);
+}
+
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
{
delete_area(m->aid);
@@ -133,6 +142,14 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *filename,
+ apr_pool_t *pool,
+ apr_int32_t flags)
+{
+ return apr_shm_attach(m, filename, pool);
+}
+
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
{
delete_area(m->aid);
diff --git a/shmem/os2/shm.c b/shmem/os2/shm.c
index f2c1b7dfb..81de941c2 100644
--- a/shmem/os2/shm.c
+++ b/shmem/os2/shm.c
@@ -56,6 +56,15 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *filename,
+ apr_pool_t *p,
+ apr_int32_t flags)
+{
+ return apr_shm_create(m, reqsize, filename, p);
+}
+
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
{
DosFreeMem(m->memblock);
@@ -90,6 +99,14 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *filename,
+ apr_pool_t *pool,
+ apr_int32_t flags)
+{
+ return apr_shm_attach(m, filename, pool);
+}
+
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
{
int rc = 0;
diff --git a/shmem/unix/shm.c b/shmem/unix/shm.c
index f1259e232..f907000c8 100644
--- a/shmem/unix/shm.c
+++ b/shmem/unix/shm.c
@@ -365,6 +365,15 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
}
}
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *filename,
+ apr_pool_t *p,
+ apr_int32_t flags)
+{
+ return apr_shm_create(m, reqsize, filename, p);
+}
+
APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
apr_pool_t *pool)
{
@@ -569,6 +578,14 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
}
}
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *filename,
+ apr_pool_t *pool,
+ apr_int32_t flags)
+{
+ return apr_shm_attach(m, filename, pool);
+}
+
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
{
apr_status_t rv = shm_cleanup_attach(m);
diff --git a/shmem/win32/shm.c b/shmem/win32/shm.c
index 930a25c74..af0115e44 100644
--- a/shmem/win32/shm.c
+++ b/shmem/win32/shm.c
@@ -114,10 +114,11 @@ static int can_create_global_maps(void)
}
#endif /* SE_CREATE_GLOBAL_NAME */
-APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
- apr_size_t reqsize,
- const char *file,
- apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *file,
+ apr_pool_t *pool,
+ apr_int32_t flags)
{
static apr_size_t memblock = 0;
HANDLE hMap, hFile;
@@ -154,6 +155,8 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
mapkey = NULL;
}
else {
+ int global;
+
/* Do file backed, which is not an inherited handle
* While we could open APR_EXCL, it doesn't seem that Unix
* ever did. Ignore that error here, but fail later when
@@ -172,7 +175,16 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
* without slashes or backslashes, and prepends the \global
* or \local prefix on Win2K and later
*/
- mapkey = res_name_from_filename(file, can_create_global_maps(), pool);
+ if (flags & APR_SHM_NS_GLOBAL) {
+ global = 1;
+ }
+ else if (flags & APR_SHM_NS_LOCAL) {
+ global = 0;
+ }
+ else {
+ global = can_create_global_maps();
+ }
+ mapkey = res_name_from_filename(file, global, pool);
}
#if APR_HAS_UNICODE_FS
@@ -228,6 +240,14 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
+ apr_size_t reqsize,
+ const char *file,
+ apr_pool_t *pool)
+{
+ return apr_shm_create_ex(m, reqsize, file, pool, 0);
+}
+
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
{
apr_status_t rv = shm_cleanup(m);
@@ -318,24 +338,36 @@ static apr_status_t shm_attach_internal(apr_shm_t **m,
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
- const char *file,
- apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_shm_attach_ex(apr_shm_t **m,
+ const char *file,
+ apr_pool_t *pool,
+ apr_int32_t flags)
{
apr_status_t rv;
- int can_create_global = can_create_global_maps();
- int try_global_local[3] = {1, /* first try to find shm under global namespace */
- 0, /* next try to find it under local namespace */
- -1}; /* nothing more to try */
+ int can_create_global;
+ int try_global_local[3] = {-1, -1, -1};
int cur;
if (!file) {
return APR_EINVAL;
}
- if (!can_create_global) { /* unprivileged process */
- try_global_local[0] = 0; /* search local before global */
- try_global_local[1] = 1;
+ if (flags & APR_SHM_NS_LOCAL) {
+ try_global_local[0] = 0; /* only search local */
+ }
+ else if (flags & APR_SHM_NS_GLOBAL) {
+ try_global_local[0] = 1; /* only search global */
+ }
+ else {
+ can_create_global = can_create_global_maps();
+ if (!can_create_global) { /* unprivileged process */
+ try_global_local[0] = 0; /* search local before global */
+ try_global_local[1] = 1;
+ }
+ else {
+ try_global_local[0] = 1; /* search global before local */
+ try_global_local[1] = 0;
+ }
}
for (cur = 0; try_global_local[cur] != -1; cur++) {
@@ -348,6 +380,13 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
return rv;
}
+APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
+ const char *file,
+ apr_pool_t *pool)
+{
+ return apr_shm_attach_ex(m, file, pool, 0);
+}
+
APR_DECLARE(apr_status_t) apr_shm_detach(apr_shm_t *m)
{
apr_status_t rv = shm_cleanup(m);