mod_slotmem_shm.c revision 59d316b83d42d2a07e25c20d8c35a07b369618bd
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Memory handler for a shared memory divided in slot.
* This one uses shared memory.
*
* Shared memory is cleaned-up for each restart, graceful or
* otherwise.
*/
#include "ap_slotmem.h"
#include "httpd.h"
#ifdef AP_NEED_SET_MUTEX_PERMS
#include "unixd.h"
#endif
#include <unistd.h> /* for getpid() */
#endif
#if HAVE_SYS_SEM_H
#if !defined(SHM_R)
#define SHM_R 0400
#endif
#if !defined(SHM_W)
#define SHM_W 0200
#endif
#endif
/* The description of the slots to reuse the slotmem */
typedef struct {
unsigned int num; /* number of mem slots */
#define AP_UNSIGNEDINT_OFFSET (APR_ALIGN_DEFAULT(sizeof(unsigned int)))
struct ap_slotmem_instance_t {
char *name; /* per segment name */
void *shm; /* ptr to memory segment (apr_shm_t *) */
void *base; /* data set start */
char *inuse; /* in-use flag table*/
unsigned int *num_free; /* slot free count for this instance */
void *persist; /* persist dataset start */
};
/*
* Memory layout:
* sharedslotdesc_t | num_free | slots | isuse array |
* ^ ^
* | . base
* . persist (also num_free)
*/
/* global pool and list of slotmem we are handling */
{
#ifdef AP_NEED_SET_MUTEX_PERMS
int shmid;
return errno;
}
return errno;
}
#if MODULE_MAGIC_NUMBER_MAJOR <= 20081212
#define ap_unixd_config unixd_config
#endif
return errno;
}
return APR_SUCCESS;
#else
return APR_ENOTIMPL;
#endif
#else
return APR_ENOTIMPL;
#endif
}
/*
* Persist the slotmem in a file
* slotmem name and file name.
* none : no persistent data
* anonymous : $server_root/logs/anonymous.slotmem
* :rel_name : $server_root/logs/rel_name.slotmem
* abs_name : $abs_name.slotmem
*
*/
{
const char *storename;
const char *fname;
return NULL;
else if (slotmemname[0] == ':') {
const char *tmpname;
}
else {
fname = slotmemname;
}
return storename;
}
{
apr_file_t *fp;
const char *storename;
if (storename) {
if (APR_STATUS_IS_EEXIST(rv)) {
}
if (rv != APR_SUCCESS) {
return;
}
}
}
/* should be apr_status_t really */
{
const char *storename;
apr_file_t *fp;
if (storename) {
pool);
if (rv == APR_SUCCESS) {
}
else {
return;
}
}
}
}
}
{
if (*mem) {
while (next) {
if (AP_SLOTMEM_IS_PERSIST(next)) {
}
}
apr_pool_destroy(p);
} else {
/* If shared mem was never called, then just remove
* the global pool */
}
return APR_SUCCESS;
}
{
unsigned int i;
char *ptr;
char *inuse;
if (!mem) {
return APR_ENOSHMAVAIL;
}
if (!AP_SLOTMEM_IS_PREGRAB(mem) ||
if (retval != APR_SUCCESS)
break;
}
}
return retval;
}
unsigned int item_num,
{
/* void *slotmem = NULL; */
char *ptr;
const char *fname;
return APR_ENOSHMAVAIL;
if (name) {
if (name[0] == ':') {
}
else {
}
/* first try to attach to existing slotmem */
if (next) {
for (;;) {
/* we already have it */
return APR_SUCCESS;
}
break;
}
}
}
}
else {
fname = "anonymous";
}
/* first try to attach to existing shared memory */
}
else {
rv = APR_EINVAL;
}
if (rv == APR_SUCCESS) {
/* check size */
return APR_EINVAL;
}
return APR_EINVAL;
}
ptr += AP_SLOTMEM_OFFSET;
}
else {
}
else {
}
if (rv != APR_SUCCESS) {
return rv;
}
/* Set permissions to shared memory
* so it can be attached by child process
* having different user credentials
*
*/
}
ptr += AP_SLOTMEM_OFFSET;
/*
* TODO: Error check the below... What error makes
* sense if the restore fails? Any?
*/
if (type & AP_SLOTMEM_TYPE_PERSIST) {
}
}
/* For the chained slotmem stuff */
sizeof(ap_slotmem_instance_t));
if (globallistmem == NULL) {
globallistmem = res;
}
else {
}
return APR_SUCCESS;
}
{
/* void *slotmem = NULL; */
char *ptr;
const char *fname;
return APR_ENOSHMAVAIL;
}
if (name) {
if (name[0] == ':') {
}
else {
}
}
else {
return APR_ENOSHMAVAIL;
}
/* first try to attach to existing slotmem */
if (next) {
for (;;) {
/* we already have it */
return APR_SUCCESS;
}
break;
}
}
}
/* first try to attach to existing shared memory */
if (rv != APR_SUCCESS) {
return rv;
}
/* Read the description of the slotmem */
ptr += AP_SLOTMEM_OFFSET;
/* For the chained slotmem stuff */
sizeof(ap_slotmem_instance_t));
if (globallistmem == NULL) {
globallistmem = res;
}
else {
}
return APR_SUCCESS;
}
{
char *ptr;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_ENOSHMAVAIL;
}
if (!ptr) {
return APR_ENOSHMAVAIL;
}
return APR_SUCCESS;
}
{
void *ptr;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_NOTFOUND;
}
if (ret != APR_SUCCESS) {
return ret;
}
*inuse = 1;
return APR_SUCCESS;
}
{
void *ptr;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_NOTFOUND;
}
if (ret != APR_SUCCESS) {
return ret;
}
*inuse=1;
return APR_SUCCESS;
}
{
}
{
if (AP_SLOTMEM_IS_PREGRAB(slot))
else {
unsigned int i, counter=0;
if (!*inuse)
counter++;
}
return counter;
}
}
{
}
{
unsigned int i;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
}
if (!*inuse) {
break;
}
}
return APR_ENOSHMAVAIL;
}
*inuse = 1;
*id = i;
return APR_SUCCESS;
}
unsigned int id)
{
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_NOTFOUND;
}
return APR_SUCCESS;
}
static const ap_slotmem_provider_t storage = {
"sharedmem",
};
/* make the storage usuable from outside */
static const ap_slotmem_provider_t *slotmem_shm_getstorage(void)
{
return (&storage);
}
/* initialise the global pool */
static void slotmem_shm_initgpool(apr_pool_t *p)
{
gpool = p;
}
/* Add the pool_clean routine */
static void slotmem_shm_initialize_cleanup(apr_pool_t *p)
{
}
/*
* Make sure the shared memory is cleaned
*/
server_rec *s)
{
return OK;
}
{
if (rv != APR_SUCCESS) {
"Fatal error: unable to create global pool for shared slotmem");
return rv;
}
return OK;
}
static void ap_slotmem_shm_register_hook(apr_pool_t *p)
{
}
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
NULL, /* command apr_table_t */
ap_slotmem_shm_register_hook /* register hooks */
};