scoreboard.c revision d6c3accf07754479fa938c752d1f739ac872e984
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.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*****************************************************************
8a3228198adb03e6996f7738c361a612777ecab6aaron * Dealing with the scoreboard... a lot of these variables are global
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * only to avoid getting clobbered by the longjmp() that happens when
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * a hard timeout expires...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We begin with routines which deal with the file itself...
8a3228198adb03e6996f7738c361a612777ecab6aaron const char *fname;
8a3228198adb03e6996f7738c361a612777ecab6aaron fname = ap_server_root_relative(p, ap_scoreboard_fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: %s",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_server_argv0, apr_strerror(rv, errmsg, sizeof errmsg));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_register_cleanup(p, NULL, ap_cleanup_shared_mem, apr_null_cleanup);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* APR_SHARED_MEM */
8a3228198adb03e6996f7738c361a612777ecab6aaron * Above code is shmem code. Below code is interacting with the shmem
8a3228198adb03e6996f7738c361a612777ecab6aaronvoid ap_perchild_set_maintain_connection_status(int flag) {
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf/* Useful to erase the status of children that might be from previous
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf * generations */
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sfvoid ap_perchild_force_reset_connection_status(long conn_id)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < STATUSES_PER_CONNECTION; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image->table[conn_id][i].key[0] = '\0';
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/* Don't mess with the string you get back from this function */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickconst char *ap_get_connection_status(long conn_id, const char *key)
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton connection_list = apr_make_array(p, 0, sizeof(long));
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /* We assume that there is a connection iff it has an entry in the status
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * table. Connections without any status sound problematic to me, so this
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * is probably for the best. - manoj */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton for (i = 0; i < ap_max_daemons_limit*HARD_THREAD_LIMIT; i++) {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (ap_scoreboard_image->table[i][0].key[0] != '\0') {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickapr_array_header_t *ap_get_connection_keys(apr_pool_t *p, long conn_id)
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe key_list = apr_make_array(p, 0, KEY_LENGTH * sizeof(char));
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/* Note: no effort is made here to prevent multiple threads from messing with
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * a single connection at the same time. ap_update_connection_status should
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * only be called by the thread that owns the connection */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickvoid ap_update_connection_status(long conn_id, const char *key,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick const char *value)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe /* Not found. Add an entry for this value */
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe /* No room. Oh well, not much anyone can do about it. */
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe server_status = apr_make_array(p, 0, sizeof(ap_status_table_row_t));
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* Go ahead and return what's in the connection status table even if we
649c9dd342a580016d29c2866de88a4609eb6457wrowe * aren't maintaining it. We can at least look at what children from
649c9dd342a580016d29c2866de88a4609eb6457wrowe * previous generations are up to. */
649c9dd342a580016d29c2866de88a4609eb6457wrowe for (i = 0; i < ap_max_daemons_limit*HARD_THREAD_LIMIT; i++) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe for (j = 0; j < STATUSES_PER_CONNECTION; j++) {