scoreboard.c revision a72ba68ecbbc61e4b513e50d6000245c33f753dc
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz/* Licensed to the Apache Software Foundation (ASF) under one or more
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz * contributor license agreements. See the NOTICE file distributed with
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * this work for additional information regarding copyright ownership.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * The ASF licenses this file to You under the Apache License, Version 2.0
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * (the "License"); you may not use this file except in compliance with
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * the License. You may obtain a copy of the License at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * http://www.apache.org/licenses/LICENSE-2.0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_strings.h"
785be1b6298010956622771c870ab3cd8ca57a2faaron#include "apr_portable.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_lib.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define APR_WANT_STRFUNC
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "apr_want.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#if APR_HAVE_SYS_TYPES_H
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include <sys/types.h>
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#endif
1b21d7b3d97def358b2e923655edeb16613a1c31gstein
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "ap_config.h"
2d71630471d1c23f0137309e3c3957c633ecbfd6rbb#include "httpd.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_log.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_main.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "ap_mpm.h"
51af95bb51b5084e883bad250b2afa2838e9ceebfielding
d4f1d9c1ff112a8ab9bee31f196973761329b236rbb#include "mpm.h"
7fae9cc4639013f3c04c085547256c68814aee8ftrawick#include "scoreboard.h"
7fae9cc4639013f3c04c085547256c68814aee8ftrawick
7fae9cc4639013f3c04c085547256c68814aee8ftrawickAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
7fae9cc4639013f3c04c085547256c68814aee8ftrawickAP_DECLARE_DATA const char *ap_scoreboard_fname = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE_DATA int ap_extended_status = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#if APR_HAS_SHARED_MEMORY
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_shm.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifndef WIN32
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic /* but must be exported to mpm_winnt */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_shm_t *ap_scoreboard_shm = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
785be1b6298010956622771c870ab3cd8ca57a2faaron#endif
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronAPR_HOOK_STRUCT(
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding APR_HOOK_LINK(pre_mpm)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_IMPLEMENT_HOOK_RUN_ALL(int,pre_mpm,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (apr_pool_t *p, ap_scoreboard_e sb_type),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (p, sb_type),OK,DECLINED)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic APR_OPTIONAL_FN_TYPE(ap_proxy_lb_workers)
785be1b6298010956622771c870ab3cd8ca57a2faaron *pfn_proxy_lb_workers;
785be1b6298010956622771c870ab3cd8ca57a2faaronstatic APR_OPTIONAL_FN_TYPE(ap_proxy_lb_worker_size)
785be1b6298010956622771c870ab3cd8ca57a2faaron *pfn_proxy_lb_worker_size;
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronstruct ap_sb_handle_t {
785be1b6298010956622771c870ab3cd8ca57a2faaron int child_num;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int thread_num;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
f4b96a996afbc46872f57ad1450e6ee1c8f13707jorton
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int server_limit, thread_limit, lb_limit, lb_size;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic apr_size_t scoreboard_size;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ToDo:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * This function should be renamed to cleanup_shared
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * and it should handle cleaning up a scoreboard shared
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * between processes using any form of IPC (file, shared memory
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * segment, etc.). Leave it as is now because it is being used
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * by various MPMs.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic apr_status_t ap_cleanup_shared_mem(void *d)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#if APR_HAS_SHARED_MEMORY
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding free(ap_scoreboard_image);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_shm_destroy(ap_scoreboard_shm);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return APR_SUCCESS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE(int) ap_calc_scoreboard_size(void)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!pfn_proxy_lb_workers)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pfn_proxy_lb_workers = APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_workers);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (pfn_proxy_lb_workers)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding lb_limit = pfn_proxy_lb_workers();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding lb_limit = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!pfn_proxy_lb_worker_size)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pfn_proxy_lb_worker_size = APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_worker_size);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (pfn_proxy_lb_worker_size)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding lb_size = pfn_proxy_lb_worker_size();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding lb_size = sizeof(lb_score);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding scoreboard_size = sizeof(global_score);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding scoreboard_size += sizeof(process_score) * server_limit;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding scoreboard_size += sizeof(worker_score) * server_limit * thread_limit;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (lb_limit && lb_size)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding scoreboard_size += lb_size * lb_limit;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return scoreboard_size;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
45acd673a68181802b112e97e84fa3813ddd3ec1stoddardvoid ap_init_scoreboard(void *shared_score)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *more_storage;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_calc_scoreboard_size();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding more_storage = shared_score;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image->global = (global_score *)more_storage;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding more_storage += sizeof(global_score);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image->parent = (process_score *)more_storage;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding more_storage += sizeof(process_score) * server_limit;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image->servers =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (worker_score **)((char*)ap_scoreboard_image + sizeof(scoreboard));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < server_limit; i++) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_scoreboard_image->servers[i] = (worker_score *)more_storage;
785be1b6298010956622771c870ab3cd8ca57a2faaron more_storage += thread_limit * sizeof(worker_score);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (lb_limit && lb_size) {
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick ap_scoreboard_image->balancers = (void *)more_storage;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding more_storage += lb_limit * lb_size;
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick }
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick ap_assert(more_storage == (char*)shared_score + scoreboard_size);
58fd79b56eb624bf011772994e9761d3c2e228c1orlikowski ap_scoreboard_image->global->server_limit = server_limit;
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick ap_scoreboard_image->global->thread_limit = thread_limit;
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick ap_scoreboard_image->global->lb_limit = lb_limit;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick
785be1b6298010956622771c870ab3cd8ca57a2faaron/**
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Create a name-based scoreboard in the given pool using the
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick * given filename.
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick */
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregamesstatic apr_status_t create_namebased_scoreboard(apr_pool_t *pool,
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames const char *fname)
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames{
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames#if APR_HAS_SHARED_MEMORY
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames apr_status_t rv;
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames /* The shared memory file must not exist before we create the
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames * segment. */
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames apr_shm_remove(fname, pool); /* ignore errors */
e160b861b50a3a8dcc013b8cd3ef849fe777e52fgregames
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, pool);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick if (rv != APR_SUCCESS) {
560f6ac786d611b858b2bad932713d9e971f0716trawick ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
560f6ac786d611b858b2bad932713d9e971f0716trawick "unable to create or access scoreboard \"%s\" "
560f6ac786d611b858b2bad932713d9e971f0716trawick "(name-based shared memory failure)", fname);
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick return rv;
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick }
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick#endif /* APR_HAS_SHARED_MEMORY */
7bf77d70b6830636bc36e6b76a228c301be23ff7brianp return APR_SUCCESS;
7bf77d70b6830636bc36e6b76a228c301be23ff7brianp}
7bf77d70b6830636bc36e6b76a228c301be23ff7brianp
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick/* ToDo: This function should be made to handle setting up
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick * a scoreboard shared between processes using any IPC technique,
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick * not just a shared memory segment
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick */
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawickstatic apr_status_t open_scoreboard(apr_pool_t *pconf)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#if APR_HAS_SHARED_MEMORY
eae32ab3fb398ca408bc2d45b22adf1b67a75471rbb apr_status_t rv;
39b76a07959a0a332366c735a23894d9e8ed6872trawick char *fname = NULL;
39b76a07959a0a332366c735a23894d9e8ed6872trawick apr_pool_t *global_pool;
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron /* We don't want to have to recreate the scoreboard after
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick * restarts, so we'll create a global pool and never clean it.
39b76a07959a0a332366c735a23894d9e8ed6872trawick */
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick rv = apr_pool_create(&global_pool, NULL);
785be1b6298010956622771c870ab3cd8ca57a2faaron if (rv != APR_SUCCESS) {
785be1b6298010956622771c870ab3cd8ca57a2faaron ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
066877f1a045103acfdd376d48cdd473c33f409bdougm "Fatal error: unable to create global pool "
8a261a9f7d18d1e862d63f68e93f288d3e1f0d94trawick "for use by the scoreboard");
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick return rv;
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick }
74b39333600dee3260355ad3a06e36ef6c61c8f1dreid
74b39333600dee3260355ad3a06e36ef6c61c8f1dreid /* The config says to create a name-based shmem */
74b39333600dee3260355ad3a06e36ef6c61c8f1dreid if (ap_scoreboard_fname) {
74b39333600dee3260355ad3a06e36ef6c61c8f1dreid /* make sure it's an absolute pathname */
97c78987224dcd037076d393aad1867c26b2c8cftrawick fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
97c78987224dcd037076d393aad1867c26b2c8cftrawick if (!fname) {
97c78987224dcd037076d393aad1867c26b2c8cftrawick ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EBADPATH, NULL,
97c78987224dcd037076d393aad1867c26b2c8cftrawick "Fatal error: Invalid Scoreboard path %s",
97c78987224dcd037076d393aad1867c26b2c8cftrawick ap_scoreboard_fname);
97c78987224dcd037076d393aad1867c26b2c8cftrawick return APR_EBADPATH;
97c78987224dcd037076d393aad1867c26b2c8cftrawick }
97c78987224dcd037076d393aad1867c26b2c8cftrawick return create_namebased_scoreboard(global_pool, fname);
97c78987224dcd037076d393aad1867c26b2c8cftrawick }
97c78987224dcd037076d393aad1867c26b2c8cftrawick else { /* config didn't specify, we get to choose shmem type */
97c78987224dcd037076d393aad1867c26b2c8cftrawick rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, NULL,
97c78987224dcd037076d393aad1867c26b2c8cftrawick global_pool); /* anonymous shared memory */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "Unable to create or access scoreboard "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "(anonymous shared memory failure)");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return rv;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron /* Make up a filename and do name-based shmem */
785be1b6298010956622771c870ab3cd8ca57a2faaron else if (rv == APR_ENOTIMPL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Make sure it's an absolute pathname */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_fname = DEFAULT_SCOREBOARD;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return create_namebased_scoreboard(global_pool, fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
785be1b6298010956622771c870ab3cd8ca57a2faaron#endif /* APR_HAS_SHARED_MEMORY */
785be1b6298010956622771c870ab3cd8ca57a2faaron return APR_SUCCESS;
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron/* If detach is non-zero, this is a seperate child process,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * if zero, it is a forked child.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingapr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
785be1b6298010956622771c870ab3cd8ca57a2faaron#if APR_HAS_SHARED_MEMORY
785be1b6298010956622771c870ab3cd8ca57a2faaron if (!detached) {
785be1b6298010956622771c870ab3cd8ca57a2faaron return APR_SUCCESS;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (apr_shm_size_get(ap_scoreboard_shm) < scoreboard_size) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "Fatal error: shared scoreboard too small for child!");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_shm_detach(ap_scoreboard_shm);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_shm = NULL;
785be1b6298010956622771c870ab3cd8ca57a2faaron return APR_EINVAL;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* everything will be cleared shortly */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (*shm) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *shm = ap_scoreboard_shm;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return APR_SUCCESS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
f4b96a996afbc46872f57ad1450e6ee1c8f13707jorton
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingapr_status_t ap_cleanup_scoreboard(void *d)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ap_scoreboard_image == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return APR_SUCCESS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ap_scoreboard_image->global->sb_type == SB_SHARED) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_cleanup_shared_mem(NULL);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding free(ap_scoreboard_image->global);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding free(ap_scoreboard_image);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return APR_SUCCESS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Create or reinit an existing scoreboard. The MPM can control whether
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the scoreboard is shared across multiple processes or not
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingint ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
785be1b6298010956622771c870ab3cd8ca57a2faaron int running_gen = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron int i;
785be1b6298010956622771c870ab3cd8ca57a2faaron#if APR_HAS_SHARED_MEMORY
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_status_t rv;
785be1b6298010956622771c870ab3cd8ca57a2faaron#endif
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron if (ap_scoreboard_image) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding running_gen = ap_scoreboard_image->global->running_generation;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image->global->restart_time = apr_time_now();
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm memset(ap_scoreboard_image->parent, 0,
785be1b6298010956622771c870ab3cd8ca57a2faaron sizeof(process_score) * server_limit);
785be1b6298010956622771c870ab3cd8ca57a2faaron for (i = 0; i < server_limit; i++) {
785be1b6298010956622771c870ab3cd8ca57a2faaron memset(ap_scoreboard_image->servers[i], 0,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sizeof(worker_score) * thread_limit);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
785be1b6298010956622771c870ab3cd8ca57a2faaron /* Clean up the lb workers data */
785be1b6298010956622771c870ab3cd8ca57a2faaron if (lb_limit && lb_size) {
785be1b6298010956622771c870ab3cd8ca57a2faaron memset(ap_scoreboard_image->balancers, 0,
785be1b6298010956622771c870ab3cd8ca57a2faaron lb_size * lb_limit);
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron return OK;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_calc_scoreboard_size();
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#if APR_HAS_SHARED_MEMORY
785be1b6298010956622771c870ab3cd8ca57a2faaron if (sb_type == SB_SHARED) {
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick void *sb_shared;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rv = open_scoreboard(p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return HTTP_INTERNAL_SERVER_ERROR;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding memset(sb_shared, 0, scoreboard_size);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_init_scoreboard(sb_shared);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* A simple malloc will suffice */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding void *sb_mem = calloc(1, scoreboard_size);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (sb_mem == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL,
a7ed9c525f9460187f327cea953bf90ecf1bdc51gstein "(%d)%s: cannot allocate scoreboard",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding errno, strerror(errno));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return HTTP_INTERNAL_SERVER_ERROR;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_init_scoreboard(sb_mem);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
a7ed9c525f9460187f327cea953bf90ecf1bdc51gstein
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick ap_scoreboard_image->global->sb_type = sb_type;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick ap_scoreboard_image->global->running_generation = running_gen;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image->global->restart_time = apr_time_now();
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick return OK;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick}
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick/* Routines called to deal with the scoreboard image
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * --- note that we do *not* need write locks, since update_child_status
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * only updates a *single* record in place, and only one process writes to
785be1b6298010956622771c870ab3cd8ca57a2faaron * a given scoreboard slot at a time (either the child process owning that
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * slot, or the parent, noting that the child has died).
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * As a final note --- setting the score entry to getpid() is always safe,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * since when the parent is writing an entry, it's only noting SERVER_DEAD
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * anyway.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE(int) ap_exists_scoreboard_image(void)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (ap_scoreboard_image ? 1 : 0);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
785be1b6298010956622771c870ab3cd8ca57a2faaronAP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sb, request_rec *r)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding worker_score *ws;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ws = &ap_scoreboard_image->servers[sb->child_num][sb->thread_num];
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef HAVE_TIMES
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding times(&ws->times);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ws->access_count++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ws->my_access_count++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ws->conn_count++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ws->bytes_served += r->bytes_sent;
a7ed9c525f9460187f327cea953bf90ecf1bdc51gstein ws->my_bytes_served += r->bytes_sent;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ws->conn_bytes += r->bytes_sent;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingint find_child_by_pid(apr_proc_t *pid)
f4b96a996afbc46872f57ad1450e6ee1c8f13707jorton{
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int max_daemons_limit;
785be1b6298010956622771c870ab3cd8ca57a2faaron
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick
39b76a07959a0a332366c735a23894d9e8ed6872trawick for (i = 0; i < max_daemons_limit; ++i) {
8fd7c5046d164fb0959222497e5925dfc6a52ff3trawick if (ap_scoreboard_image->parent[i].pid == pid->pid) {
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick return i;
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
17f3ba69f65182426ad4e568bb2d6f192ccd2ed5trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return -1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8f8ec0957334f50b7ac11359f90490ee467258eedreidAP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int child_num, int thread_num)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *new_sbh = (ap_sb_handle_t *)apr_palloc(p, sizeof(ap_sb_handle_t));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (*new_sbh)->child_num = child_num;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (*new_sbh)->thread_num = thread_num;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE(int) ap_update_child_status_from_indexes(int child_num,
785be1b6298010956622771c870ab3cd8ca57a2faaron int thread_num,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int status,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int old_status;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding worker_score *ws;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf process_score *ps;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (child_num < 0) {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return -1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ws = &ap_scoreboard_image->servers[child_num][thread_num];
39b76a07959a0a332366c735a23894d9e8ed6872trawick old_status = ws->status;
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick ws->status = status;
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron ps = &ap_scoreboard_image->parent[child_num];
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf
39b76a07959a0a332366c735a23894d9e8ed6872trawick if (status == SERVER_READY
6b38fca3ec543a0f72efd5683e91a0b30fc752d1trawick && old_status == SERVER_STARTING) {
785be1b6298010956622771c870ab3cd8ca57a2faaron ws->thread_num = child_num * thread_limit + thread_num;
785be1b6298010956622771c870ab3cd8ca57a2faaron ps->generation = ap_my_generation;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf
785be1b6298010956622771c870ab3cd8ca57a2faaron if (ap_extended_status) {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf ws->last_used = apr_time_now();
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf if (status == SERVER_READY || status == SERVER_DEAD) {
785be1b6298010956622771c870ab3cd8ca57a2faaron /*
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf * Reset individual counters
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf */
785be1b6298010956622771c870ab3cd8ca57a2faaron if (status == SERVER_DEAD) {
785be1b6298010956622771c870ab3cd8ca57a2faaron ws->my_access_count = 0L;
785be1b6298010956622771c870ab3cd8ca57a2faaron ws->my_bytes_served = 0L;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf ws->conn_count = 0;
066877f1a045103acfdd376d48cdd473c33f409bdougm ws->conn_bytes = 0;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron if (r) {
785be1b6298010956622771c870ab3cd8ca57a2faaron conn_rec *c = r->connection;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf apr_cpystrn(ws->client, ap_get_remote_host(c, r->per_dir_config,
785be1b6298010956622771c870ab3cd8ca57a2faaron REMOTE_NOLOOKUP, NULL), sizeof(ws->client));
785be1b6298010956622771c870ab3cd8ca57a2faaron if (r->the_request == NULL) {
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_cpystrn(ws->request, "NULL", sizeof(ws->request));
785be1b6298010956622771c870ab3cd8ca57a2faaron } else if (r->parsed_uri.password == NULL) {
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_cpystrn(ws->request, r->the_request, sizeof(ws->request));
785be1b6298010956622771c870ab3cd8ca57a2faaron } else {
785be1b6298010956622771c870ab3cd8ca57a2faaron /* Don't reveal the password in the server-status view */
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_cpystrn(ws->request, apr_pstrcat(r->pool, r->method, " ",
785be1b6298010956622771c870ab3cd8ca57a2faaron apr_uri_unparse(r->pool, &r->parsed_uri,
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf APR_URI_UNP_OMITPASSWORD),
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf r->assbackwards ? NULL : " ", r->protocol, NULL),
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf sizeof(ws->request));
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf apr_cpystrn(ws->vhost, r->server->server_hostname,
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf sizeof(ws->vhost));
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
066877f1a045103acfdd376d48cdd473c33f409bdougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return old_status;
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronAP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
785be1b6298010956622771c870ab3cd8ca57a2faaron return ap_update_child_status_from_indexes(sbh->child_num, sbh->thread_num,
785be1b6298010956622771c870ab3cd8ca57a2faaron status, r);
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanfvoid ap_time_process_request(ap_sb_handle_t *sbh, int status)
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf{
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf worker_score *ws;
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf if (sbh->child_num < 0) {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return;
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaron ws = &ap_scoreboard_image->servers[sbh->child_num][sbh->thread_num];
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf if (status == START_PREQUEST) {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf ws->start_time = apr_time_now();
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf else if (status == STOP_PREQUEST) {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf ws->stop_time = apr_time_now();
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronAP_DECLARE(worker_score *) ap_get_scoreboard_worker_from_indexes(int x, int y)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
785be1b6298010956622771c870ab3cd8ca57a2faaron if (((x < 0) || (x > server_limit)) ||
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick ((y < 0) || (y > thread_limit))) {
785be1b6298010956622771c870ab3cd8ca57a2faaron return(NULL); /* Out of range */
785be1b6298010956622771c870ab3cd8ca57a2faaron }
785be1b6298010956622771c870ab3cd8ca57a2faaron return &ap_scoreboard_image->servers[x][y];
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronAP_DECLARE(worker_score *) ap_get_scoreboard_worker(ap_sb_handle_t *sbh)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return ap_get_scoreboard_worker_from_indexes(sbh->child_num,
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf sbh->thread_num);
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanfAP_DECLARE(process_score *) ap_get_scoreboard_process(int x)
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf{
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf if ((x < 0) || (x >= server_limit)) {
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return(NULL); /* Out of range */
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf }
b88f887ed5554d9050d97f9a56a89ae62bdbd906fanf return &ap_scoreboard_image->parent[x];
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronAP_DECLARE(global_score *) ap_get_scoreboard_global()
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick{
785be1b6298010956622771c870ab3cd8ca57a2faaron return ap_scoreboard_image->global;
785be1b6298010956622771c870ab3cd8ca57a2faaron}
785be1b6298010956622771c870ab3cd8ca57a2faaron
785be1b6298010956622771c870ab3cd8ca57a2faaronAP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num)
785be1b6298010956622771c870ab3cd8ca57a2faaron{
785be1b6298010956622771c870ab3cd8ca57a2faaron if ( (lb_num < 0) || (lb_limit < lb_num) || (lb_size==0) ) {
785be1b6298010956622771c870ab3cd8ca57a2faaron return(NULL); /* Out of range */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (lb_score *) ( ((char *) ap_scoreboard_image->balancers) +
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (lb_num*lb_size) );
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
ebc18d48bea83ee5ed7a1b4e30007e5192539829wrowe