mod_slotmem_shm.c revision 50abd937b8eaac9389cdf31a29319c86ef59a3b6
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* Licensed to the Apache Software Foundation (ASF) under one or more
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * contributor license agreements. See the NOTICE file distributed with
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * this work for additional information regarding copyright ownership.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * The ASF licenses this file to You under the Apache License, Version 2.0
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * (the "License"); you may not use this file except in compliance with
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * the License. You may obtain a copy of the License at
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * Unless required by applicable law or agreed to in writing, software
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * distributed under the License is distributed on an "AS IS" BASIS,
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen/* Memory handler for a shared memory divided in slot.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * This one uses shared memory.
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#if !defined(SHM_R)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#if !defined(SHM_W)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end struct ap_slotmem_instance_t *next; /* location of next allocated segment */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* The description of the slots to reuse the slotmem */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end unsigned int item_num;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * Memory layout:
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * sharedslotdesc | slots | isuse array
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end/* global pool and list of slotmem we are handling */
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endstatic struct ap_slotmem_instance_t *globallistmem = NULL;
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define SLOTMEM_LOCK(s) do { \
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end} while (0)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end#define SLOTMEM_UNLOCK(s) do { \
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end} while (0)
94cfb5d816f18c39adb74a03b6502ab73e35a73bnilgunstatic apr_status_t unixd_set_shm_perms(const char *fname)
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd * Persiste the slotmem in a file
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd * slotmem name and file name.
* abs_name : $abs_name.slotmem
const char *storename;
const char *fname;
const char *tmpname;
return storename;
const char *storename;
rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT, slotmem->gpool);
rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT, slotmem->gpool);
const char *storename;
if (*mem) {
while (next) {
return APR_SUCCESS;
static apr_status_t slotmem_do(ap_slotmem_instance_t *mem, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool)
void *ptr;
char *inuse;
if (!mem) {
return APR_ENOSHMAVAIL;
if (*inuse) {
return APR_SUCCESS;
static apr_status_t slotmem_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)
void *ptr;
const char *fname;
return APR_ENOSHMAVAIL;
if (name) {
while (next) {
return APR_SUCCESS;
return APR_EINVAL;
return APR_EINVAL;
return rv;
return APR_SUCCESS;
static apr_status_t slotmem_attach(ap_slotmem_instance_t **new, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool)
void *ptr;
const char *fname;
return APR_ENOSHMAVAIL;
if (name) {
return APR_ENOSHMAVAIL;
while (next) {
return APR_SUCCESS;
return rv;
return APR_SUCCESS;
void *ptr;
if (!slot) {
return APR_ENOSHMAVAIL;
return APR_ENOSHMAVAIL;
if (!ptr) {
return APR_ENOSHMAVAIL;
return APR_SUCCESS;
static apr_status_t slotmem_get(ap_slotmem_instance_t *slot, unsigned int id, unsigned char *dest, apr_size_t dest_len)
void *ptr;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
return APR_NOTFOUND;
return ret;
return APR_SUCCESS;
static apr_status_t slotmem_put(ap_slotmem_instance_t *slot, unsigned int id, unsigned char *src, apr_size_t src_len)
void *ptr;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
return APR_NOTFOUND;
return ret;
return APR_SUCCESS;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
if (!*inuse) {
return APR_ENOSHMAVAIL;
*id = i;
return APR_SUCCESS;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
return APR_NOTFOUND;
return APR_SUCCESS;
return (&storage);
gpool = p;
const char *temp_dir;
char *template;
void *data;
if (!data) {
return OK;
return rv;
APR_FILEPATH_NATIVE, p);
temp_dir);
return rv;
return rv;
return rv;
return rv;
#ifdef AP_NEED_SET_MUTEX_PERMS
return rv;
return OK;
return rv;
return OK;
mutex_fname, p);