scoreboard.c revision d6c3accf07754479fa938c752d1f739ac872e984
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 "ap_config.h"
a7318397b355119d990d1f311b951dea2aafc53arbb#include "httpd.h"
a7318397b355119d990d1f311b951dea2aafc53arbb#include "http_log.h"
ce4dc40a4e87991087488f70d96d3447d7557294sf#include "http_main.h"
a7318397b355119d990d1f311b951dea2aafc53arbb#include "http_core.h"
a7318397b355119d990d1f311b951dea2aafc53arbb#include "http_config.h"
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe#include "unixd.h"
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe#include "http_conf_globals.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "mpm_status.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "scoreboard.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "mpm.h" /* for ap_max_daemons_limit */
8a3228198adb03e6996f7738c361a612777ecab6aaron#ifdef HAVE_SYS_TYPES_H
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include <sys/types.h>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic scoreboard *ap_scoreboard_image = NULL;
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*****************************************************************
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...
8a3228198adb03e6996f7738c361a612777ecab6aaron *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * We begin with routines which deal with the file itself...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#if APR_HAS_SHARED_MEMORY
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "apr_shmem.h"
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic apr_shmem_t *scoreboard_shm = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaronapr_status_t ap_cleanup_shared_mem(void *d)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_shm_free(scoreboard_shm, ap_scoreboard_image);
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_scoreboard_image = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_shm_destroy(scoreboard_shm);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return APR_SUCCESS;
8a3228198adb03e6996f7738c361a612777ecab6aaron}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void setup_shared_mem(apr_pool_t *p)
8a3228198adb03e6996f7738c361a612777ecab6aaron{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char buf[512];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char errmsg[120];
8a3228198adb03e6996f7738c361a612777ecab6aaron const char *fname;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_status_t rv;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaron fname = ap_server_root_relative(p, ap_scoreboard_fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rv != APR_SUCCESS) {
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: %s",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_server_argv0, apr_strerror(rv, errmsg, sizeof errmsg));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding fprintf(stderr, "%s\n", buf);
8a3228198adb03e6996f7738c361a612777ecab6aaron exit(APEXIT_INIT);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
8a3228198adb03e6996f7738c361a612777ecab6aaron if (ap_scoreboard_image == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_server_argv0);
8a3228198adb03e6996f7738c361a612777ecab6aaron perror(buf); /* o.k. since MM sets errno */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_shm_destroy(scoreboard_shm);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding exit(APEXIT_INIT);
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_register_cleanup(p, NULL, ap_cleanup_shared_mem, apr_null_cleanup);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingvoid reinit_scoreboard(apr_pool_t *p)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
8a3228198adb03e6996f7738c361a612777ecab6aaron if (ap_scoreboard_image == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding setup_shared_mem(p);
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding memset(ap_scoreboard_image, 0, SCOREBOARD_SIZE);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* APR_SHARED_MEM */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaron/****
8a3228198adb03e6996f7738c361a612777ecab6aaron * Above code is shmem code. Below code is interacting with the shmem
8a3228198adb03e6996f7738c361a612777ecab6aaron ****/
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaronstatic int maintain_connection_status = 1;
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaronvoid ap_perchild_set_maintain_connection_status(int flag) {
8a3228198adb03e6996f7738c361a612777ecab6aaron maintain_connection_status = flag;
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf return;
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf}
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf
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)
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf{
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf int i;
8a3228198adb03e6996f7738c361a612777ecab6aaron
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < STATUSES_PER_CONNECTION; i++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_scoreboard_image->table[conn_id][i].key[0] = '\0';
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe}
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowe
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawickvoid ap_reset_connection_status(long conn_id)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick if (maintain_connection_status) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick ap_perchild_force_reset_connection_status(conn_id);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick}
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
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{
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton int i = 0;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton status_table_entry *ss;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (!maintain_connection_status) return "";
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton while (i < STATUSES_PER_CONNECTION) {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton ss = &(ap_scoreboard_image->table[conn_id][i]);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (ss->key[0] == '\0') {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton break;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton }
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (0 == strcmp(ss->key, key)) {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton return ss->value;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton }
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton }
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton return NULL;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe}
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jortonapr_array_header_t *ap_get_connections(apr_pool_t *p)
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton{
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton int i;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_array_header_t *connection_list;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton long *array_slot;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
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') {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton array_slot = apr_push_array(connection_list);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick *array_slot = i;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick return connection_list;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick}
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickapr_array_header_t *ap_get_connection_keys(apr_pool_t *p, long conn_id)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick int i = 0;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick status_table_entry *ss;
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe apr_array_header_t *key_list;
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe char **array_slot;
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe key_list = apr_make_array(p, 0, KEY_LENGTH * sizeof(char));
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe while (i < STATUSES_PER_CONNECTION) {
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe ss = &(ap_scoreboard_image->table[conn_id][i]);
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe if (ss->key[0] == '\0') {
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe break;
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe }
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe array_slot = apr_push_array(key_list);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick *array_slot = apr_pstrdup(p, ss->key);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick i++;
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick return key_list;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick}
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
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 */
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickvoid ap_update_connection_status(long conn_id, const char *key,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick const char *value)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick int i = 0;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick status_table_entry *ss;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick if (!maintain_connection_status) return;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick while (i < STATUSES_PER_CONNECTION) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick ss = &(ap_scoreboard_image->table[conn_id][i]);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick if (ss->key[0] == '\0') {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick break;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
ebc18d48bea83ee5ed7a1b4e30007e5192539829wrowe if (0 == strcmp(ss->key, key)) {
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick apr_cpystrn(ss->value, value, VALUE_LENGTH);
066877f1a045103acfdd376d48cdd473c33f409bdougm return;
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick }
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick i++;
e8f95a682820a599fe41b22977010636be5c2717jim }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe /* Not found. Add an entry for this value */
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (i >= STATUSES_PER_CONNECTION) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe /* No room. Oh well, not much anyone can do about it. */
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe return;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_cpystrn(ss->key, key, KEY_LENGTH);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_cpystrn(ss->value, value, VALUE_LENGTH);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe return;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe}
85c435ceda98eab940615e4466d9c5955252e745wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wroweapr_array_header_t *ap_get_status_table(apr_pool_t *p)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe{
92eed7d377d8be7cd8e48d1299412fc8c742b7f5jorton int i, j;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_array_header_t *server_status;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ap_status_table_row_t *array_slot;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe status_table_entry *ss;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe server_status = apr_make_array(p, 0, sizeof(ap_status_table_row_t));
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
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
649c9dd342a580016d29c2866de88a4609eb6457wrowe for (i = 0; i < ap_max_daemons_limit*HARD_THREAD_LIMIT; i++) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (ap_scoreboard_image->table[i][0].key[0] == '\0')
649c9dd342a580016d29c2866de88a4609eb6457wrowe continue;
649c9dd342a580016d29c2866de88a4609eb6457wrowe array_slot = apr_push_array(server_status);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe array_slot->data = apr_make_table(p, 0);
649c9dd342a580016d29c2866de88a4609eb6457wrowe array_slot->conn_id = i;
649c9dd342a580016d29c2866de88a4609eb6457wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe for (j = 0; j < STATUSES_PER_CONNECTION; j++) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe ss = &(ap_scoreboard_image->table[i][j]);
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (ss->key[0] != '\0') {
649c9dd342a580016d29c2866de88a4609eb6457wrowe apr_table_add(array_slot->data, ss->key, ss->value);
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe else {
649c9dd342a580016d29c2866de88a4609eb6457wrowe break;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe return server_status;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe}
649c9dd342a580016d29c2866de88a4609eb6457wrowe