mod_slotmem_shm.c revision c3e233736c4a453cbb2166a041f779e86230630a
/* 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.
*/
#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 */
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*/
};
/*
* Memory layout:
* sharedslotdesc_t | slots | isuse array
*/
/* 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
}
/*
* Persiste the slotmem in a file
* slotmem name and file name.
* anonymous : $server_root/logs/anonymous.slotmem
* abs_name : $abs_name.slotmem
*
*/
{
const char *storename;
const char *fname;
else if (slotmemname[0] == ':') {
const char *tmpname;
}
else {
fname = slotmemname;
}
return storename;
}
{
apr_file_t *fp;
const char *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;
pool);
if (rv == APR_SUCCESS) {
}
else {
return;
}
}
}
}
{
if (*mem) {
while (next) {
}
}
return APR_SUCCESS;
}
{
unsigned int i;
void *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; */
void *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;
}
}
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
*
*/
}
/*
* 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; */
void *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 */
/* For the chained slotmem stuff */
sizeof(ap_slotmem_instance_t));
if (globallistmem == NULL) {
globallistmem = res;
}
else {
}
return APR_SUCCESS;
}
{
void *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;
}
return APR_SUCCESS;
}
{
void *ptr;
char *inuse;
if (!slot) {
return APR_ENOSHMAVAIL;
}
return APR_NOTFOUND;
}
if (ret != APR_SUCCESS) {
return ret;
}
return APR_SUCCESS;
}
{
}
{
}
/*
* XXXX: if !AP_SLOTMEM_IS_PREGRAB, then still worry about
* inuse for grab and return?
*/
{
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)
{
void *data;
const char *userdata_key = "slotmem_shm_post_config";
if (!data) {
return OK;
}
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 */
};