mod_slotmem_shm.c revision ee64d217c5a5f10d4bd69487cdc5612c0ddd8fd1
/* 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"
#include "http_main.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 */
int fbased; /* filebased? */
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 */
#define DEFAULT_SLOTMEM_PREFIX "slotmem-shm-"
#define DEFAULT_SLOTMEM_SUFFIX ".shm"
{
#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
* rel_name : $server_root/rel_name
* /abs_name : $abs_name
*
*/
{
const char *fname;
return NULL;
}
else if (slotmemname[0] != '/') {
}
else {
fname = slotmemname;
}
return fname;
}
{
}
{
apr_file_t *fp;
const char *storename;
"storing %s", storename);
if (storename) {
if (APR_STATUS_IS_EEXIST(rv)) {
}
if (rv != APR_SUCCESS) {
return;
}
/* XXX: Error handling */
}
}
/* should be apr_status_t really */
{
const char *storename;
apr_file_t *fp;
"restoring %s", storename);
if (storename) {
pool);
if (rv == APR_SUCCESS) {
}
else {
return;
}
}
}
}
}
{
if (*mem) {
while (next) {
if (AP_SLOTMEM_IS_PERSIST(next)) {
}
}
}
}
/* apr_pool_destroy(gpool); */
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; */
int fbased = 1;
char *ptr;
const char *fname;
return APR_ENOSHMAVAIL;
}
if (fname) {
/* first try to attach to existing slotmem */
if (next) {
for (;;) {
/* we already have it */
return APR_SUCCESS;
}
break;
}
}
}
}
else {
fbased = 0;
fname = "none";
}
/* first try to attach to existing shared memory */
item_num);
if (fbased) {
}
else {
rv = APR_EINVAL;
}
if (rv == APR_SUCCESS) {
/* check size */
return APR_EINVAL;
}
return APR_EINVAL;
}
ptr += AP_SLOTMEM_OFFSET;
}
else {
if (fbased) {
}
else {
}
if (rv != APR_SUCCESS) {
return rv;
}
if (fbased) {
/* 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 (!fname) {
return APR_ENOSHMAVAIL;
}
"attach looking for %s", fname);
/* first try to attach to existing slotmem */
if (next) {
for (;;) {
/* we already have it */
APLOGNO(02302)
return APR_SUCCESS;
}
break;
}
}
}
/* next 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 {
}
APLOGNO(02303)
return APR_SUCCESS;
}
{
char *ptr;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_EINVAL;
}
if (!ptr) {
return APR_ENOSHMAVAIL;
}
return APR_SUCCESS;
}
{
void *ptr;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_EINVAL;
}
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_EINVAL;
}
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_EINVAL;
}
*inuse = 1;
*id = i;
return APR_SUCCESS;
}
{
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_EINVAL;
}
if (!*inuse) {
*inuse = 1;
}
return APR_SUCCESS;
}
unsigned int id)
{
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_EINVAL;
} else {
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;
}
{
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 */
};