scoreboard.c revision 8232302b6fc415a7ef743b65754f7d4240a5a95a
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * http://www.apache.org/licenses/LICENSE-2.0
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * Unless required by applicable law or agreed to in writing, software
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * distributed under the License is distributed on an "AS IS" BASIS,
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * See the License for the specific language governing permissions and
71da3cca78eea6010f89b139ecadb79e6d213c4fnd * limitations under the License.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr.h"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein#include "apr_strings.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_portable.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_lib.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define APR_WANT_STRFUNC
952023a04a2f9d51553babd9094fb857f1c97548trawick#include "apr_want.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#if APR_HAVE_SYS_TYPES_H
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include <sys/types.h>
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_config.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "httpd.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_log.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_main.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_core.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_config.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_mpm.h"
99d46a23c6eac800f327b29f8009f7d7da986230trawick
99d46a23c6eac800f327b29f8009f7d7da986230trawick#include "scoreboard.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm/* we know core's module_index is 0 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#undef APLOG_MODULE_INDEX
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE_DATA scoreboard *ap_scoreboard_image = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE_DATA const char *ap_scoreboard_fname = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic ap_scoreboard_e scoreboard_type;
99d46a23c6eac800f327b29f8009f7d7da986230trawick
f4c310fd2555c6faca1f980f00b161eadb089023gsteinconst char * ap_set_scoreboard(cmd_parms *cmd, void *dummy,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
e8f95a682820a599fe41b22977010636be5c2717jim if (err != NULL) {
99d46a23c6eac800f327b29f8009f7d7da986230trawick return err;
99d46a23c6eac800f327b29f8009f7d7da986230trawick }
5b03ba47ff7225cacb131f14b019332af27da960gstein
5b03ba47ff7225cacb131f14b019332af27da960gstein ap_scoreboard_fname = arg;
5b03ba47ff7225cacb131f14b019332af27da960gstein return NULL;
99d46a23c6eac800f327b29f8009f7d7da986230trawick}
5b03ba47ff7225cacb131f14b019332af27da960gstein
5b03ba47ff7225cacb131f14b019332af27da960gstein/* Default to false when mod_status is not loaded */
5b03ba47ff7225cacb131f14b019332af27da960gsteinAP_DECLARE_DATA int ap_extended_status = 0;
5b03ba47ff7225cacb131f14b019332af27da960gstein
5b03ba47ff7225cacb131f14b019332af27da960gsteinconst char *ap_set_extended_status(cmd_parms *cmd, void *dummy, int arg)
5b03ba47ff7225cacb131f14b019332af27da960gstein{
5b03ba47ff7225cacb131f14b019332af27da960gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
5b03ba47ff7225cacb131f14b019332af27da960gstein if (err != NULL) {
e8f95a682820a599fe41b22977010636be5c2717jim return err;
e8f95a682820a599fe41b22977010636be5c2717jim }
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe ap_extended_status = arg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return NULL;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE_DATA int ap_mod_status_reqtail = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinconst char *ap_set_reqtail(cmd_parms *cmd, void *dummy, int arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (err != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return err;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
691db92094897494d6c31326108da20088bc175etrawick ap_mod_status_reqtail = arg;
691db92094897494d6c31326108da20088bc175etrawick return NULL;
691db92094897494d6c31326108da20088bc175etrawick}
691db92094897494d6c31326108da20088bc175etrawick
691db92094897494d6c31326108da20088bc175etrawick#if APR_HAS_SHARED_MEMORY
691db92094897494d6c31326108da20088bc175etrawick
691db92094897494d6c31326108da20088bc175etrawick#include "apr_shm.h"
691db92094897494d6c31326108da20088bc175etrawick
691db92094897494d6c31326108da20088bc175etrawick#ifndef WIN32
691db92094897494d6c31326108da20088bc175etrawickstatic /* but must be exported to mpm_winnt */
691db92094897494d6c31326108da20088bc175etrawick#endif
691db92094897494d6c31326108da20088bc175etrawick apr_shm_t *ap_scoreboard_shm = NULL;
691db92094897494d6c31326108da20088bc175etrawick
691db92094897494d6c31326108da20088bc175etrawick#endif
691db92094897494d6c31326108da20088bc175etrawick
691db92094897494d6c31326108da20088bc175etrawickAPR_HOOK_STRUCT(
691db92094897494d6c31326108da20088bc175etrawick APR_HOOK_LINK(pre_mpm)
691db92094897494d6c31326108da20088bc175etrawick)
691db92094897494d6c31326108da20088bc175etrawick
691db92094897494d6c31326108da20088bc175etrawickAP_IMPLEMENT_HOOK_RUN_ALL(int,pre_mpm,
691db92094897494d6c31326108da20088bc175etrawick (apr_pool_t *p, ap_scoreboard_e sb_type),
691db92094897494d6c31326108da20088bc175etrawick (p, sb_type),OK,DECLINED)
691db92094897494d6c31326108da20088bc175etrawick
691db92094897494d6c31326108da20088bc175etrawickstatic APR_OPTIONAL_FN_TYPE(ap_logio_get_last_bytes)
e8f95a682820a599fe41b22977010636be5c2717jim *pfn_ap_logio_get_last_bytes;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstruct ap_sb_handle_t {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int child_num;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int thread_num;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe};
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic int server_limit, thread_limit;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic apr_size_t scoreboard_size;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ToDo:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * This function should be renamed to cleanup_shared
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and it should handle cleaning up a scoreboard shared
e8f95a682820a599fe41b22977010636be5c2717jim * between processes using any form of IPC (file, shared memory
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * segment, etc.). Leave it as is now because it is being used
f4c310fd2555c6faca1f980f00b161eadb089023gstein * by various MPMs.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_status_t ap_cleanup_shared_mem(void *d)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAS_SHARED_MEMORY
f4c310fd2555c6faca1f980f00b161eadb089023gstein free(ap_scoreboard_image);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_shm_destroy(ap_scoreboard_shm);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#endif
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return APR_SUCCESS;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_calc_scoreboard_size(void)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein scoreboard_size = sizeof(global_score);
f4c310fd2555c6faca1f980f00b161eadb089023gstein scoreboard_size += sizeof(process_score) * server_limit;
f4c310fd2555c6faca1f980f00b161eadb089023gstein scoreboard_size += sizeof(worker_score) * server_limit * thread_limit;
e8f95a682820a599fe41b22977010636be5c2717jim
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe pfn_ap_logio_get_last_bytes = APR_RETRIEVE_OPTIONAL_FN(ap_logio_get_last_bytes);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return scoreboard_size;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(void) ap_init_scoreboard(void *shared_score)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
e8f95a682820a599fe41b22977010636be5c2717jim char *more_storage;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
58fd79b56eb624bf011772994e9761d3c2e228c1orlikowski ap_calc_scoreboard_size();
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image =
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *));
f4c310fd2555c6faca1f980f00b161eadb089023gstein more_storage = shared_score;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->global = (global_score *)more_storage;
f4c310fd2555c6faca1f980f00b161eadb089023gstein more_storage += sizeof(global_score);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->parent = (process_score *)more_storage;
f4c310fd2555c6faca1f980f00b161eadb089023gstein more_storage += sizeof(process_score) * server_limit;
e8f95a682820a599fe41b22977010636be5c2717jim ap_scoreboard_image->servers =
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe (worker_score **)((char*)ap_scoreboard_image + sizeof(scoreboard));
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < server_limit; i++) {
58fd79b56eb624bf011772994e9761d3c2e228c1orlikowski ap_scoreboard_image->servers[i] = (worker_score *)more_storage;
f4c310fd2555c6faca1f980f00b161eadb089023gstein more_storage += thread_limit * sizeof(worker_score);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_assert(more_storage == (char*)shared_score + scoreboard_size);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->global->server_limit = server_limit;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->global->thread_limit = thread_limit;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
e8f95a682820a599fe41b22977010636be5c2717jim
e8f95a682820a599fe41b22977010636be5c2717jim/**
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * Create a name-based scoreboard in the given pool using the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * given filename.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic apr_status_t create_namebased_scoreboard(apr_pool_t *pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *fname)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAS_SHARED_MEMORY
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The shared memory file must not exist before we create the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * segment. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_shm_remove(fname, pool); /* ignore errors */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv != APR_SUCCESS) {
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, APLOGNO(00001)
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz "unable to create or access scoreboard \"%s\" "
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz "(name-based shared memory failure)", fname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* APR_HAS_SHARED_MEMORY */
91644a5f4d3e992dc208304b50e80bbb236fca89trawick return APR_SUCCESS;
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ToDo: This function should be made to handle setting up
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a scoreboard shared between processes using any IPC technique,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * not just a shared memory segment
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowestatic apr_status_t open_scoreboard(apr_pool_t *pconf)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe#if APR_HAS_SHARED_MEMORY
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *fname = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_t *global_pool;
48f35e10f195dd594d75738fc536bb885eda537cgstein
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* We don't want to have to recreate the scoreboard after
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe * restarts, so we'll create a global pool and never clean it.
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_pool_create(&global_pool, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv != APR_SUCCESS) {
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, APLOGNO(00002)
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Fatal error: unable to create global pool "
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe "for use by the scoreboard");
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return rv;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe /* The config says to create a name-based shmem */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_scoreboard_fname) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* make sure it's an absolute pathname */
48f35e10f195dd594d75738fc536bb885eda537cgstein fname = ap_runtime_dir_relative(pconf, ap_scoreboard_fname);
48f35e10f195dd594d75738fc536bb885eda537cgstein if (!fname) {
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EBADPATH, ap_server_conf, APLOGNO(00003)
48f35e10f195dd594d75738fc536bb885eda537cgstein "Fatal error: Invalid Scoreboard path %s",
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_scoreboard_fname);
48f35e10f195dd594d75738fc536bb885eda537cgstein return APR_EBADPATH;
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein return create_namebased_scoreboard(global_pool, fname);
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein else { /* config didn't specify, we get to choose shmem type */
48f35e10f195dd594d75738fc536bb885eda537cgstein rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, NULL,
48f35e10f195dd594d75738fc536bb885eda537cgstein global_pool); /* anonymous shared memory */
48f35e10f195dd594d75738fc536bb885eda537cgstein if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) {
7b6ba9c468f26bdb3492d5e8cb79628a3b04e8c8wrowe ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, APLOGNO(00004)
48f35e10f195dd594d75738fc536bb885eda537cgstein "Unable to create or access scoreboard "
48f35e10f195dd594d75738fc536bb885eda537cgstein "(anonymous shared memory failure)");
48f35e10f195dd594d75738fc536bb885eda537cgstein return rv;
24efed0910118b762a4eb84830875d4714b8d315ianh }
48f35e10f195dd594d75738fc536bb885eda537cgstein /* Make up a filename and do name-based shmem */
48f35e10f195dd594d75738fc536bb885eda537cgstein else if (rv == APR_ENOTIMPL) {
48f35e10f195dd594d75738fc536bb885eda537cgstein /* Make sure it's an absolute pathname */
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_scoreboard_fname = DEFAULT_SCOREBOARD;
c1b808d160bfb5c849263be8d4acff600853a328trawick fname = ap_runtime_dir_relative(pconf, ap_scoreboard_fname);
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein return create_namebased_scoreboard(global_pool, fname);
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein }
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein }
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein#endif /* APR_HAS_SHARED_MEMORY */
48f35e10f195dd594d75738fc536bb885eda537cgstein return APR_SUCCESS;
48f35e10f195dd594d75738fc536bb885eda537cgstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein/* If detach is non-zero, this is a separate child process,
48f35e10f195dd594d75738fc536bb885eda537cgstein * if zero, it is a forked child.
48f35e10f195dd594d75738fc536bb885eda537cgstein */
48f35e10f195dd594d75738fc536bb885eda537cgsteinAP_DECLARE(apr_status_t) ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm,
48f35e10f195dd594d75738fc536bb885eda537cgstein int detached)
48f35e10f195dd594d75738fc536bb885eda537cgstein{
48f35e10f195dd594d75738fc536bb885eda537cgstein#if APR_HAS_SHARED_MEMORY
48f35e10f195dd594d75738fc536bb885eda537cgstein if (!detached) {
48f35e10f195dd594d75738fc536bb885eda537cgstein return APR_SUCCESS;
48f35e10f195dd594d75738fc536bb885eda537cgstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (apr_shm_size_get(ap_scoreboard_shm) < scoreboard_size) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_CRIT, 0, ap_server_conf, APLOGNO(00005)
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Fatal error: shared scoreboard too small for child!");
e8f95a682820a599fe41b22977010636be5c2717jim apr_shm_detach(ap_scoreboard_shm);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_shm = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return APR_EINVAL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* everything will be cleared shortly */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (*shm) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein *shm = ap_scoreboard_shm;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein return APR_SUCCESS;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgsteinapr_status_t ap_cleanup_scoreboard(void *d)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (ap_scoreboard_image == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return APR_SUCCESS;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (scoreboard_type == SB_SHARED) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_cleanup_shared_mem(NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein free(ap_scoreboard_image->global);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe free(ap_scoreboard_image);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_scoreboard_image = NULL;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return APR_SUCCESS;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
77c2148c53e0a4a20a80af735caa4e0e6bd448e0gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Create or reinit an existing scoreboard. The MPM can control whether
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the scoreboard is shared across multiple processes or not
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
8b99f2a316c5e2fa6ab208206fdd7fc2bfc4a921dougm int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAS_SHARED_MEMORY
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein pfn_ap_logio_get_last_bytes = APR_RETRIEVE_OPTIONAL_FN(ap_logio_get_last_bytes);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f958dac1550254a59b45f4655138bb34dad5e76egstein if (ap_scoreboard_image) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_scoreboard_image->global->restart_time = apr_time_now();
f4c310fd2555c6faca1f980f00b161eadb089023gstein memset(ap_scoreboard_image->parent, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein sizeof(process_score) * server_limit);
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < server_limit; i++) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein memset(ap_scoreboard_image->servers[i], 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein sizeof(worker_score) * thread_limit);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz ap_calc_scoreboard_size();
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz#if APR_HAS_SHARED_MEMORY
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sb_type == SB_SHARED) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein void *sb_shared;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe rv = open_scoreboard(p);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_INTERNAL_SERVER_ERROR;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein memset(sb_shared, 0, scoreboard_size);
e8f95a682820a599fe41b22977010636be5c2717jim ap_init_scoreboard(sb_shared);
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* A simple malloc will suffice */
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe void *sb_mem = ap_calloc(1, scoreboard_size);
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ap_init_scoreboard(sb_mem);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein scoreboard_type = sb_type;
f39230a531b23d94f86a087963299bbe2e431a4agstein ap_scoreboard_image->global->running_generation = 0;
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe ap_scoreboard_image->global->restart_time = apr_time_now();
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
f39230a531b23d94f86a087963299bbe2e431a4agstein
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe return OK;
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein/* Routines called to deal with the scoreboard image
f39230a531b23d94f86a087963299bbe2e431a4agstein * --- note that we do *not* need write locks, since update_child_status
1e2133fe37e6cbcd683233057ef62236bc8e5826trawick * only updates a *single* record in place, and only one process writes to
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * a given scoreboard slot at a time (either the child process owning that
f39230a531b23d94f86a087963299bbe2e431a4agstein * slot, or the parent, noting that the child has died).
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein *
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * As a final note --- setting the score entry to getpid() is always safe,
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * since when the parent is writing an entry, it's only noting SERVER_DEAD
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * anyway.
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein */
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinAP_DECLARE(int) ap_exists_scoreboard_image(void)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein return (ap_scoreboard_image ? 1 : 0);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein}
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gsteinAP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sb, request_rec *r)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein{
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein worker_score *ws;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein apr_off_t bytes;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein if (!sb)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein ws = &ap_scoreboard_image->servers[sb->child_num][sb->thread_num];
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein if (pfn_ap_logio_get_last_bytes != NULL) {
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein bytes = pfn_ap_logio_get_last_bytes(r->connection);
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein }
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein else if (r->method_number == M_GET && r->method[0] == 'H') {
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein bytes = 0;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein }
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein else {
f39230a531b23d94f86a087963299bbe2e431a4agstein bytes = r->bytes_sent;
f39230a531b23d94f86a087963299bbe2e431a4agstein }
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein#ifdef HAVE_TIMES
f39230a531b23d94f86a087963299bbe2e431a4agstein times(&ws->times);
f39230a531b23d94f86a087963299bbe2e431a4agstein#endif
f39230a531b23d94f86a087963299bbe2e431a4agstein ws->access_count++;
f39230a531b23d94f86a087963299bbe2e431a4agstein ws->my_access_count++;
f39230a531b23d94f86a087963299bbe2e431a4agstein ws->conn_count++;
f39230a531b23d94f86a087963299bbe2e431a4agstein ws->bytes_served += bytes;
f39230a531b23d94f86a087963299bbe2e431a4agstein ws->my_bytes_served += bytes;
f39230a531b23d94f86a087963299bbe2e431a4agstein ws->conn_bytes += bytes;
f39230a531b23d94f86a087963299bbe2e431a4agstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinAP_DECLARE(int) ap_find_child_by_pid(apr_proc_t *pid)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein int i;
f39230a531b23d94f86a087963299bbe2e431a4agstein int max_daemons_limit;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein for (i = 0; i < max_daemons_limit; ++i) {
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein if (ap_scoreboard_image->parent[i].pid == pid->pid) {
f39230a531b23d94f86a087963299bbe2e431a4agstein return i;
f39230a531b23d94f86a087963299bbe2e431a4agstein }
f39230a531b23d94f86a087963299bbe2e431a4agstein }
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein return -1;
f39230a531b23d94f86a087963299bbe2e431a4agstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinAP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
f39230a531b23d94f86a087963299bbe2e431a4agstein int child_num, int thread_num)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein *new_sbh = (ap_sb_handle_t *)apr_palloc(p, sizeof(ap_sb_handle_t));
f39230a531b23d94f86a087963299bbe2e431a4agstein (*new_sbh)->child_num = child_num;
f39230a531b23d94f86a087963299bbe2e431a4agstein (*new_sbh)->thread_num = thread_num;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein}
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gsteinstatic void copy_request(char *rbuf, apr_size_t rbuflen, request_rec *r)
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein{
6810bf1570bed88d16239b27ce47d48408bb2e51gstein char *p;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein if (r->the_request == NULL) {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein apr_cpystrn(rbuf, "NULL", rbuflen);
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein return; /* short circuit below */
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein }
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein if (r->parsed_uri.password == NULL) {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein p = r->the_request;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein }
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein else {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein /* Don't reveal the password in the server-status view */
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein p = apr_pstrcat(r->pool, r->method, " ",
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein apr_uri_unparse(r->pool, &r->parsed_uri,
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein APR_URI_UNP_OMITPASSWORD),
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein r->assbackwards ? NULL : " ", r->protocol, NULL);
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein }
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein /* now figure out if we copy over the 1st rbuflen chars or the last */
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein if (!ap_mod_status_reqtail) {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein apr_cpystrn(rbuf, p, rbuflen);
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein }
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein else {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein apr_size_t slen = strlen(p);
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein if (slen < rbuflen) {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein /* it all fits anyway */
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein apr_cpystrn(rbuf, p, rbuflen);
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein }
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein else {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein apr_cpystrn(rbuf, p+(slen-rbuflen+1), rbuflen);
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein }
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein }
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein}
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gsteinstatic int update_child_status_internal(int child_num,
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein int thread_num,
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein int status,
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein conn_rec *c,
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein request_rec *r)
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein{
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein int old_status;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein worker_score *ws;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein process_score *ps;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein int mpm_generation;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ws = &ap_scoreboard_image->servers[child_num][thread_num];
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein old_status = ws->status;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ws->status = status;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ps = &ap_scoreboard_image->parent[child_num];
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein if (status == SERVER_READY
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein && old_status == SERVER_STARTING) {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ws->thread_num = child_num * thread_limit + thread_num;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ap_mpm_query(AP_MPMQ_GENERATION, &mpm_generation);
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ps->generation = mpm_generation;
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein }
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein
0946f90438dcf29a5fe5d9e21559b3b9d640bc12wrowe if (ap_extended_status) {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein ws->last_used = apr_time_now();
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein if (status == SERVER_READY || status == SERVER_DEAD) {
b5989e567e4fac5b3ab1252024ae19b0a54893a7gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Reset individual counters
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == SERVER_DEAD) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->my_access_count = 0L;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->my_bytes_served = 0L;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->conn_count = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->conn_bytes = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ws->client, ap_get_remote_host(c, r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein REMOTE_NOLOOKUP, NULL), sizeof(ws->client));
f4c310fd2555c6faca1f980f00b161eadb089023gstein copy_request(ws->request, sizeof(ws->request), r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->server) {
0206c121a68a63559b2e843288e81bcf16093e46jerenkrantz apr_snprintf(ws->vhost, sizeof(ws->vhost), "%s:%d",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->server->server_hostname,
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->connection->local_addr->port);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm else if (c) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_cpystrn(ws->client, ap_get_remote_host(c, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein REMOTE_NOLOOKUP, NULL), sizeof(ws->client));
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe ws->request[0]='\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->vhost[0]='\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return old_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wroweAP_DECLARE(int) ap_update_child_status_from_indexes(int child_num,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int thread_num,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe int status,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe request_rec *r)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (child_num < 0) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return -1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return update_child_status_internal(child_num, thread_num, status,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe r ? r->connection : NULL,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status,
f4c310fd2555c6faca1f980f00b161eadb089023gstein request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!sbh)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return -1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return update_child_status_internal(sbh->child_num, sbh->thread_num,
f4c310fd2555c6faca1f980f00b161eadb089023gstein status,
f4c310fd2555c6faca1f980f00b161eadb089023gstein r ? r->connection : NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
6f15570e3adc0faf87bf55f70857028276fc9e32wroweAP_DECLARE(int) ap_update_child_status_from_conn(ap_sb_handle_t *sbh, int status,
f4c310fd2555c6faca1f980f00b161eadb089023gstein conn_rec *c)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!sbh)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return -1;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein return update_child_status_internal(sbh->child_num, sbh->thread_num,
f4c310fd2555c6faca1f980f00b161eadb089023gstein status, c, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(void) ap_time_process_request(ap_sb_handle_t *sbh, int status)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein worker_score *ws;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!sbh)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe if (sbh->child_num < 0) {
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return;
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws = &ap_scoreboard_image->servers[sbh->child_num][sbh->thread_num];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (status == START_PREQUEST) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ws->start_time = apr_time_now();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (status == STOP_PREQUEST) {
e8f95a682820a599fe41b22977010636be5c2717jim ws->stop_time = apr_time_now();
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
6f15570e3adc0faf87bf55f70857028276fc9e32wroweAP_DECLARE(worker_score *) ap_get_scoreboard_worker_from_indexes(int x, int y)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe{
42f2b4b0e9b84dfd8acbb9c0da18a07c664e30a1jorton if (((x < 0) || (x >= server_limit)) ||
42f2b4b0e9b84dfd8acbb9c0da18a07c664e30a1jorton ((y < 0) || (y >= thread_limit))) {
42f2b4b0e9b84dfd8acbb9c0da18a07c664e30a1jorton return(NULL); /* Out of range */
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz }
42f2b4b0e9b84dfd8acbb9c0da18a07c664e30a1jorton return &ap_scoreboard_image->servers[x][y];
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz}
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantzAP_DECLARE(worker_score *) ap_get_scoreboard_worker(ap_sb_handle_t *sbh)
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz{
5a8f3bcf803321e69b226d3b98314305a68a586cjerenkrantz if (!sbh)
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe return NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_get_scoreboard_worker_from_indexes(sbh->child_num,
6f15570e3adc0faf87bf55f70857028276fc9e32wrowe sbh->thread_num);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(process_score *) ap_get_scoreboard_process(int x)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((x < 0) || (x >= server_limit)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return(NULL); /* Out of range */
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return &ap_scoreboard_image->parent[x];
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(global_score *) ap_get_scoreboard_global()
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_scoreboard_image->global;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein