scoreboard.c revision f6f8d06ef9dc2f04d08775e6a998be731e8f7ec5
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ====================================================================
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd *
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Copyright (c) 2000 The Apache Software Foundation. All rights
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * reserved.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Redistribution and use in source and binary forms, with or without
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * modification, are permitted provided that the following conditions
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * are met:
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 1. Redistributions of source code must retain the above copyright
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * notice, this list of conditions and the following disclaimer.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen *
2e545ce2450a9953665f701bb05350f0d3f26275nd * 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * distribution.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if any, must include the following acknowledgment:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * "This product includes software developed by the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Apache Software Foundation (http://www.apache.org/)."
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Alternately, this acknowledgment may appear in the software itself,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if and wherever such third-party acknowledgments normally appear.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * 4. The names "Apache" and "Apache Software Foundation" must
af84459fbf938e508fd10b01cb8d699c79083813takashi * not be used to endorse or promote products derived from this
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * software without prior written permission. For written
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * permission, please contact apache@apache.org.
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 5. Products derived from this software may not be called "Apache",
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * nor may "Apache" appear in their name, without prior written
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * permission of the Apache Software Foundation.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
71fccc298df6a1540d408151a26aa22beed55d0bnd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * SUCH DAMAGE.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ====================================================================
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * This software consists of voluntary contributions made by many
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * individuals on behalf of the Apache Software Foundation. For more
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * information on the Apache Software Foundation, please see
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * <http://www.apache.org/>.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * Portions of this software are based upon public domain software
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * originally written at the National Center for Supercomputing Applications,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * University of Illinois, Urbana-Champaign.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "apr_strings.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "apr_portable.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "ap_config.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "httpd.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "http_log.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "http_main.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "http_core.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "http_config.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ToDo: Fix this right */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#if !defined(WIN32) && !defined(OS2) && !defined(BEOS)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "unixd.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "http_conf_globals.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "mpm.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "scoreboard.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#ifdef HAVE_SYS_TYPES_H
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include <sys/types.h>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE_DATA const char *ap_scoreboard_fname=NULL;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE_DATA int ap_extended_status = 0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE_DATA apr_time_t ap_restart_time = 0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#if APR_HAS_SHARED_MEMORY
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#include "apr_shmem.h"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic apr_shmem_t *scoreboard_shm = NULL;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/*
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ToDo:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * This function should be renamed to cleanup_shared
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * and it should handle cleaning up a scoreboard shared
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * between processes using any form of IPC (file, shared memory
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * segment, etc.). Leave it as is now because it is being used
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * by various MPMs.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic apr_status_t ap_cleanup_shared_mem(void *d)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#if APR_HAS_SHARED_MEMORY
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_shm_free(scoreboard_shm, ap_scoreboard_image);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_scoreboard_image = NULL;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_shm_destroy(scoreboard_shm);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return APR_SUCCESS;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ToDo: This function should be made to handle setting up
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * a scoreboard shared between processes using any IPC technique,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * not just a shared memory segment
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic void setup_shared(apr_pool_t *p)
71fccc298df6a1540d408151a26aa22beed55d0bnd{
71fccc298df6a1540d408151a26aa22beed55d0bnd#if APR_HAS_SHARED_MEMORY
71fccc298df6a1540d408151a26aa22beed55d0bnd char buf[512];
71fccc298df6a1540d408151a26aa22beed55d0bnd char errmsg[120];
71fccc298df6a1540d408151a26aa22beed55d0bnd const char *fname;
71fccc298df6a1540d408151a26aa22beed55d0bnd apr_status_t rv;
71fccc298df6a1540d408151a26aa22beed55d0bnd
71fccc298df6a1540d408151a26aa22beed55d0bnd fname = ap_server_root_relative(p, ap_scoreboard_fname);
71fccc298df6a1540d408151a26aa22beed55d0bnd rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
71fccc298df6a1540d408151a26aa22beed55d0bnd if (rv != APR_SUCCESS) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: %s",
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_server_argv0, apr_strerror(rv, errmsg, sizeof errmsg));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd fprintf(stderr, "%s\n", buf);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd exit(APEXIT_INIT);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (ap_scoreboard_image == NULL) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_server_argv0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd perror(buf); /* o.k. since MM sets errno */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_shm_destroy(scoreboard_shm);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd exit(APEXIT_INIT);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_scoreboard_image->global.running_generation = 0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE(void) reopen_scoreboard(apr_pool_t *p)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
71fccc298df6a1540d408151a26aa22beed55d0bnd/* ap_cleanup_scoreboard
71fccc298df6a1540d408151a26aa22beed55d0bnd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndapr_status_t ap_cleanup_scoreboard(void *d) {
71fccc298df6a1540d408151a26aa22beed55d0bnd if (ap_scoreboard_image == NULL)
71fccc298df6a1540d408151a26aa22beed55d0bnd return APR_SUCCESS;
71fccc298df6a1540d408151a26aa22beed55d0bnd if (ap_scoreboard_image->global.sb_type == SB_SHARED) {
71fccc298df6a1540d408151a26aa22beed55d0bnd ap_cleanup_shared_mem(NULL);
71fccc298df6a1540d408151a26aa22beed55d0bnd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd else {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd free(ap_scoreboard_image);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_scoreboard_image = NULL;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return APR_SUCCESS;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ap_create_scoreboard(apr_pool_t*, ap_scoreboard_e t)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Create or reinit an existing scoreboard. The MPM can control whether
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * the scoreboard is shared across multiple processes or not
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd int running_gen = 0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (ap_scoreboard_image)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd running_gen = ap_scoreboard_image->global.running_generation;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (ap_scoreboard_image == NULL) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (sb_type == SB_SHARED) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd setup_shared(p);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd else {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* A simple malloc will suffice */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd char buf[512];
71fccc298df6a1540d408151a26aa22beed55d0bnd ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
71fccc298df6a1540d408151a26aa22beed55d0bnd if (ap_scoreboard_image == NULL) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_server_argv0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd perror(buf); /* o.k. since MM sets errno */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd exit(APEXIT_INIT);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd memset(ap_scoreboard_image, 0, SCOREBOARD_SIZE);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_scoreboard_image->global.sb_type = sb_type;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_scoreboard_image->global.running_generation = running_gen;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_restart_time = apr_time_now();
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* Routines called to deal with the scoreboard image
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * --- note that we do *not* need write locks, since update_child_status
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * only updates a *single* record in place, and only one process writes to
71fccc298df6a1540d408151a26aa22beed55d0bnd * a given scoreboard slot at a time (either the child process owning that
71fccc298df6a1540d408151a26aa22beed55d0bnd * slot, or the parent, noting that the child has died).
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd *
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * As a final note --- setting the score entry to getpid() is always safe,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * since when the parent is writing an entry, it's only noting SERVER_DEAD
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * anyway.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndvoid ap_sync_scoreboard_image(void)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE(int) ap_exists_scoreboard_image(void)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return (ap_scoreboard_image ? 1 : 0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic apr_inline void put_scoreboard_info(int child_num, int thread_num,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd short_score *new_score_rec)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* XXX - needs to be fixed to account for threads */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#ifdef SCOREBOARD_FILE
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd lseek(scoreboard_fd, (long) child_num * sizeof(short_score), 0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd force_write(scoreboard_fd, new_score_rec, sizeof(short_score));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
71fccc298df6a1540d408151a26aa22beed55d0bndvoid update_scoreboard_global(void)
71fccc298df6a1540d408151a26aa22beed55d0bnd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#ifdef SCOREBOARD_FILE
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd lseek(scoreboard_fd,
71fccc298df6a1540d408151a26aa22beed55d0bnd (char *) &ap_scoreboard_image->global -(char *) ap_scoreboard_image, 0);
71fccc298df6a1540d408151a26aa22beed55d0bnd force_write(scoreboard_fd, &ap_scoreboard_image->global,
71fccc298df6a1540d408151a26aa22beed55d0bnd sizeof ap_scoreboard_image->global);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndvoid increment_counts(int child_num, int thread_num, request_rec *r)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd short_score *ss;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss = &ap_scoreboard_image->servers[child_num][thread_num];
71fccc298df6a1540d408151a26aa22beed55d0bnd
71fccc298df6a1540d408151a26aa22beed55d0bnd#ifdef HAVE_TIMES
71fccc298df6a1540d408151a26aa22beed55d0bnd times(&ss->times);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->access_count++;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->my_access_count++;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->conn_count++;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->bytes_served += r->bytes_sent;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->my_bytes_served += r->bytes_sent;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->conn_bytes += r->bytes_sent;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd put_scoreboard_info(child_num, thread_num, ss);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE(int) find_child_by_pid(apr_proc_t *pid)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
71fccc298df6a1540d408151a26aa22beed55d0bnd int i;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd int max_daemons_limit = ap_get_max_daemons();
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (i = 0; i < max_daemons_limit; ++i)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (ap_scoreboard_image->parent[i].pid == pid->pid)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return i;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return -1;
71fccc298df6a1540d408151a26aa22beed55d0bnd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndint ap_update_child_status(int child_num, int thread_num, int status, request_rec *r)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
71fccc298df6a1540d408151a26aa22beed55d0bnd int old_status;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd short_score *ss;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd parent_score *ps;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (child_num < 0)
71fccc298df6a1540d408151a26aa22beed55d0bnd return -1;
71fccc298df6a1540d408151a26aa22beed55d0bnd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss = &ap_scoreboard_image->servers[child_num][thread_num];
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd old_status = ss->status;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->status = status;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ps = &ap_scoreboard_image->parent[child_num];
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if ((status == SERVER_READY || status == SERVER_ACCEPTING)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd && old_status == SERVER_STARTING) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->thread_num = child_num * HARD_SERVER_LIMIT + thread_num;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ps->worker_threads = ap_threads_per_child;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (ap_extended_status) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (status == SERVER_READY || status == SERVER_DEAD) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /*
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Reset individual counters
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (status == SERVER_DEAD) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->my_access_count = 0L;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->my_bytes_served = 0L;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->conn_count = (unsigned short) 0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->conn_bytes = (unsigned long) 0;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (r) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd conn_rec *c = r->connection;
71fccc298df6a1540d408151a26aa22beed55d0bnd apr_cpystrn(ss->client, ap_get_remote_host(c, r->per_dir_config,
71fccc298df6a1540d408151a26aa22beed55d0bnd REMOTE_NOLOOKUP), sizeof(ss->client));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (r->the_request == NULL) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_cpystrn(ss->request, "NULL", sizeof(ss->request));
71fccc298df6a1540d408151a26aa22beed55d0bnd } else if (r->parsed_uri.password == NULL) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_cpystrn(ss->request, r->the_request, sizeof(ss->request));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd } else {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Don't reveal the password in the server-status view */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_cpystrn(ss->request, apr_pstrcat(r->pool, r->method, " ",
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_unparse_uri_components(r->pool, &r->parsed_uri, UNP_OMITPASSWORD),
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd r->assbackwards ? NULL : " ", r->protocol, NULL),
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd sizeof(ss->request));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->vhostrec = r->server;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd put_scoreboard_info(child_num, thread_num, ss);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return old_status;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd}
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndvoid ap_time_process_request(int child_num, int thread_num, int status)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd{
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd short_score *ss;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (child_num < 0)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss = &ap_scoreboard_image->servers[child_num][thread_num];
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if (status == START_PREQUEST) {
71fccc298df6a1540d408151a26aa22beed55d0bnd ss->start_time = apr_time_now();
71fccc298df6a1540d408151a26aa22beed55d0bnd }
71fccc298df6a1540d408151a26aa22beed55d0bnd else if (status == STOP_PREQUEST) {
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->stop_time = apr_time_now();
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd }
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd put_scoreboard_info(child_num, thread_num, ss);
71fccc298df6a1540d408151a26aa22beed55d0bnd}
71fccc298df6a1540d408151a26aa22beed55d0bnd
71fccc298df6a1540d408151a26aa22beed55d0bnd