mod_sharedmem.c revision f47619526e37e2005a4be21700a3d615fb1d58c9
/* 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
struct ap_slotmem_t {
char *name; /* per segment name */
void *shm; /* ptr to memory segment (apr_shm_t *) */
void *base; /* data set start */
unsigned int num; /* number of mem slots */
};
/* The description of the slots to reuse the slotmem */
struct sharedslotdesc {
unsigned int item_num;
};
/* global pool and list of slotmem we are handling */
static apr_global_mutex_t *smutex;
static const char *mutex_fname;
{
#ifdef AP_NEED_SET_MUTEX_PERMS
int shmid;
return errno;
}
return errno;
}
#if MODULE_MAGIC_NUMBER_MAJOR > 20081212
#else
#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;
rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT, slotmem->gpool);
if (APR_STATUS_IS_EEXIST(rv)) {
rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT, slotmem->gpool);
}
if (rv != APR_SUCCESS) {
return;
}
}
static void restore_slotmem(void *ptr, const char *name, apr_size_t item_size, unsigned int item_num, apr_pool_t *pool)
{
const char *storename;
apr_file_t *fp;
if (rv == APR_SUCCESS) {
}
else {
return;
}
}
}
}
{
if (*mem) {
while (next) {
}
}
return APR_SUCCESS;
}
static apr_status_t slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool)
{
unsigned int i;
void *ptr;
if (!mem) {
return APR_ENOSHMAVAIL;
}
}
return APR_SUCCESS;
}
static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size, unsigned int item_num, int type, apr_pool_t *pool)
{
/* void *slotmem = NULL; */
void *ptr;
struct sharedslotdesc desc;
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
*/
}
if (type & CREPER_SLOTMEM)
}
/* For the chained slotmem stuff */
if (globallistmem == NULL) {
globallistmem = res;
}
else {
}
return APR_SUCCESS;
}
static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool)
{
/* void *slotmem = NULL; */
void *ptr;
struct sharedslotdesc desc;
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 */
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;
}
/* XXX: Those 2 should be removed */
{
}
{
}
static apr_status_t slotmem_get(ap_slotmem_t *slot, unsigned int id, unsigned char *dest, apr_size_t dest_len)
{
void *ptr;
if (ret != APR_SUCCESS) {
return ret;
}
return APR_SUCCESS;
}
static apr_status_t slotmem_put(ap_slotmem_t *slot, unsigned int id, unsigned char *src, apr_size_t src_len)
{
void *ptr;
if (ret != APR_SUCCESS) {
return ret;
}
return APR_SUCCESS;
}
static const ap_slotmem_storage_method storage = {
"sharedmem",
};
/* make the storage usuable from outside */
static const ap_slotmem_storage_method *sharedmem_getstorage(void)
{
return (&storage);
}
/* initialise the global pool */
static void sharedmem_initgpool(apr_pool_t *p)
{
gpool = p;
}
/* Add the pool_clean routine */
static void sharedmem_initialize_cleanup(apr_pool_t *p)
{
}
/*
* Create the shared mem mutex and
* make sure the shared memory is cleaned
*/
{
const char *temp_dir;
char *template;
void *data;
const char *userdata_key = "sharedmem_post_config";
if (!data) {
return OK;
}
if (rv != APR_SUCCESS) {
"sharedmem: search for temporary directory failed");
return rv;
}
APR_FILEPATH_NATIVE, p);
if (rv != APR_SUCCESS) {
"sharedmem: creation of mutex file in directory %s failed",
temp_dir);
return rv;
}
if (rv != APR_SUCCESS) {
"sharedmem: unable to get mutex fname");
return rv;
}
if (rv != APR_SUCCESS) {
"sharedmem: could not close mutex file");
return rv;
}
mutex_fname, APR_LOCK_DEFAULT, p);
if (rv != APR_SUCCESS) {
"sharedmem: creation of mutex failed");
return rv;
}
#ifdef AP_NEED_SET_MUTEX_PERMS
if (rv != APR_SUCCESS) {
"sharedmem: failed to set mutex permissions");
return rv;
}
#endif
return OK;
}
{
if (rv != APR_SUCCESS) {
"Fatal error: unable to create global pool for shared slotmem");
return rv;
}
return OK;
}
{
mutex_fname, p);
if (rv != APR_SUCCESS) {
"Failed to initialise global mutex %s in child process %"
APR_PID_T_FMT ".",
mutex_fname, getpid());
}
}
static void ap_sharedmem_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_sharedmem_register_hook /* register hooks */
};