scoreboard.c revision 666d616b7986a83bb0eac453694fbf4d6f05b98c
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* Copyright 2001-2004 The Apache Software Foundation
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Licensed under the Apache License, Version 2.0 (the "License");
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * you may not use this file except in compliance with the License.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * You may obtain a copy of the License at
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Unless required by applicable law or agreed to in writing, software
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * distributed under the License is distributed on an "AS IS" BASIS,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndstatic /* but must be exported to mpm_winnt */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * This function should be renamed to cleanup_shared
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * and it should handle cleaning up a scoreboard shared
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * between processes using any form of IPC (file, shared memory
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * segment, etc.). Leave it as is now because it is being used
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * by various MPMs.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd proxy_lb_workers = APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_workers);
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd scoreboard_size += sizeof(worker_score) * server_limit * thread_limit;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *) +
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd ap_scoreboard_image->global = (global_score *)more_storage;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd ap_scoreboard_image->parent = (process_score *)more_storage;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd (worker_score **)((char*)ap_scoreboard_image + sizeof(scoreboard));
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd for (i = 0; i < server_limit; i++) {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd ap_scoreboard_image->servers[i] = (worker_score *)more_storage;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd ap_scoreboard_image->balancers = (lb_score *)more_storage;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd ap_assert(more_storage == (char*)shared_score + scoreboard_size);
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd ap_scoreboard_image->global->server_limit = server_limit;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd ap_scoreboard_image->global->thread_limit = thread_limit;
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * Create a name-based scoreboard in the given pool using the
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * given filename.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndstatic apr_status_t create_namebased_scoreboard(apr_pool_t *pool,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd const char *fname)
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* The shared memory file must not exist before we create the
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * segment. */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, pool);
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd "unable to create scoreboard \"%s\" "
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#endif /* APR_HAS_SHARED_MEMORY */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* ToDo: This function should be made to handle setting up
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * a scoreboard shared between processes using any IPC technique,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * not just a shared memory segment
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* We don't want to have to recreate the scoreboard after
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * restarts, so we'll create a global pool and never clean it.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd "Fatal error: unable to create global pool "
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd "for use with by the scoreboard");
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* The config says to create a name-based shmem */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* make sure it's an absolute pathname */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd "Fatal error: Invalid Scoreboard path %s",
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd else { /* config didn't specify, we get to choose shmem type */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, NULL,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd "Unable to create scoreboard "
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd "(anonymous shared memory failure)");
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Make up a filename and do name-based shmem */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* Make sure it's an absolute pathname */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd#endif /* APR_HAS_SHARED_MEMORY */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* If detach is non-zero, this is a seperate child process,
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd * if zero, it is a forked child.
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndapr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached)
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd if (apr_shm_size_get(ap_scoreboard_shm) < scoreboard_size) {
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd "Fatal error: shared scoreboard too small for child!");
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd /* everything will be cleared shortly */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd/* Create or reinit an existing scoreboard. The MPM can control whether
9472e4d3c410be3b3f1addbf3b1db1769f64e765nd * the scoreboard is shared across multiple processes or not
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34ndint ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
0d0ba3a410038e179b695446bb149cce6264e0abnd running_gen = ap_scoreboard_image->global->running_generation;
0d0ba3a410038e179b695446bb149cce6264e0abnd ap_scoreboard_image->global->restart_time = apr_time_now();
0d0ba3a410038e179b695446bb149cce6264e0abnd for (i = 0; i < server_limit; i++) {
0d0ba3a410038e179b695446bb149cce6264e0abnd /* Clean up the lb workers data */
97a3ecc40b65d5f8e865bbe0b1c9325d8c016e34nd if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
#ifdef HAVE_TIMES
int max_daemons_limit;
for (i = 0; i < max_daemons_limit; ++i) {
int thread_num,
int status,
request_rec *r)
int old_status;
if (child_num < 0) {
if (ap_extended_status) {
return old_status;
request_rec *r)
status, r);
if (child_num < 0) {
if (((x < 0) || (server_limit < x)) ||
((y < 0) || (thread_limit < y))) {
if ((x < 0) || (server_limit < x)) {