#include "http_log.h"
#include "slotmem.h"
+#include "sharedmem_util.h"
/* make sure the shared memory is cleaned */
static int initialize_cleanup(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
static void ap_sharedmem_register_hook(apr_pool_t *p)
{
- slotmem_storage_method *storage = sharedmem_getstorage();
+ const slotmem_storage_method *storage = sharedmem_getstorage();
ap_register_provider(p, SLOTMEM_STORAGE, "shared", "0", storage);
ap_hook_post_config(initialize_cleanup, NULL, NULL, APR_HOOK_LAST);
ap_hook_pre_config(pre_config, NULL, NULL, APR_HOOK_MIDDLE);
#define CORE_PRIVATE
#include "apr.h"
+#include "apr_strings.h"
#include "apr_pools.h"
#include "apr_shm.h"
#include "http_config.h"
#include "http_log.h"
-#include "slotmem.h"
+#include "slotmem.h"
+#include "sharedmem_util.h"
/* The description of the slots to reuse the slotmem */
struct sharedslotdesc {
};
/* make the storage usuable from outside */
-slotmem_storage_method *sharedmem_getstorage()
+const slotmem_storage_method *sharedmem_getstorage()
{
return(&storage);
}
--- /dev/null
+/* 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+const slotmem_storage_method *sharedmem_getstorage();
return sizeof(struct proxy_worker_conf);
}
/* copy the worker information in the shared area so the health-checker can extract the part it need */
-static apr_status_t add_entry(proxy_worker *worker, char *balancer_name, int id)
+static apr_status_t add_entry(proxy_worker *worker, const char *balancer_name, int id)
{
struct proxy_worker_conf *workerconf = NULL;
apr_status_t rv;
static apr_status_t get_entry(int id, proxy_worker **worker, char **balancer_name, apr_pool_t *pool)
{
struct proxy_worker_conf *workerconf = NULL;
+ char *ptr;
apr_status_t rv;
if (myscore == NULL)
/* allocate the data */
*worker = apr_pcalloc(pool, sizeof(proxy_worker));
if (workerconf->balancer_name)
- *balancer_name = apr_pcalloc(pool, strlen(workerconf->balancer_name));
+ *balancer_name = apr_pcalloc(pool, strlen(workerconf->balancer_name) + 1);
else
*balancer_name = NULL;
// XXX: what to do (* worker)->s = workerconf;
(* worker)->retry = workerconf->retry;
(* worker)->lbfactor = workerconf->lbfactor;
- if (workerconf->name)
- strcpy((* worker)->name, workerconf->name);
- if (workerconf->scheme)
- strcpy((* worker)->scheme, workerconf->scheme);
- if (workerconf->hostname)
- strcpy((* worker)->hostname, workerconf->hostname);
- if (workerconf->route)
- strcpy((* worker)->route, workerconf->route);
- if (workerconf->redirect)
- strcpy((* worker)->redirect, workerconf->redirect);
+ if (workerconf->name) {
+ ptr = apr_pcalloc(pool, strlen(workerconf->name) + 1);
+ strcpy(ptr, workerconf->name);
+ (* worker)->name = ptr;
+ }
+ if (workerconf->scheme) {
+ ptr = apr_pcalloc(pool, strlen(workerconf->scheme) + 1);
+ strcpy(ptr, workerconf->scheme);
+ (* worker)->scheme = ptr;
+ }
+ if (workerconf->hostname) {
+ ptr = apr_pcalloc(pool, strlen(workerconf->hostname) + 1);
+ strcpy(ptr, workerconf->hostname);
+ (* worker)->hostname = ptr;
+ }
+ if (workerconf->route) {
+ ptr = apr_pcalloc(pool, strlen(workerconf->route) + 1);
+ strcpy(ptr, workerconf->route);
+ (* worker)->route = ptr;
+ }
+ if (workerconf->redirect) {
+ ptr = apr_pcalloc(pool, strlen(workerconf->redirect) + 1);
+ strcpy(ptr, workerconf->redirect);
+ (* worker)->redirect = ptr;
+ }
(* worker)->status = workerconf->status;
(* worker)->port = workerconf->port;
(* worker)->min = workerconf->min;
if (myscore == NULL)
return APR_ENOSHMAVAIL;
- rv = checkstorage->ap_slotmem_mem(myscore, id, workerconf);
+ rv = checkstorage->ap_slotmem_mem(myscore, id, (void **) workerconf);
if (rv != APR_SUCCESS)
return rv;
*balancer_name = (*workerconf)->balancer_name;
if (myscore == NULL)
return APR_ENOSHMAVAIL;
- rv = checkstorage->ap_slotmem_mem(myscore, id, &workerconf);
+ rv = checkstorage->ap_slotmem_mem(myscore, id, (void **) &workerconf);
if (rv != APR_SUCCESS)
return rv;
/* If the error is not initialized to the worker to be removed keep it */
};
/* make the module usuable from outside */
-health_worker_method *health_checker_get_storage()
+const health_worker_method *health_checker_get_storage()
{
return(&worker_storage);
}
/* handle the slotmem storage */
-void health_checker_init_slotmem_storage(slotmem_storage_method * storage)
+void health_checker_init_slotmem_storage(const slotmem_storage_method * storage)
{
checkstorage = storage;
}
-slotmem_storage_method * health_checker_get_slotmem_storage()
+const slotmem_storage_method * health_checker_get_slotmem_storage()
{
return(checkstorage);
}
/* proxy_util.c */
+PROXY_DECLARE(void) proxy_checkstorage_add_entry(proxy_worker *worker, const char *balancer_name);
+PROXY_DECLARE(void) proxy_create_comarea(apr_pool_t *pconf);
+PROXY_DECLARE(void) proxy_lookup_storage_provider();
+
PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r,
apr_bucket_brigade *brigade);
+
/* Scoreboard */
#if MODULE_MAGIC_NUMBER_MAJOR > 20020903
#define PROXY_HAS_SCOREBOARD 1
apr_pool_t *ptemp)
{
slotmem_storage_method *checkstorage;
- health_worker_method *worker_storage = health_checker_get_storage();
+ const health_worker_method *worker_storage = health_checker_get_storage();
ap_slotmem_t *myscore;
checkstorage = ap_lookup_provider(SLOTMEM_STORAGE, "shared", "0");
static void ap_healthstore_register_hook(apr_pool_t *p)
{
- static const char * const aszPre[] = { "mod_proxy.c", NULL };
static const char * const aszPos[] = { "mod_sharedmem.c", NULL };
- health_worker_method *worker_storage = health_checker_get_storage();
+ const health_worker_method *worker_storage = health_checker_get_storage();
ap_register_provider(p, PROXY_CKMETHOD, "default", "0", worker_storage);
ap_hook_pre_config(healthck_pre_config, NULL, aszPos, APR_HOOK_MIDDLE);
- /* XXX: Too late....
- ap_hook_post_config(healthck_post_config, aszPre, NULL, APR_HOOK_MIDDLE);
- */
}
module AP_MODULE_DECLARE_DATA proxy_health_checker_module = {
/* allow health check method on workers in a non httpd process */
struct health_worker_method {
/* read the size of the entry: to create the shared area */
- int (* getentrysize)();
+ int (* getentrysize)(void);
/* copy the worker information in the shared area so the health-checker can extract the part it need */
- apr_status_t (*add_entry)(proxy_worker *worker, char *balancer_name, int id);
+ apr_status_t (*add_entry)(proxy_worker *worker, const char *balancer_name, int id);
/* XXX : Remove the entry */
apr_status_t (*del_entry)(int id);
/* read the health of the entry: for httpd */
/* set the health of the entry: for the health-checker */
apr_status_t (*set_health)(int id, int value);
/* read the entry stored in the shared area */
- apr_status_t (*get_entry)(proxy_worker **worker, char **balancer_name, apr_pool_t *pool);
+ apr_status_t (*get_entry)(int id, proxy_worker **worker, char **balancer_name, apr_pool_t *pool);
/* read the conf part. */
apr_status_t (*get_entryconf)(int id, proxy_worker_conf **worker, char **balancer_name, apr_pool_t *pool);
/* check the back-end server health */
apr_time_t time_checked;
};
+/*
+ * Other routines.
+ */
+const health_worker_method *health_checker_get_storage();
+void health_checker_init_slotmem_storage(const slotmem_storage_method * storage);
+void health_checker_init_slotmem(ap_slotmem_t *score);
+const slotmem_storage_method * health_checker_get_slotmem_storage();
}
/* Store the worker information in the comarea */
-PROXY_DECLARE(void) proxy_checkstorage_add_entry(proxy_worker *worker, char *balancer_name)
+PROXY_DECLARE(void) proxy_checkstorage_add_entry(proxy_worker *worker, const char *balancer_name)
{
if (checkstorage) {
checkstorage->add_entry(worker, balancer_name, worker->id);
#include "mod_proxy.h"
#include "ajp.h"
-#include "mod_proxy_health_checker.h"
#include "slotmem.h"
+#include "sharedmem_util.h"
+#include "mod_proxy_health_checker.h"
#if APR_HAVE_UNISTD_H
#include <unistd.h>
static apr_time_t now; /* start time of this processing run */
-extern int AP_DECLARE_DATA ap_default_loglevel = APLOG_ERR;
+extern int AP_DECLARE_DATA ap_default_loglevel;
static apr_file_t *errfile; /* stderr file handle */
static apr_file_t *outfile; /* stdout file handle */
{
apr_size_t size;
apr_status_t rv;
- slotmem_storage_method *checkstorage;
+ const slotmem_storage_method *checkstorage;
ap_slotmem_t *myscore;
sharedmem_initglobalpool(pool);