scoreboard.c revision 17f77e3bb7dc5bbbcfad34e974d9707cfbfde52f
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
bc8fd1b0b1afdf89b8d28eefa8cd74e26ba97986fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * are met:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. The end-user documentation included with the redistribution,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if any, must include the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Apache Software Foundation (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Alternately, this acknowledgment may appear in the software itself,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if and wherever such third-party acknowledgments normally appear.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache" and "Apache Software Foundation" must
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * not be used to endorse or promote products derived from this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software without prior written permission. For written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission, please contact apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache",
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their name, without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation. For more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * information on the Apache Software Foundation, please see
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * <http://www.apache.org/>.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Portions of this software are based upon public domain software
f4c310fd2555c6faca1f980f00b161eadb089023gstein * originally written at the National Center for Supercomputing Applications,
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker * University of Illinois, Urbana-Champaign.
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker */
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "apr.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "apr_strings.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "apr_portable.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "apr_lib.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#define APR_WANT_STRFUNC
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "apr_want.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#if APR_HAVE_SYS_TYPES_H
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include <sys/types.h>
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#endif
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "ap_config.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "httpd.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "http_log.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "http_main.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "http_core.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "http_config.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "ap_mpm.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "mpm.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker#include "scoreboard.h"
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
1b21d7b3d97def358b2e923655edeb16613a1c31gsteinAP_DECLARE_DATA const char *ap_scoreboard_fname=NULL;
1327b173ab33ae5bec795b798d5c54c16a7b5c05gsteinAP_DECLARE_DATA int ap_extended_status = 0;
1b21d7b3d97def358b2e923655edeb16613a1c31gsteinAP_DECLARE_DATA apr_time_t ap_restart_time = 0;
1b21d7b3d97def358b2e923655edeb16613a1c31gstein
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#if APR_HAS_SHARED_MEMORY
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "apr_shmem.h"
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_shmem_t *scoreboard_shm = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPR_HOOK_STRUCT(
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(pre_mpm)
f4c310fd2555c6faca1f980f00b161eadb089023gstein)
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_VOID(pre_mpm,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (apr_pool_t *p, ap_scoreboard_e sb_type),
f4c310fd2555c6faca1f980f00b161eadb089023gstein (p, sb_type))
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
000397350b42c6266351bd618fa07df929fa7c79gstein * ToDo:
000397350b42c6266351bd618fa07df929fa7c79gstein * This function should be renamed to cleanup_shared
000397350b42c6266351bd618fa07df929fa7c79gstein * and it should handle cleaning up a scoreboard shared
f4c310fd2555c6faca1f980f00b161eadb089023gstein * between processes using any form of IPC (file, shared memory
f4c310fd2555c6faca1f980f00b161eadb089023gstein * segment, etc.). Leave it as is now because it is being used
f4c310fd2555c6faca1f980f00b161eadb089023gstein * by various MPMs.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_status_t ap_cleanup_shared_mem(void *d)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAS_SHARED_MEMORY
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_shm_free(scoreboard_shm, ap_scoreboard_image);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ap_scoreboard_image = NULL;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein apr_shm_destroy(scoreboard_shm);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein return APR_SUCCESS;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ToDo: This function should be made to handle setting up
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a scoreboard shared between processes using any IPC technique,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * not just a shared memory segment
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
b47464a901075041e800be2de098a603923fa4f9gsteinstatic void setup_shared(apr_pool_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAS_SHARED_MEMORY
f4c310fd2555c6faca1f980f00b161eadb089023gstein char buf[512];
f4c310fd2555c6faca1f980f00b161eadb089023gstein char errmsg[120];
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker const char *fname;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein fname = ap_server_root_relative(p, ap_scoreboard_fname);
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv != APR_SUCCESS) {
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: (%d)%s",
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein ap_server_argv0, rv, apr_strerror(rv, errmsg, sizeof errmsg));
5a9667916c79d8c699b069068e5570aa1c331c80gstein fprintf(stderr, "%s\n", buf);
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein exit(APEXIT_INIT);
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein }
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein if (ap_scoreboard_image == NULL) {
5a9667916c79d8c699b069068e5570aa1c331c80gstein apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
9d0665da83d1e22c0ea0e5f6f940f70f75bf5237ianh ap_server_argv0);
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein perror(buf); /* o.k. since MM sets errno */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_shm_destroy(scoreboard_shm);
f4c310fd2555c6faca1f980f00b161eadb089023gstein exit(APEXIT_INIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein ap_scoreboard_image->global.running_generation = 0;
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein#endif
ef3c32d4a7accb38368c7b9face2ade88d987a8bgstein}
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3strikerAP_DECLARE(void) reopen_scoreboard(apr_pool_t *p)
9d0665da83d1e22c0ea0e5f6f940f70f75bf5237ianh{
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* ap_cleanup_scoreboard
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinapr_status_t ap_cleanup_scoreboard(void *d) {
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker if (ap_scoreboard_image == NULL)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return APR_SUCCESS;
b47464a901075041e800be2de098a603923fa4f9gstein if (ap_scoreboard_image->global.sb_type == SB_SHARED) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_cleanup_shared_mem(NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein free(ap_scoreboard_image);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_scoreboard_image = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
b47464a901075041e800be2de098a603923fa4f9gstein return APR_SUCCESS;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
b47464a901075041e800be2de098a603923fa4f9gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ap_create_scoreboard(apr_pool_t*, ap_scoreboard_e t)
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker * Create or reinit an existing scoreboard. The MPM can control whether
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the scoreboard is shared across multiple processes or not
b47464a901075041e800be2de098a603923fa4f9gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ###: Is there any reason to export this symbol in the first place?
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE_NONSTD(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int running_gen = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_image)
f4c310fd2555c6faca1f980f00b161eadb089023gstein running_gen = ap_scoreboard_image->global.running_generation;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_image == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sb_type == SB_SHARED) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein setup_shared(p);
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker }
de18a9e85398b9c79c422f578633ed56c2747bbbgstein else {
de18a9e85398b9c79c422f578633ed56c2747bbbgstein /* A simple malloc will suffice */
de18a9e85398b9c79c422f578633ed56c2747bbbgstein char buf[512];
de18a9e85398b9c79c422f578633ed56c2747bbbgstein ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
de18a9e85398b9c79c422f578633ed56c2747bbbgstein if (ap_scoreboard_image == NULL) {
de18a9e85398b9c79c422f578633ed56c2747bbbgstein apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
de18a9e85398b9c79c422f578633ed56c2747bbbgstein ap_server_argv0);
de18a9e85398b9c79c422f578633ed56c2747bbbgstein perror(buf); /* o.k. since MM sets errno */
de18a9e85398b9c79c422f578633ed56c2747bbbgstein exit(APEXIT_INIT);
de18a9e85398b9c79c422f578633ed56c2747bbbgstein }
de18a9e85398b9c79c422f578633ed56c2747bbbgstein }
de18a9e85398b9c79c422f578633ed56c2747bbbgstein }
de18a9e85398b9c79c422f578633ed56c2747bbbgstein memset(ap_scoreboard_image, 0, SCOREBOARD_SIZE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->global.sb_type = sb_type;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->global.running_generation = running_gen;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_restart_time = apr_time_now();
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Routines called to deal with the scoreboard image
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker * --- note that we do *not* need write locks, since update_child_status
f4c310fd2555c6faca1f980f00b161eadb089023gstein * only updates a *single* record in place, and only one process writes to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a given scoreboard slot at a time (either the child process owning that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * slot, or the parent, noting that the child has died).
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
de18a9e85398b9c79c422f578633ed56c2747bbbgstein * As a final note --- setting the score entry to getpid() is always safe,
de18a9e85398b9c79c422f578633ed56c2747bbbgstein * since when the parent is writing an entry, it's only noting SERVER_DEAD
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * anyway.
9f18c80269be35c0b5653e84b0db0a24044722c4gstein */
000397350b42c6266351bd618fa07df929fa7c79gstein
000397350b42c6266351bd618fa07df929fa7c79gsteinvoid ap_sync_scoreboard_image(void)
000397350b42c6266351bd618fa07df929fa7c79gstein{
000397350b42c6266351bd618fa07df929fa7c79gstein}
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gsteinAP_DECLARE(int) ap_exists_scoreboard_image(void)
000397350b42c6266351bd618fa07df929fa7c79gstein{
000397350b42c6266351bd618fa07df929fa7c79gstein return (ap_scoreboard_image ? 1 : 0);
000397350b42c6266351bd618fa07df929fa7c79gstein}
000397350b42c6266351bd618fa07df929fa7c79gstein
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic APR_INLINE void put_scoreboard_info(int child_num, int thread_num,
000397350b42c6266351bd618fa07df929fa7c79gstein worker_score *new_score_rec)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX - needs to be fixed to account for threads */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef SCOREBOARD_FILE
f4c310fd2555c6faca1f980f00b161eadb089023gstein lseek(scoreboard_fd, (long) child_num * sizeof(worker_score), 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein force_write(scoreboard_fd, new_score_rec, sizeof(worker_score));
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3strikervoid update_scoreboard_global(void)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein#ifdef SCOREBOARD_FILE
f4c310fd2555c6faca1f980f00b161eadb089023gstein lseek(scoreboard_fd,
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein (char *) &ap_scoreboard_image->global -(char *) ap_scoreboard_image, 0);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein force_write(scoreboard_fd, &ap_scoreboard_image->global,
9f18c80269be35c0b5653e84b0db0a24044722c4gstein sizeof ap_scoreboard_image->global);
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein#endif
9f18c80269be35c0b5653e84b0db0a24044722c4gstein}
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gsteinAP_DECLARE(void) ap_increment_counts(int child_num, int thread_num, request_rec *r)
709df1e1c2e1710570f8cb4209497e88662829c3gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein worker_score *ws;
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein
709df1e1c2e1710570f8cb4209497e88662829c3gstein ws = &ap_scoreboard_image->servers[child_num][thread_num];
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein#ifdef HAVE_TIMES
f4c310fd2555c6faca1f980f00b161eadb089023gstein times(&ws->times);
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein#endif
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein ws->access_count++;
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein ws->my_access_count++;
709df1e1c2e1710570f8cb4209497e88662829c3gstein ws->conn_count++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->bytes_served += r->bytes_sent;
709df1e1c2e1710570f8cb4209497e88662829c3gstein ws->my_bytes_served += r->bytes_sent;
709df1e1c2e1710570f8cb4209497e88662829c3gstein ws->conn_bytes += r->bytes_sent;
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein put_scoreboard_info(child_num, thread_num, ws);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
7281ea331999debdc337b02ce37a3169e0e033a2gstein
7281ea331999debdc337b02ce37a3169e0e033a2gsteinAP_DECLARE(int) find_child_by_pid(apr_proc_t *pid)
7281ea331999debdc337b02ce37a3169e0e033a2gstein{
7281ea331999debdc337b02ce37a3169e0e033a2gstein int i;
7281ea331999debdc337b02ce37a3169e0e033a2gstein int max_daemons_limit;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
000397350b42c6266351bd618fa07df929fa7c79gstein ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
000397350b42c6266351bd618fa07df929fa7c79gstein for (i = 0; i < max_daemons_limit; ++i)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_image->parent[i].pid == pid->pid)
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker return i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
000397350b42c6266351bd618fa07df929fa7c79gstein return -1;
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker}
000397350b42c6266351bd618fa07df929fa7c79gstein
000397350b42c6266351bd618fa07df929fa7c79gsteinAP_DECLARE(int) ap_update_child_status(int child_num, int thread_num, int status, request_rec *r)
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker{
9f18c80269be35c0b5653e84b0db0a24044722c4gstein int old_status;
000397350b42c6266351bd618fa07df929fa7c79gstein worker_score *ws;
000397350b42c6266351bd618fa07df929fa7c79gstein process_score *ps;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
000397350b42c6266351bd618fa07df929fa7c79gstein if (child_num < 0)
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein return -1;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ws = &ap_scoreboard_image->servers[child_num][thread_num];
9f18c80269be35c0b5653e84b0db0a24044722c4gstein old_status = ws->status;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ws->status = status;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ps = &ap_scoreboard_image->parent[child_num];
9f18c80269be35c0b5653e84b0db0a24044722c4gstein
9f18c80269be35c0b5653e84b0db0a24044722c4gstein if (status == SERVER_READY
9f18c80269be35c0b5653e84b0db0a24044722c4gstein && old_status == SERVER_STARTING) {
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ws->thread_num = child_num * HARD_SERVER_LIMIT + thread_num;
9f18c80269be35c0b5653e84b0db0a24044722c4gstein ps->generation = ap_my_generation;
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein ws->vhostrec = NULL;
000397350b42c6266351bd618fa07df929fa7c79gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_extended_status) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->last_used = apr_time_now();
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == SERVER_READY || status == SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Reset individual counters
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->my_access_count = 0L;
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker ws->my_bytes_served = 0L;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->conn_count = (unsigned short) 0;
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker ws->conn_bytes = (unsigned long) 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker if (r) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein conn_rec *c = r->connection;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ws->client, ap_get_remote_host(c, r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein REMOTE_NOLOOKUP, NULL), sizeof(ws->client));
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->the_request == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ws->request, "NULL", sizeof(ws->request));
f4c310fd2555c6faca1f980f00b161eadb089023gstein } else if (r->parsed_uri.password == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ws->request, r->the_request, sizeof(ws->request));
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein } else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Don't reveal the password in the server-status view */
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker apr_cpystrn(ws->request, apr_pstrcat(r->pool, r->method, " ",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_uri_unparse(r->pool, &r->parsed_uri, APR_URI_UNP_OMITPASSWORD),
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->assbackwards ? NULL : " ", r->protocol, NULL),
f4c310fd2555c6faca1f980f00b161eadb089023gstein sizeof(ws->request));
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->vhostrec = r->server;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein put_scoreboard_info(child_num, thread_num, ws);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return old_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinvoid ap_time_process_request(int child_num, int thread_num, int status)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein worker_score *ws;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (child_num < 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws = &ap_scoreboard_image->servers[child_num][thread_num];
5b03ba47ff7225cacb131f14b019332af27da960gstein
5b03ba47ff7225cacb131f14b019332af27da960gstein if (status == START_PREQUEST) {
5b03ba47ff7225cacb131f14b019332af27da960gstein ws->start_time = apr_time_now();
5b03ba47ff7225cacb131f14b019332af27da960gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (status == STOP_PREQUEST) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->stop_time = apr_time_now();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein put_scoreboard_info(child_num, thread_num, ws);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinworker_score *ap_get_servers_scoreboard(int x, int y)
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker{
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker if (((x < 0) || (HARD_SERVER_LIMIT < x)) ||
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker ((y < 0) || (HARD_THREAD_LIMIT < y))) {
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker return(NULL); /* Out of range */
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker }
f5d88bab65052e00ba37a1af17e5e67a437628b5wrowe return(&ap_scoreboard_image->servers[x][y]);
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3striker}
f5d88bab65052e00ba37a1af17e5e67a437628b5wrowe
49f1aab8b6762ee5b4afdb3a9cc48e7c00435dd3strikerprocess_score *ap_get_parent_scoreboard(int x)
f5d88bab65052e00ba37a1af17e5e67a437628b5wrowe{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((x < 0) || (HARD_SERVER_LIMIT < x)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return(NULL); /* Out of range */
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return(&ap_scoreboard_image->parent[x]);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein