scoreboard.c revision 842ae4bd224140319ae7feec1872b93dfd491143
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_lib.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#endif
#include "ap_config.h"
#include "httpd.h"
#include "http_log.h"
#include "http_main.h"
#include "http_core.h"
#include "http_config.h"
#include "ap_mpm.h"
#include "mpm.h"
#include "scoreboard.h"
AP_DECLARE_DATA int ap_extended_status = 0;
#include "apr_shm.h"
#ifndef WIN32
static /* but must be exported to mpm_winnt */
#endif
#endif
)
struct ap_sb_handle_t {
int child_num;
int thread_num;
};
static apr_size_t scoreboard_size;
/*
* ToDo:
* This function should be renamed to cleanup_shared
* and it should handle cleaning up a scoreboard shared
* between processes using any form of IPC (file, shared memory
* segment, etc.). Leave it as is now because it is being used
* by various MPMs.
*/
static apr_status_t ap_cleanup_shared_mem(void *d)
{
#endif
return APR_SUCCESS;
}
AP_DECLARE(int) ap_calc_scoreboard_size(void)
{
if (!proxy_lb_workers)
if (proxy_lb_workers)
lb_limit = proxy_lb_workers();
else
lb_limit = 0;
scoreboard_size = sizeof(global_score);
if (lb_limit)
return scoreboard_size;
}
void ap_init_scoreboard(void *shared_score)
{
char *more_storage;
int i;
more_storage += sizeof(global_score);
for (i = 0; i < server_limit; i++) {
}
if (lb_limit) {
}
}
/**
* Create a name-based scoreboard in the given pool using the
* given filename.
*/
const char *fname)
{
/* The shared memory file must not exist before we create the
* segment. */
if (rv != APR_SUCCESS) {
"unable to create scoreboard \"%s\" "
"(name-based shared memory failure)", fname);
return rv;
}
#endif /* APR_HAS_SHARED_MEMORY */
return APR_SUCCESS;
}
/* ToDo: This function should be made to handle setting up
* a scoreboard shared between processes using any IPC technique,
* not just a shared memory segment
*/
{
/* We don't want to have to recreate the scoreboard after
* restarts, so we'll create a global pool and never clean it.
*/
if (rv != APR_SUCCESS) {
"Fatal error: unable to create global pool "
"for use by the scoreboard");
return rv;
}
/* The config says to create a name-based shmem */
if (ap_scoreboard_fname) {
/* make sure it's an absolute pathname */
if (!fname) {
"Fatal error: Invalid Scoreboard path %s",
return APR_EBADPATH;
}
}
else { /* config didn't specify, we get to choose shmem type */
global_pool); /* anonymous shared memory */
"Unable to create scoreboard "
"(anonymous shared memory failure)");
return rv;
}
/* Make up a filename and do name-based shmem */
else if (rv == APR_ENOTIMPL) {
/* Make sure it's an absolute pathname */
}
}
#endif /* APR_HAS_SHARED_MEMORY */
return APR_SUCCESS;
}
/* If detach is non-zero, this is a seperate child process,
* if zero, it is a forked child.
*/
{
if (!detached) {
return APR_SUCCESS;
}
"Fatal error: shared scoreboard too small for child!");
return APR_EINVAL;
}
/* everything will be cleared shortly */
if (*shm) {
*shm = ap_scoreboard_shm;
}
#endif
return APR_SUCCESS;
}
apr_status_t ap_cleanup_scoreboard(void *d)
{
if (ap_scoreboard_image == NULL) {
return APR_SUCCESS;
}
}
else {
}
return APR_SUCCESS;
}
/* Create or reinit an existing scoreboard. The MPM can control whether
* the scoreboard is shared across multiple processes or not
*/
{
int running_gen = 0;
int i;
#endif
if (ap_scoreboard_image) {
sizeof(process_score) * server_limit);
for (i = 0; i < server_limit; i++) {
sizeof(worker_score) * thread_limit);
}
/* Clean up the lb workers data */
if (lb_limit) {
}
return OK;
}
void *sb_shared;
rv = open_scoreboard(p);
return HTTP_INTERNAL_SERVER_ERROR;
}
}
else
#endif
{
/* A simple malloc will suffice */
"(%d)%s: cannot allocate scoreboard",
return HTTP_INTERNAL_SERVER_ERROR;
}
}
return OK;
}
/* Routines called to deal with the scoreboard image
* --- note that we do *not* need write locks, since update_child_status
* only updates a *single* record in place, and only one process writes to
* a given scoreboard slot at a time (either the child process owning that
* slot, or the parent, noting that the child has died).
*
* As a final note --- setting the score entry to getpid() is always safe,
* since when the parent is writing an entry, it's only noting SERVER_DEAD
* anyway.
*/
AP_DECLARE(int) ap_exists_scoreboard_image(void)
{
return (ap_scoreboard_image ? 1 : 0);
}
{
#ifdef HAVE_TIMES
#endif
ws->access_count++;
ws->my_access_count++;
ws->conn_count++;
}
{
int i;
int max_daemons_limit;
for (i = 0; i < max_daemons_limit; ++i) {
return i;
}
}
return -1;
}
int child_num, int thread_num)
{
}
int thread_num,
int status,
request_rec *r)
{
int old_status;
if (child_num < 0) {
return -1;
}
if (status == SERVER_READY
&& old_status == SERVER_STARTING) {
}
if (ap_extended_status) {
/*
* Reset individual counters
*/
if (status == SERVER_DEAD) {
ws->my_access_count = 0L;
ws->my_bytes_served = 0L;
}
ws->conn_count = 0;
ws->conn_bytes = 0;
}
if (r) {
conn_rec *c = r->connection;
if (r->the_request == NULL) {
} else {
/* Don't reveal the password in the server-status view */
}
}
}
return old_status;
}
request_rec *r)
{
status, r);
}
{
return;
}
if (status == START_PREQUEST) {
}
else if (status == STOP_PREQUEST) {
}
}
{
if (((x < 0) || (x >= server_limit)) ||
((y < 0) || (y >= thread_limit))) {
return(NULL); /* Out of range */
}
return &ap_scoreboard_image->servers[x][y];
}
{
if ((x < 0) || (x >= server_limit)) {
return(NULL); /* Out of range */
}
return &ap_scoreboard_image->parent[x];
}
{
return ap_scoreboard_image->global;
}
{
return(NULL); /* Out of range */
}
}