scoreboard.c revision 65db4f712167a3498de73cee5c08032a8aa6a010
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/* ====================================================================
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * The Apache Software License, Version 1.1
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin *
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * reserved.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin *
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Redistribution and use in source and binary forms, with or without
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * modification, are permitted provided that the following conditions
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * are met:
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin *
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * 1. Redistributions of source code must retain the above copyright
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * notice, this list of conditions and the following disclaimer.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin *
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 *
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.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin *
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 *
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 *
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 *
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 * <http://www.apache.org/>.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin *
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.
ab364c14d11072380abeab42015e19c3db3336c1sf */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "apr.h"
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin#include "apr_strings.h"
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin#include "apr_portable.h"
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin#include "apr_lib.h"
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin#define APR_WANT_STRFUNC
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin#include "apr_want.h"
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#if APR_HAVE_SYS_TYPES_H
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include <sys/types.h>
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#endif
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "ap_config.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "httpd.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "http_log.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "http_main.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "http_core.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "http_config.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "ap_mpm.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "mpm.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#include "scoreboard.h"
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrinAP_DECLARE_DATA const char *ap_scoreboard_fname=NULL;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE_DATA int ap_extended_status = 0;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE_DATA apr_time_t ap_restart_time = 0;
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi#if APR_HAS_SHARED_MEMORY
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin#include "apr_shmem.h"
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrinstatic apr_shmem_t *scoreboard_shm = NULL;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#endif
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAPR_HOOK_STRUCT(
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin APR_HOOK_LINK(pre_mpm)
562e9ce367eaaf4d3ea0ed4eaf3dbf0a644cf4aajorton)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_IMPLEMENT_HOOK_VOID(pre_mpm,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin (apr_pool_t *p, ap_scoreboard_e sb_type),
ab364c14d11072380abeab42015e19c3db3336c1sf (p, sb_type))
ab364c14d11072380abeab42015e19c3db3336c1sf
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/*
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * ToDo:
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.
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin */
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrinstatic apr_status_t ap_cleanup_shared_mem(void *d)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#if APR_HAS_SHARED_MEMORY
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_shm_free(scoreboard_shm, ap_scoreboard_image);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image = NULL;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_shm_destroy(scoreboard_shm);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#endif
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin return APR_SUCCESS;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
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
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin */
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrinstatic void setup_shared(apr_pool_t *p)
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#if APR_HAS_SHARED_MEMORY
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin char buf[512];
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi char errmsg[120];
d05e6175473332a8433e4ac85edda0d5a33c94b5minfrin const char *fname;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_status_t rv;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin fname = ap_server_root_relative(p, ap_scoreboard_fname);
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin if (rv != APR_SUCCESS) {
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: %s",
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin ap_server_argv0, apr_strerror(rv, errmsg, sizeof errmsg));
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin fprintf(stderr, "%s\n", buf);
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin exit(APEXIT_INIT);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin }
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin if (ap_scoreboard_image == NULL) {
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_server_argv0);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin perror(buf); /* o.k. since MM sets errno */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_shm_destroy(scoreboard_shm);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin exit(APEXIT_INIT);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin }
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image->global.running_generation = 0;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#endif
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrinAP_DECLARE(void) reopen_scoreboard(apr_pool_t *p)
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi/* ap_cleanup_scoreboard
d05e6175473332a8433e4ac85edda0d5a33c94b5minfrin *
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinapr_status_t ap_cleanup_scoreboard(void *d) {
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin if (ap_scoreboard_image == NULL)
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin return APR_SUCCESS;
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin if (ap_scoreboard_image->global.sb_type == SB_SHARED) {
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin ap_cleanup_shared_mem(NULL);
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin }
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin else {
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin free(ap_scoreboard_image);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image = NULL;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin }
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin return APR_SUCCESS;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/* ap_create_scoreboard(apr_pool_t*, ap_scoreboard_e t)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin *
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Create or reinit an existing scoreboard. The MPM can control whether
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * the scoreboard is shared across multiple processes or not
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin int running_gen = 0;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin if (ap_scoreboard_image)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin running_gen = ap_scoreboard_image->global.running_generation;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin if (ap_scoreboard_image == NULL) {
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin if (sb_type == SB_SHARED) {
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin setup_shared(p);
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi }
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin else {
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* A simple malloc will suffice */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin char buf[512];
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin if (ap_scoreboard_image == NULL) {
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_server_argv0);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin perror(buf); /* o.k. since MM sets errno */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin exit(APEXIT_INIT);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin }
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin }
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin }
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin memset(ap_scoreboard_image, 0, SCOREBOARD_SIZE);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image->global.sb_type = sb_type;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_scoreboard_image->global.running_generation = running_gen;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_restart_time = apr_time_now();
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
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 *
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
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * anyway.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinvoid ap_sync_scoreboard_image(void)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(int) ap_exists_scoreboard_image(void)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin return (ap_scoreboard_image ? 1 : 0);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinstatic APR_INLINE void put_scoreboard_info(int child_num, int thread_num,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin worker_score *new_score_rec)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* XXX - needs to be fixed to account for threads */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#ifdef SCOREBOARD_FILE
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin lseek(scoreboard_fd, (long) child_num * sizeof(worker_score), 0);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin force_write(scoreboard_fd, new_score_rec, sizeof(worker_score));
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#endif
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinvoid update_scoreboard_global(void)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#ifdef SCOREBOARD_FILE
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin lseek(scoreboard_fd,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin (char *) &ap_scoreboard_image->global -(char *) ap_scoreboard_image, 0);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin force_write(scoreboard_fd, &ap_scoreboard_image->global,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin sizeof ap_scoreboard_image->global);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#endif
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(void) ap_increment_counts(int child_num, int thread_num, request_rec *r)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin worker_score *ws;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws = &ap_scoreboard_image->servers[child_num][thread_num];
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#ifdef HAVE_TIMES
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin times(&ws->times);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin#endif
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws->access_count++;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws->my_access_count++;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws->conn_count++;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws->bytes_served += r->bytes_sent;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws->my_bytes_served += r->bytes_sent;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws->conn_bytes += r->bytes_sent;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin put_scoreboard_info(child_num, thread_num, ws);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(int) find_child_by_pid(apr_proc_t *pid)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin int i;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin int max_daemons_limit;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ap_mpm_query(AP_MPMQ_MAX_DAEMON_USED, &max_daemons_limit);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin for (i = 0; i < max_daemons_limit; ++i)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin if (ap_scoreboard_image->parent[i].pid == pid->pid)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin return i;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin return -1;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin}
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinint ap_update_child_status(int child_num, int thread_num, int status, request_rec *r)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin{
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin int old_status;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin worker_score *ws;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin process_score *ps;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin if (child_num < 0)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin return -1;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws = &ap_scoreboard_image->servers[child_num][thread_num];
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin old_status = ws->status;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ws->status = status;
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin ps = &ap_scoreboard_image->parent[child_num];
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin
if (status == SERVER_READY
&& old_status == SERVER_STARTING) {
ws->thread_num = child_num * HARD_SERVER_LIMIT + thread_num;
ps->generation = ap_my_generation;
}
if (ap_extended_status) {
ws->last_used = apr_time_now();
if (status == SERVER_READY || status == SERVER_DEAD) {
/*
* Reset individual counters
*/
if (status == SERVER_DEAD) {
ws->my_access_count = 0L;
ws->my_bytes_served = 0L;
}
ws->conn_count = (unsigned short) 0;
ws->conn_bytes = (unsigned long) 0;
}
if (r) {
conn_rec *c = r->connection;
apr_cpystrn(ws->client, ap_get_remote_host(c, r->per_dir_config,
REMOTE_NOLOOKUP, NULL), sizeof(ws->client));
if (r->the_request == NULL) {
apr_cpystrn(ws->request, "NULL", sizeof(ws->request));
} else if (r->parsed_uri.password == NULL) {
apr_cpystrn(ws->request, r->the_request, sizeof(ws->request));
} else {
/* Don't reveal the password in the server-status view */
apr_cpystrn(ws->request, apr_pstrcat(r->pool, r->method, " ",
apr_uri_unparse_components(r->pool, &r->parsed_uri, UNP_OMITPASSWORD),
r->assbackwards ? NULL : " ", r->protocol, NULL),
sizeof(ws->request));
}
ws->vhostrec = r->server;
}
}
put_scoreboard_info(child_num, thread_num, ws);
return old_status;
}
void ap_time_process_request(int child_num, int thread_num, int status)
{
worker_score *ws;
if (child_num < 0)
return;
ws = &ap_scoreboard_image->servers[child_num][thread_num];
if (status == START_PREQUEST) {
ws->start_time = apr_time_now();
}
else if (status == STOP_PREQUEST) {
ws->stop_time = apr_time_now();
}
put_scoreboard_info(child_num, thread_num, ws);
}
worker_score *ap_get_servers_scoreboard(int x, int y)
{
if (((x < 0) || (HARD_SERVER_LIMIT < x)) ||
((y < 0) || (HARD_THREAD_LIMIT < y))) {
return(NULL); /* Out of range */
}
return(&ap_scoreboard_image->servers[x][y]);
}
process_score *ap_get_parent_scoreboard(int x)
{
if ((x < 0) || (HARD_SERVER_LIMIT < x)) {
return(NULL); /* Out of range */
}
return(&ap_scoreboard_image->parent[x]);
}