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