scoreboard.c revision 299ab6917ab56d6e8ec61b2e5513b968ae18c998
6bdda696b3ea703c47e87fea61017ec655f91d92nd/* Licensed to the Apache Software Foundation (ASF) under one or more
6bdda696b3ea703c47e87fea61017ec655f91d92nd * contributor license agreements. See the NOTICE file distributed with
6bdda696b3ea703c47e87fea61017ec655f91d92nd * this work for additional information regarding copyright ownership.
6bdda696b3ea703c47e87fea61017ec655f91d92nd * The ASF licenses this file to You under the Apache License, Version 2.0
6bdda696b3ea703c47e87fea61017ec655f91d92nd * (the "License"); you may not use this file except in compliance with
6bdda696b3ea703c47e87fea61017ec655f91d92nd * the License. You may obtain a copy of the License at
6bdda696b3ea703c47e87fea61017ec655f91d92nd * Unless required by applicable law or agreed to in writing, software
0662ed52e814f8f08ef0e09956413a792584eddffuankg * distributed under the License is distributed on an "AS IS" BASIS,
6bdda696b3ea703c47e87fea61017ec655f91d92nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6bdda696b3ea703c47e87fea61017ec655f91d92nd * See the License for the specific language governing permissions and
6bdda696b3ea703c47e87fea61017ec655f91d92nd * limitations under the License.
6bdda696b3ea703c47e87fea61017ec655f91d92ndstatic /* but must be exported to mpm_winnt */
6bdda696b3ea703c47e87fea61017ec655f91d92nd * This function should be renamed to cleanup_shared
6bdda696b3ea703c47e87fea61017ec655f91d92nd * and it should handle cleaning up a scoreboard shared
6bdda696b3ea703c47e87fea61017ec655f91d92nd * between processes using any form of IPC (file, shared memory
6bdda696b3ea703c47e87fea61017ec655f91d92nd * segment, etc.). Leave it as is now because it is being used
6bdda696b3ea703c47e87fea61017ec655f91d92nd * by various MPMs.
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
6bdda696b3ea703c47e87fea61017ec655f91d92nd pfn_proxy_lb_workers = APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_workers);
6bdda696b3ea703c47e87fea61017ec655f91d92nd pfn_proxy_lb_worker_size = APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_worker_size);
6bdda696b3ea703c47e87fea61017ec655f91d92nd scoreboard_size += sizeof(worker_score) * server_limit * thread_limit;
6bdda696b3ea703c47e87fea61017ec655f91d92nd calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *));
6bdda696b3ea703c47e87fea61017ec655f91d92nd ap_scoreboard_image->global = (global_score *)more_storage;
6bdda696b3ea703c47e87fea61017ec655f91d92nd ap_scoreboard_image->parent = (process_score *)more_storage;
6bdda696b3ea703c47e87fea61017ec655f91d92nd (worker_score **)((char*)ap_scoreboard_image + sizeof(scoreboard));
6bdda696b3ea703c47e87fea61017ec655f91d92nd for (i = 0; i < server_limit; i++) {
0662ed52e814f8f08ef0e09956413a792584eddffuankg ap_scoreboard_image->servers[i] = (worker_score *)more_storage;
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg ap_assert(more_storage == (char*)shared_score + scoreboard_size);
6bdda696b3ea703c47e87fea61017ec655f91d92nd ap_scoreboard_image->global->server_limit = server_limit;
6bdda696b3ea703c47e87fea61017ec655f91d92nd ap_scoreboard_image->global->thread_limit = thread_limit;
6bdda696b3ea703c47e87fea61017ec655f91d92nd * Create a name-based scoreboard in the given pool using the
6bdda696b3ea703c47e87fea61017ec655f91d92nd * given filename.
6bdda696b3ea703c47e87fea61017ec655f91d92ndstatic apr_status_t create_namebased_scoreboard(apr_pool_t *pool,
6bdda696b3ea703c47e87fea61017ec655f91d92nd const char *fname)
6bdda696b3ea703c47e87fea61017ec655f91d92nd /* The shared memory file must not exist before we create the
6bdda696b3ea703c47e87fea61017ec655f91d92nd * segment. */
6bdda696b3ea703c47e87fea61017ec655f91d92nd rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, pool);
6bdda696b3ea703c47e87fea61017ec655f91d92nd "unable to create or access scoreboard \"%s\" "
6bdda696b3ea703c47e87fea61017ec655f91d92nd#endif /* APR_HAS_SHARED_MEMORY */
6bdda696b3ea703c47e87fea61017ec655f91d92nd/* ToDo: This function should be made to handle setting up
6bdda696b3ea703c47e87fea61017ec655f91d92nd * a scoreboard shared between processes using any IPC technique,
6bdda696b3ea703c47e87fea61017ec655f91d92nd * not just a shared memory segment
6bdda696b3ea703c47e87fea61017ec655f91d92nd /* We don't want to have to recreate the scoreboard after
6bdda696b3ea703c47e87fea61017ec655f91d92nd * restarts, so we'll create a global pool and never clean it.
6bdda696b3ea703c47e87fea61017ec655f91d92nd "Fatal error: unable to create global pool "
6bdda696b3ea703c47e87fea61017ec655f91d92nd "for use by the scoreboard");
6bdda696b3ea703c47e87fea61017ec655f91d92nd /* The config says to create a name-based shmem */
6bdda696b3ea703c47e87fea61017ec655f91d92nd /* make sure it's an absolute pathname */
6bdda696b3ea703c47e87fea61017ec655f91d92nd fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
8ffac2c334103c0336602aaede650cb578611151fuankg "Fatal error: Invalid Scoreboard path %s",
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg return create_namebased_scoreboard(global_pool, fname);
6bdda696b3ea703c47e87fea61017ec655f91d92nd else { /* config didn't specify, we get to choose shmem type */
6bdda696b3ea703c47e87fea61017ec655f91d92nd rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, NULL,
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg "Unable to create or access scoreboard "
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg "(anonymous shared memory failure)");
6bdda696b3ea703c47e87fea61017ec655f91d92nd /* Make up a filename and do name-based shmem */
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg /* Make sure it's an absolute pathname */
6bdda696b3ea703c47e87fea61017ec655f91d92nd fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
6bdda696b3ea703c47e87fea61017ec655f91d92nd#endif /* APR_HAS_SHARED_MEMORY */
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg/* If detach is non-zero, this is a seperate child process,
0662ed52e814f8f08ef0e09956413a792584eddffuankg * if zero, it is a forked child.
6bdda696b3ea703c47e87fea61017ec655f91d92ndapr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached)
6bdda696b3ea703c47e87fea61017ec655f91d92nd if (apr_shm_size_get(ap_scoreboard_shm) < scoreboard_size) {
6bdda696b3ea703c47e87fea61017ec655f91d92nd "Fatal error: shared scoreboard too small for child!");
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg /* everything will be cleared shortly */
if (*shm) {
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
int running_gen = 0;
if (ap_scoreboard_image) {
for (i = 0; i < server_limit; i++) {
return OK;
void *sb_shared;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
if (!sb)
#ifdef HAVE_TIMES
int max_daemons_limit;
for (i = 0; i < max_daemons_limit; ++i) {
p = r->the_request;
if (!ap_mod_status_reqtail) {
int thread_num,
int status,
conn_rec *c,
request_rec *r)
int old_status;
int mpm_generation;
if (ap_extended_status) {
if (r->server) {
return old_status;
int thread_num,
int status,
request_rec *r)
if (child_num < 0) {
request_rec *r)
if (!sbh)
conn_rec *c)
if (!sbh)
if (!sbh)
if (((x < 0) || (x >= server_limit)) ||
((y < 0) || (y >= thread_limit))) {
if (!sbh)
return NULL;
if ((x < 0) || (x >= server_limit)) {