scoreboard.c revision 65db4f712167a3498de73cee5c08032a8aa6a010
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/* ====================================================================
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * The Apache Software License, Version 1.1
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * reserved.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Redistribution and use in source and binary forms, with or without
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * modification, are permitted provided that the following conditions
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * 1. Redistributions of source code must retain the above copyright
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * notice, this list of conditions and the following disclaimer.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * 2. Redistributions in binary form must reproduce the above copyright
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * notice, this list of conditions and the following disclaimer in
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * the documentation and/or other materials provided with the
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * distribution.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * 3. The end-user documentation included with the redistribution,
447d8ea77d7e9fcc7aa286122668d8fe0f8cc690fuankg * if any, must include the following acknowledgment:
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf * "This product includes software developed by the
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Apache Software Foundation (http://www.apache.org/)."
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Alternately, this acknowledgment may appear in the software itself,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * if and wherever such third-party acknowledgments normally appear.
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf * 4. The names "Apache" and "Apache Software Foundation" must
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf * not be used to endorse or promote products derived from this
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf * software without prior written permission. For written
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf * permission, please contact apache@apache.org.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * 5. Products derived from this software may not be called "Apache",
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * nor may "Apache" appear in their name, without prior written
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * permission of the Apache Software Foundation.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * SUCH DAMAGE.
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * ====================================================================
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * This software consists of voluntary contributions made by many
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * individuals on behalf of the Apache Software Foundation. For more
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * information on the Apache Software Foundation, please see
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Portions of this software are based upon public domain software
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * originally written at the National Center for Supercomputing Applications,
ab364c14d11072380abeab42015e19c3db3336c1sf * University of Illinois, Urbana-Champaign.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrinAP_DECLARE_DATA const char *ap_scoreboard_fname=NULL;
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * This function should be renamed to cleanup_shared
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * and it should handle cleaning up a scoreboard shared
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * between processes using any form of IPC (file, shared memory
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * segment, etc.). Leave it as is now because it is being used
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * by various MPMs.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/* ToDo: This function should be made to handle setting up
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * a scoreboard shared between processes using any IPC technique,
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin * not just a shared memory segment
d05e6175473332a8433e4ac85edda0d5a33c94b5minfrin const char *fname;
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin fname = ap_server_root_relative(p, ap_scoreboard_fname);
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: %s",
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin ap_server_argv0, apr_strerror(rv, errmsg, sizeof errmsg));
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi/* ap_cleanup_scoreboard
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin if (ap_scoreboard_image->global.sb_type == SB_SHARED) {
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/* ap_create_scoreboard(apr_pool_t*, ap_scoreboard_e t)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Create or reinit an existing scoreboard. The MPM can control whether
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * the scoreboard is shared across multiple processes or not
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin running_gen = ap_scoreboard_image->global.running_generation;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* A simple malloc will suffice */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image->global.running_generation = running_gen;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/* Routines called to deal with the scoreboard image
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * --- note that we do *not* need write locks, since update_child_status
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * only updates a *single* record in place, and only one process writes to
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * a given scoreboard slot at a time (either the child process owning that
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * slot, or the parent, noting that the child has died).
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * As a final note --- setting the score entry to getpid() is always safe,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * since when the parent is writing an entry, it's only noting SERVER_DEAD
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinstatic APR_INLINE void put_scoreboard_info(int child_num, int thread_num,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* XXX - needs to be fixed to account for threads */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin lseek(scoreboard_fd, (long) child_num * sizeof(worker_score), 0);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin force_write(scoreboard_fd, new_score_rec, sizeof(worker_score));
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin (char *) &ap_scoreboard_image->global -(char *) ap_scoreboard_image, 0);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin force_write(scoreboard_fd, &ap_scoreboard_image->global,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(void) ap_increment_counts(int child_num, int thread_num, request_rec *r)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws = &ap_scoreboard_image->servers[child_num][thread_num];
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_mpm_query(AP_MPMQ_MAX_DAEMON_USED, &max_daemons_limit);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin for (i = 0; i < max_daemons_limit; ++i)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinint ap_update_child_status(int child_num, int thread_num, int status, request_rec *r)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws = &ap_scoreboard_image->servers[child_num][thread_num];
if (ap_extended_status) {
return old_status;
if (child_num < 0)
if (((x < 0) || (HARD_SERVER_LIMIT < x)) ||
((y < 0) || (HARD_THREAD_LIMIT < y))) {
if ((x < 0) || (HARD_SERVER_LIMIT < x)) {