scoreboard.c revision f6f8d06ef9dc2f04d08775e6a998be731e8f7ec5
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ====================================================================
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Copyright (c) 2000 The Apache Software Foundation. All rights
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * reserved.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Redistribution and use in source and binary forms, with or without
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * modification, are permitted provided that the following conditions
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * are met:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 1. Redistributions of source code must retain the above copyright
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * notice, this list of conditions and the following disclaimer.
2e545ce2450a9953665f701bb05350f0d3f26275nd * 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * distribution.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if any, must include the following acknowledgment:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * "This product includes software developed by the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Apache Software Foundation (http://www.apache.org/)."
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Alternately, this acknowledgment may appear in the software itself,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if and wherever such third-party acknowledgments normally appear.
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * 4. The names "Apache" and "Apache Software Foundation" must
af84459fbf938e508fd10b01cb8d699c79083813takashi * not be used to endorse or promote products derived from this
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * software without prior written permission. For written
e1e8390280254f7f0580d701e583f670643d4f3fnilgun * permission, please contact apache@apache.org.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 5. Products derived from this software may not be called "Apache",
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * nor may "Apache" appear in their name, without prior written
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * permission of the Apache Software Foundation.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
71fccc298df6a1540d408151a26aa22beed55d0bnd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * SUCH DAMAGE.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ====================================================================
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * This software consists of voluntary contributions made by many
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * individuals on behalf of the Apache Software Foundation. For more
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * information on the Apache Software Foundation, please see
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * Portions of this software are based upon public domain software
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * originally written at the National Center for Supercomputing Applications,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * University of Illinois, Urbana-Champaign.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ToDo: Fix this right */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * This function should be renamed to cleanup_shared
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * and it should handle cleaning up a scoreboard shared
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * between processes using any form of IPC (file, shared memory
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * segment, etc.). Leave it as is now because it is being used
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * by various MPMs.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ToDo: This function should be made to handle setting up
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * a scoreboard shared between processes using any IPC technique,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * not just a shared memory segment
71fccc298df6a1540d408151a26aa22beed55d0bnd const char *fname;
71fccc298df6a1540d408151a26aa22beed55d0bnd rv = apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard: %s",
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_server_argv0, apr_strerror(rv, errmsg, sizeof errmsg));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
71fccc298df6a1540d408151a26aa22beed55d0bnd/* ap_cleanup_scoreboard
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ap_create_scoreboard(apr_pool_t*, ap_scoreboard_e t)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Create or reinit an existing scoreboard. The MPM can control whether
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * the scoreboard is shared across multiple processes or not
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAP_DECLARE(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd running_gen = ap_scoreboard_image->global.running_generation;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* A simple malloc will suffice */
71fccc298df6a1540d408151a26aa22beed55d0bnd ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_scoreboard_image->global.running_generation = running_gen;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* Routines called to deal with the scoreboard image
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * --- note that we do *not* need write locks, since update_child_status
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * only updates a *single* record in place, and only one process writes to
71fccc298df6a1540d408151a26aa22beed55d0bnd * a given scoreboard slot at a time (either the child process owning that
71fccc298df6a1540d408151a26aa22beed55d0bnd * slot, or the parent, noting that the child has died).
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * As a final note --- setting the score entry to getpid() is always safe,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * since when the parent is writing an entry, it's only noting SERVER_DEAD
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndstatic apr_inline void put_scoreboard_info(int child_num, int thread_num,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* XXX - needs to be fixed to account for threads */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd lseek(scoreboard_fd, (long) child_num * sizeof(short_score), 0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd force_write(scoreboard_fd, new_score_rec, sizeof(short_score));
71fccc298df6a1540d408151a26aa22beed55d0bnd (char *) &ap_scoreboard_image->global -(char *) ap_scoreboard_image, 0);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndvoid increment_counts(int child_num, int thread_num, request_rec *r)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss = &ap_scoreboard_image->servers[child_num][thread_num];
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd for (i = 0; i < max_daemons_limit; ++i)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return -1;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndint ap_update_child_status(int child_num, int thread_num, int status, request_rec *r)
71fccc298df6a1540d408151a26aa22beed55d0bnd return -1;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss = &ap_scoreboard_image->servers[child_num][thread_num];
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if ((status == SERVER_READY || status == SERVER_ACCEPTING)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ss->thread_num = child_num * HARD_SERVER_LIMIT + thread_num;
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Reset individual counters
71fccc298df6a1540d408151a26aa22beed55d0bnd apr_cpystrn(ss->client, ap_get_remote_host(c, r->per_dir_config,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_cpystrn(ss->request, r->the_request, sizeof(ss->request));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Don't reveal the password in the server-status view */
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd apr_cpystrn(ss->request, apr_pstrcat(r->pool, r->method, " ",
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ap_unparse_uri_components(r->pool, &r->parsed_uri, UNP_OMITPASSWORD),
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndvoid ap_time_process_request(int child_num, int thread_num, int status)