scoreboard.c revision 750ec6495c0f3f2786f0655420fe604a1a91725b
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Redistribution and use in source and binary forms, with or without
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * modification, are permitted provided that the following conditions
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * 1. Redistributions of source code must retain the above copyright
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * notice, this list of conditions and the following disclaimer.
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.
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 * 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.
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 * 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 * 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
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.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE_DATA const char *ap_scoreboard_fname=NULL;
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/* 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 const char *fname;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding fname = ap_server_root_relative(p, ap_scoreboard_fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: %s",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_server_argv0, apr_strerror(rv, errmsg, sizeof errmsg));
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
8a3228198adb03e6996f7738c361a612777ecab6aaron/* ap_cleanup_scoreboard
649c9dd342a580016d29c2866de88a4609eb6457wrowe/* ap_create_scoreboard(apr_pool_t*, ap_scoreboard_e t)
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowe * Create or reinit an existing scoreboard. The MPM can control whether
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick * the scoreboard is shared across multiple processes or not
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickAP_DECLARE(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick running_gen = ap_scoreboard_image->global.running_generation;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /* A simple malloc will suffice */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ap_scoreboard_image->global.running_generation = running_gen;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
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 * 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
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowestatic apr_inline void put_scoreboard_info(int child_num, int thread_num,
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe /* XXX - needs to be fixed to account for threads */
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe lseek(scoreboard_fd, (long) child_num * sizeof(short_score), 0);
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe force_write(scoreboard_fd, new_score_rec, sizeof(short_score));
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick (char *) &ap_scoreboard_image->global -(char *) ap_scoreboard_image, 0);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick force_write(scoreboard_fd, &ap_scoreboard_image->global,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickvoid increment_counts(int child_num, int thread_num, request_rec *r)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick ss = &ap_scoreboard_image->servers[child_num][thread_num];
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe for (i = 0; i < max_daemons_limit; ++i)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wroweint ap_update_child_status(int child_num, int thread_num, int status, request_rec *r)
649c9dd342a580016d29c2866de88a4609eb6457wrowe ss = &ap_scoreboard_image->servers[child_num][thread_num];
649c9dd342a580016d29c2866de88a4609eb6457wrowe if ((status == SERVER_READY || status == SERVER_ACCEPTING)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ss->thread_num = child_num * HARD_SERVER_LIMIT + thread_num;
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (status == SERVER_READY || status == SERVER_DEAD) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe * Reset individual counters
760b90f5b0bb414646deb6a3a2a53c14bf49bf3dwrowe apr_cpystrn(ss->client, ap_get_remote_host(c, r->per_dir_config,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_cpystrn(ss->request, "NULL", sizeof(ss->request));
76185d819b745e953dd2cd636fbdd515c333e4a4trawick apr_cpystrn(ss->request, r->the_request, sizeof(ss->request));
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),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingvoid ap_time_process_request(int child_num, int thread_num, int status)