scoreboard.c revision bf5cf58cc30750e9f9764cc830aff426ced288f9
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Redistribution and use in source and binary forms, with or without
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * modification, are permitted provided that the following conditions
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * are met:
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 1. Redistributions of source code must retain the above copyright
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * notice, this list of conditions and the following disclaimer.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 2. Redistributions in binary form must reproduce the above copyright
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * notice, this list of conditions and the following disclaimer in
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the documentation and/or other materials provided with the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * distribution.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 3. The end-user documentation included with the redistribution,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * if any, must include the following acknowledgment:
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * "This product includes software developed by the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Apache Software Foundation (http://www.apache.org/)."
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Alternately, this acknowledgment may appear in the software itself,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * if and wherever such third-party acknowledgments normally appear.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 4. The names "Apache" and "Apache Software Foundation" must
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * not be used to endorse or promote products derived from this
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * software without prior written permission. For written
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * permission, please contact apache@apache.org.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * 5. Products derived from this software may not be called "Apache",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * nor may "Apache" appear in their name, without prior written
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * permission of the Apache Software Foundation.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
806b50b4d37ade77f1c767a1593fac5a2d7786c8minfrin * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
c07866e582be4daac7f6a0a8754fa12fca044663fuankg * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
07ed2f9227b98d2cac21a7121ef7ea5328fa3f98fuankg * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
15ff8c621815e8337abc10638f2b2853ee6fd076minfrin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * SUCH DAMAGE.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * ====================================================================
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * This software consists of voluntary contributions made by many
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * individuals on behalf of the Apache Software Foundation. For more
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * information on the Apache Software Foundation, please see
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * <http://www.apache.org/>.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Portions of this software are based upon public domain software
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * originally written at the National Center for Supercomputing Applications,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * University of Illinois, Urbana-Champaign.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "apr.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "apr_strings.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "apr_portable.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "apr_lib.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#define APR_WANT_STRFUNC
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "apr_want.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#if APR_HAVE_SYS_TYPES_H
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include <sys/types.h>
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#endif
15351ab1a34130c1f880daef4e5dc15407a75969colm
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "ap_config.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "httpd.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "http_log.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "http_main.h"
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#include "http_core.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "http_config.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "ap_mpm.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "mpm.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "scoreboard.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzAP_DECLARE_DATA const char *ap_scoreboard_fname = NULL;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndAP_DECLARE_DATA int ap_extended_status = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#if APR_HAS_SHARED_MEMORY
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#include "apr_shm.h"
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#ifndef WIN32
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic /* but must be exported to mpm_winnt */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#endif
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_shm_t *ap_scoreboard_shm = NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#endif
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndAPR_HOOK_STRUCT(
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd APR_HOOK_LINK(pre_mpm)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndAP_IMPLEMENT_HOOK_RUN_ALL(int,pre_mpm,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd (apr_pool_t *p, ap_scoreboard_e sb_type),
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz (p, sb_type),OK,DECLINED)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstruct ap_sb_handle_t {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int child_num;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int thread_num;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd};
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic int server_limit, thread_limit;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic apr_size_t scoreboard_size;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/*
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * ToDo:
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * This function should be renamed to cleanup_shared
2d728410bcf9e6e53698bb035f516e18efd76d8bnd * and it should handle cleaning up a scoreboard shared
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * between processes using any form of IPC (file, shared memory
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * segment, etc.). Leave it as is now because it is being used
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * by various MPMs.
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin */
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrinstatic apr_status_t ap_cleanup_shared_mem(void *d)
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#if APR_HAS_SHARED_MEMORY
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin free(ap_scoreboard_image);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_scoreboard_image = NULL;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin apr_shm_destroy(ap_scoreboard_shm);
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin#endif
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin return APR_SUCCESS;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin}
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrinint ap_calc_scoreboard_size(void)
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin{
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz scoreboard_size = sizeof(global_score);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz scoreboard_size += sizeof(process_score) * server_limit;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz scoreboard_size += sizeof(worker_score) * server_limit * thread_limit;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return scoreboard_size;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzvoid ap_init_scoreboard(void *shared_score)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz char *more_storage;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int i;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
a51acf58d9d82f52e0ee56106cd9282030f3f3bend ap_calc_scoreboard_size();
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_scoreboard_image =
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz more_storage = shared_score;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_scoreboard_image->global = (global_score *)more_storage;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz more_storage += sizeof(global_score);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_scoreboard_image->parent = (process_score *)more_storage;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz more_storage += sizeof(process_score) * server_limit;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_scoreboard_image->servers =
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz (worker_score **)((char*)ap_scoreboard_image + sizeof(scoreboard));
a51acf58d9d82f52e0ee56106cd9282030f3f3bend for (i = 0; i < server_limit; i++) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_scoreboard_image->servers[i] = (worker_score *)more_storage;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz more_storage += thread_limit * sizeof(worker_score);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_assert(more_storage == (char*)shared_score + scoreboard_size);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_scoreboard_image->global->server_limit = server_limit;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_scoreboard_image->global->thread_limit = thread_limit;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/**
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Create a name-based scoreboard in the given pool using the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * given filename.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic apr_status_t create_namebased_scoreboard(apr_pool_t *pool,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *fname)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#if APR_HAS_SHARED_MEMORY
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_status_t rv;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* The shared memory file must not exist before we create the
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * segment. */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_file_remove(fname, pool); /* ignore errors */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, pool);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (rv != APR_SUCCESS) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "unable to create scoreboard "
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "(name-based shared memory failure)");
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return rv;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#endif /* APR_HAS_SHARED_MEMORY */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return APR_SUCCESS;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin/* ToDo: This function should be made to handle setting up
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * a scoreboard shared between processes using any IPC technique,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * not just a shared memory segment
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin */
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrinstatic apr_status_t open_scoreboard(apr_pool_t *pconf)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#if APR_HAS_SHARED_MEMORY
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_status_t rv;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin char *fname = NULL;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin apr_pool_t *global_pool;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* We don't want to have to recreate the scoreboard after
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin * restarts, so we'll create a global pool and never clean it.
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz rv = apr_pool_create(&global_pool, NULL);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (rv != APR_SUCCESS) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin "Fatal error: unable to create global pool "
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin "for use with by the scoreboard");
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return rv;
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* The config says to create a name-based shmem */
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin if (ap_scoreboard_fname) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* make sure it's an absolute pathname */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return create_namebased_scoreboard(global_pool, fname);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else { /* config didn't specify, we get to choose shmem type */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz global_pool); /* anonymous shared memory */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Unable to create scoreboard "
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "(anonymous shared memory failure)");
a51acf58d9d82f52e0ee56106cd9282030f3f3bend return rv;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* Make up a filename and do name-based shmem */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin else if (rv == APR_ENOTIMPL) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* Make sure it's an absolute pathname */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_scoreboard_fname = DEFAULT_SCOREBOARD;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin fname = ap_server_root_relative(pconf, ap_scoreboard_fname);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return create_namebased_scoreboard(global_pool, fname);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#endif /* APR_HAS_SHARED_MEMORY */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return APR_SUCCESS;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin/* If detach is non-zero, this is a seperate child process,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * if zero, it is a forked child.
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinapr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#if APR_HAS_SHARED_MEMORY
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (!detached) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return APR_SUCCESS;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (apr_shm_size_get(ap_scoreboard_shm) < scoreboard_size) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_error(APLOG_MARK, APLOG_CRIT | APLOG_NOERRNO, 0, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Fatal error: shared scoreboard too small for child!");
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin apr_shm_detach(ap_scoreboard_shm);
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin ap_scoreboard_shm = NULL;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin return APR_EINVAL;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin }
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin /* everything will be cleared shortly */
289a94d4157967ac04dc5c865b94e361400eae0afuankg if (*shm) {
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin *shm = ap_scoreboard_shm;
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin }
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin#endif
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin return APR_SUCCESS;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzapr_status_t ap_cleanup_scoreboard(void *d)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (ap_scoreboard_image == NULL) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return APR_SUCCESS;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (ap_scoreboard_image->global->sb_type == SB_SHARED) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_cleanup_shared_mem(NULL);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin else {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin free(ap_scoreboard_image->global);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin free(ap_scoreboard_image);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_scoreboard_image = NULL;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return APR_SUCCESS;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin/* Create or reinit an existing scoreboard. The MPM can control whether
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * the scoreboard is shared across multiple processes or not
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinint ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin int running_gen = 0;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#if APR_HAS_SHARED_MEMORY
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin apr_status_t rv;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#endif
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (ap_scoreboard_image) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin running_gen = ap_scoreboard_image->global->running_generation;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (ap_scoreboard_image == NULL) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_calc_scoreboard_size();
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#if APR_HAS_SHARED_MEMORY
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (sb_type == SB_SHARED) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin void *sb_shared;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin rv = open_scoreboard(p);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return HTTP_INTERNAL_SERVER_ERROR;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin memset(sb_shared, 0, scoreboard_size);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_init_scoreboard(sb_shared);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz else
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#endif
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* A simple malloc will suffice */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin void *sb_mem = calloc(1, scoreboard_size);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (sb_mem == NULL) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_log_error(APLOG_MARK, APLOG_CRIT | APLOG_NOERRNO, 0, NULL,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "(%d)%s: cannot allocate scoreboard",
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin errno, strerror(errno));
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return HTTP_INTERNAL_SERVER_ERROR;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_init_scoreboard(sb_mem);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_scoreboard_image->global->sb_type = sb_type;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_scoreboard_image->global->running_generation = running_gen;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_scoreboard_image->global->restart_time = apr_time_now();
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return OK;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/* Routines called to deal with the scoreboard image
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * --- note that we do *not* need write locks, since update_child_status
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * only updates a *single* record in place, and only one process writes to
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * a given scoreboard slot at a time (either the child process owning that
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * slot, or the parent, noting that the child has died).
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin *
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * As a final note --- setting the score entry to getpid() is always safe,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * since when the parent is writing an entry, it's only noting SERVER_DEAD
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * anyway.
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinvoid ap_sync_scoreboard_image(void)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndAP_DECLARE(int) ap_exists_scoreboard_image(void)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return (ap_scoreboard_image ? 1 : 0);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd}
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic APR_INLINE void put_scoreboard_info(int child_num, int thread_num,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd worker_score *new_score_rec)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* XXX - needs to be fixed to account for threads */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#ifdef SCOREBOARD_FILE
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz lseek(scoreboard_fd, sizeof(global_score)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz + (long)child_num * sizeof(worker_score), 0);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz force_write(scoreboard_fd, new_score_rec, sizeof(worker_score));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz#endif
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinvoid update_scoreboard_global(void)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#ifdef SCOREBOARD_FILE
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd lseek(scoreboard_fd, 0, 0);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz force_write(scoreboard_fd, &ap_scoreboard_image->global,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd sizeof ap_scoreboard_image->global);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd#endif
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinAP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sb, request_rec *r)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin{
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin worker_score *ws;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ws = &ap_scoreboard_image->servers[sb->child_num][sb->thread_num];
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#ifdef HAVE_TIMES
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin times(&ws->times);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin#endif
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ws->access_count++;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ws->my_access_count++;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ws->conn_count++;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ws->bytes_served += r->bytes_sent;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ws->my_bytes_served += r->bytes_sent;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ws->conn_bytes += r->bytes_sent;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin put_scoreboard_info(sb->child_num, sb->thread_num, ws);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin}
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinAP_DECLARE(int) find_child_by_pid(apr_proc_t *pid)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz{
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int i;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz int max_daemons_limit;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd for (i = 0; i < max_daemons_limit; ++i) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd if (ap_scoreboard_image->parent[i].pid == pid->pid) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return i;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin }
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return -1;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz}
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz
5876f43a746f688a32b7201bced8591ddf19bd43minfrinAP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin int child_num, int thread_num)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
5876f43a746f688a32b7201bced8591ddf19bd43minfrin *new_sbh = (ap_sb_handle_t *)apr_palloc(p, sizeof(ap_sb_handle_t));
5876f43a746f688a32b7201bced8591ddf19bd43minfrin (*new_sbh)->child_num = child_num;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin (*new_sbh)->thread_num = thread_num;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinAP_DECLARE(int) ap_update_child_status_from_indexes(int child_num,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin int thread_num,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin int status,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin request_rec *r)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
5876f43a746f688a32b7201bced8591ddf19bd43minfrin int old_status;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin worker_score *ws;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin process_score *ps;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (child_num < 0) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return -1;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
717473b4288c54ef043f016a4ee801aba477303erjung ws = &ap_scoreboard_image->servers[child_num][thread_num];
5876f43a746f688a32b7201bced8591ddf19bd43minfrin old_status = ws->status;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->status = status;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ps = &ap_scoreboard_image->parent[child_num];
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (status == SERVER_READY
5876f43a746f688a32b7201bced8591ddf19bd43minfrin && old_status == SERVER_STARTING) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->thread_num = child_num * server_limit + thread_num;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ps->generation = ap_my_generation;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (ap_extended_status) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->last_used = apr_time_now();
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (status == SERVER_READY || status == SERVER_DEAD) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /*
c840604b10dc1d368a2da321ec51362373d502a3minfrin * Reset individual counters
5876f43a746f688a32b7201bced8591ddf19bd43minfrin */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (status == SERVER_DEAD) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->my_access_count = 0L;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->my_bytes_served = 0L;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->conn_count = (unsigned short)0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->conn_bytes = (unsigned long)0;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (r) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin conn_rec *c = r->connection;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_cpystrn(ws->client, ap_get_remote_host(c, r->per_dir_config,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin REMOTE_NOLOOKUP, NULL), sizeof(ws->client));
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (r->the_request == NULL) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_cpystrn(ws->request, "NULL", sizeof(ws->request));
5876f43a746f688a32b7201bced8591ddf19bd43minfrin } else if (r->parsed_uri.password == NULL) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_cpystrn(ws->request, r->the_request, sizeof(ws->request));
5876f43a746f688a32b7201bced8591ddf19bd43minfrin } else {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* Don't reveal the password in the server-status view */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_cpystrn(ws->request, apr_pstrcat(r->pool, r->method, " ",
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_uri_unparse(r->pool, &r->parsed_uri,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin APR_URI_UNP_OMITPASSWORD),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin r->assbackwards ? NULL : " ", r->protocol, NULL),
5876f43a746f688a32b7201bced8591ddf19bd43minfrin sizeof(ws->request));
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_cpystrn(ws->vhost, r->server->server_hostname,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin sizeof(ws->vhost));
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin put_scoreboard_info(child_num, thread_num, ws);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return old_status;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinAP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin request_rec *r)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return ap_update_child_status_from_indexes(sbh->child_num, sbh->thread_num,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin status, r);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinvoid ap_time_process_request(int child_num, int thread_num, int status)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
5876f43a746f688a32b7201bced8591ddf19bd43minfrin worker_score *ws;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (child_num < 0) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws = &ap_scoreboard_image->servers[child_num][thread_num];
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (status == START_PREQUEST) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->start_time = apr_time_now();
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin else if (status == STOP_PREQUEST) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ws->stop_time = apr_time_now();
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin put_scoreboard_info(child_num, thread_num, ws);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinAP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
5876f43a746f688a32b7201bced8591ddf19bd43minfrin if (((x < 0) || (server_limit < x)) ||
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ((y < 0) || (thread_limit < y))) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return(NULL); /* Out of range */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return &ap_scoreboard_image->servers[x][y];
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinAP_DECLARE(process_score *) ap_get_scoreboard_process(int x)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg if ((x < 0) || (server_limit < x)) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return(NULL); /* Out of range */
51c6a215cedf19fe46a20b5cbb57f01ec4d5e8c4fuankg }
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return &ap_scoreboard_image->parent[x];
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin
5876f43a746f688a32b7201bced8591ddf19bd43minfrinAP_DECLARE(global_score *) ap_get_scoreboard_global()
5876f43a746f688a32b7201bced8591ddf19bd43minfrin{
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return ap_scoreboard_image->global;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin}
5876f43a746f688a32b7201bced8591ddf19bd43minfrin