scoreboard.c revision 404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004b
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
#include "ap_config.h"
#include "httpd.h"
#include "http_log.h"
#include "http_main.h"
#include "http_core.h"
#include "http_config.h"
#include "unixd.h"
#include "http_conf_globals.h"
#include "mpm_status.h"
#include "scoreboard.h"
#include "dexter.h" /* for max_daemons_limit */
#ifdef USE_SHMGET_SCOREBOARD
#endif
#ifdef USE_OS2_SCOREBOARD
/* Add MMAP style functionality to OS/2 */
#define INCL_DOSMEMMGR
#define INCL_DOSEXCEPTIONS
#define INCL_DOSSEMAPHORES
#include <os2.h>
#include <umalloc.h>
#include <stdio.h>
#endif
/*****************************************************************
*
* Dealing with the scoreboard... a lot of these variables are global
* only to avoid getting clobbered by the longjmp() that happens when
* a hard timeout expires...
*
* We begin with routines which deal with the file itself...
*/
#if defined(USE_OS2_SCOREBOARD)
/* The next two routines are used to access shared memory under OS/2. */
/* This requires EMX v09c to be installed. */
{
void *mem;
Heap_t h;
if (rc != 0)
return NULL;
if (h == NULL)
return (caddr_t) h;
}
{
the shared memory object */
of the shared memory object */
/* Request read and write access to */
/* the shared memory object */
if (rc != 0) {
return 0;
}
return BaseAddress;
}
static void setup_shared_mem(ap_pool_t *p)
{
caddr_t m;
int rc;
if (m == 0) {
"%s: Could not create OS/2 Shared memory pool.",
}
if (rc != 0) {
"%s: Could not uopen() newly created OS/2 Shared memory pool.",
}
ap_scoreboard_image = (scoreboard *) m;
}
{
caddr_t m;
int rc;
if (m == 0) {
"%s: Could not find existing OS/2 Shared memory pool.",
}
ap_scoreboard_image = (scoreboard *) m;
}
#elif defined(USE_POSIX_SCOREBOARD)
/*
* POSIX 1003.4 style
*
* Note 1:
* where no subdirectories allowed.
*
* POSIX shm_open() and shm_unlink() will take care about this issue,
* but to avoid confusion, I suggest to redefine scoreboard file name
* in httpd.conf to cut "logs/" from it. With default setup actual name
* will be "/dev/shmem/logs.apache_status".
*
* If something went wrong and Apache did not unlinked this object upon
* exit, you can remove it manually, using "rm -f" command.
*
* Note 2:
* does NOT support BSD style anonymous mapping. So, the order of
* conditional compilation is important:
* this #ifdef section must be ABOVE the next one (BSD style).
*
* I tested this stuff and it works fine for me, but if it provides
* trouble for you, just comment out USE_MMAP_SCOREBOARD in QNX section
* of ap_config.h
*
* June 5, 1997,
* Igor N. Kovalenko -- infoh@mail.wplus.net
*/
static void cleanup_shared_mem(void *d)
{
}
static void setup_shared_mem(ap_pool_t *p)
{
char buf[512];
caddr_t m;
int fd;
if (fd == -1) {
}
}
}
ap_scoreboard_image = (scoreboard *) m;
}
{
}
#elif defined(USE_MMAP_SCOREBOARD)
static void setup_shared_mem(ap_pool_t *p)
{
caddr_t m;
#if defined(MAP_ANON)
/* BSD style */
#ifdef CONVEXOS11
/*
* 9-Aug-97 - Jeff Venters (venters@convex.hp.com)
* ConvexOS maps address space as follows:
* 0x00000000 - 0x7fffffff : Kernel
* 0x80000000 - 0xffffffff : User
* Start mmapped area 1GB above start of text.
*
* Also, the length requires a pointer as the actual length is
* returned (rounded up to a page boundary).
*/
{
unsigned len = SCOREBOARD_SIZE;
}
#elif defined(MAP_TMPFILE)
{
char mfile[] = "/tmp/apache_shmem_XXXX";
if (fd == -1) {
perror("open");
}
if (m == (caddr_t) - 1) {
perror("mmap");
}
}
#else
#endif
if (m == (caddr_t) - 1) {
perror("mmap");
"%s: Could not mmap memory", ap_server_argv0);
}
#else
/* Sun style */
int fd;
if (fd == -1) {
perror("open");
"%s: Could not open /dev/zero", ap_server_argv0);
}
if (m == (caddr_t) - 1) {
perror("mmap");
"%s: Could not mmap /dev/zero", ap_server_argv0);
}
#endif
ap_scoreboard_image = (scoreboard *) m;
}
{
}
#elif defined(USE_SHMGET_SCOREBOARD)
static int shmid = -1;
static void setup_shared_mem(ap_pool_t *p)
{
#ifdef MOVEBREAK
char *obrk;
#endif
#ifdef LINUX
"Your kernel was built without CONFIG_SYSVIPC\n"
"%s: Please consult the Apache FAQ for details",
}
#endif
"could not call shmget");
}
"created shared memory segment #%d", shmid);
#ifdef MOVEBREAK
/*
* Some SysV systems place the shared segment WAY too close
* to the dynamic memory break point (sbrk(0)). This severely
* refuse to move past that point.
*
* To get around this, we move the break point "way up there",
* attach the segment and then move break back down. Ugly
*/
"sbrk() could not move break");
}
#endif
"shmat error");
/*
* We exit below, after we try to remove the segment
*/
}
else { /* only worry about permissions if we attached the segment */
"shmctl() could not stat segment #%d", shmid);
}
else {
"shmctl() could not set segment #%d", shmid);
}
}
}
/*
* We must avoid leaving segments in the kernel's
* (small) tables.
*/
"shmctl: IPC_RMID: could not remove shared memory segment #%d",
shmid);
}
#ifdef MOVEBREAK
if (obrk == (char *) -1)
return; /* nothing else to do */
"sbrk() could not move break back");
}
#endif
}
{
}
#endif
/* Called by parent process */
void reinit_scoreboard(ap_pool_t *p)
{
if (ap_scoreboard_image == NULL) {
setup_shared_mem(p);
}
}
/****
* Above code is shmem code. Below code is interacting with the shmem
****/
static int maintain_connection_status = 1;
void ap_dexter_set_maintain_connection_status(int flag) {
return;
}
/* Useful to erase the status of children that might be from previous
* generations */
void ap_dexter_force_reset_connection_status(long conn_id)
{
int i;
for (i = 0; i < STATUSES_PER_CONNECTION; i++) {
}
}
void ap_reset_connection_status(long conn_id)
{
if (maintain_connection_status) {
}
}
/* Don't mess with the string you get back from this function */
{
int i = 0;
if (!maintain_connection_status) return "";
while (i < STATUSES_PER_CONNECTION) {
break;
}
}
}
return NULL;
}
{
int i;
long *array_slot;
connection_list = ap_make_array(p, 0, sizeof(long));
/* We assume that there is a connection iff it has an entry in the status
* table. Connections without any status sound problematic to me, so this
* is probably for the best. - manoj */
for (i = 0; i < max_daemons_limit*HARD_THREAD_LIMIT; i++) {
*array_slot = i;
}
}
return connection_list;
}
{
int i = 0;
char **array_slot;
while (i < STATUSES_PER_CONNECTION) {
break;
}
i++;
}
return key_list;
}
/* Note: no effort is made here to prevent multiple threads from messing with
* a single connection at the same time. ap_update_connection_status should
* only be called by the thread that owns the connection */
const char *value)
{
int i = 0;
if (!maintain_connection_status) return;
while (i < STATUSES_PER_CONNECTION) {
break;
}
return;
}
i++;
}
/* Not found. Add an entry for this value */
if (i >= STATUSES_PER_CONNECTION) {
/* No room. Oh well, not much anyone can do about it. */
return;
}
return;
}
{
int i, j;
/* Go ahead and return what's in the connection status table even if we
* aren't maintaining it. We can at least look at what children from
* previous generations are up to. */
for (i = 0; i < max_daemons_limit*HARD_THREAD_LIMIT; i++) {
continue;
array_slot->conn_id = i;
for (j = 0; j < STATUSES_PER_CONNECTION; j++) {
}
else {
break;
}
}
}
return server_status;
}