From 07fb6d511854e911edfee0bd240e8182f223b53c Mon Sep 17 00:00:00 2001 From: Manoj Kasichainula Date: Fri, 27 Aug 1999 22:16:18 +0000 Subject: [PATCH] Some cleanups. Among other things: - The scoreboard is gond, so we don't call it that anymore - We were accessing the child table through a weird combination of wrappers and direct access; just switch to direct access and get rid of scoreboard.[ch] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83820 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/dexter/dexter.c | 71 ++++++++++++++++--------- server/mpm/dexter/scoreboard.c | 45 ---------------- server/mpm/dexter/scoreboard.h | 94 ---------------------------------- 3 files changed, 47 insertions(+), 163 deletions(-) delete mode 100644 server/mpm/dexter/scoreboard.c delete mode 100644 server/mpm/dexter/scoreboard.h diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index cbbf0a6ba5..92ea865e4f 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -67,8 +67,8 @@ #include "unixd.h" #include "iol_socket.h" #include "ap_listen.h" -#include "scoreboard.h" #include "acceptlock.h" +#include "mpm_default.h" #include #include @@ -90,6 +90,16 @@ static int requests_this_child; static int num_listenfds = 0; static struct pollfd *listenfds; +/* Table of child status */ +#define SERVER_DEAD 0 +#define SERVER_DYING 1 +#define SERVER_ALIVE 2 + +static struct { + pid_t pid; + unsigned char status; +} child_table[HARD_SERVER_LIMIT]; + #if 0 #define SAFE_ACCEPT(stmt) do {if (ap_listeners->next != NULL) {stmt;}} while (0) #else @@ -99,7 +109,7 @@ static struct pollfd *listenfds; /* * The max child slot ever assigned, preserved across restarts. Necessary * to deal with NumServers changes across SIGWINCH restarts. We use this - * value to optimize routines that have to scan the entire scoreboard. + * value to optimize routines that have to scan the entire child table. * * XXX - It might not be worth keeping this code in. There aren't very * many child processes in this MPM. @@ -134,7 +144,7 @@ int raise_sigstop_flags; #endif #ifdef HAS_OTHER_CHILD -/* used to maintain list of children which aren't part of the scoreboard */ +/* used to maintain list of children which aren't part of the child table */ typedef struct other_child_rec other_child_rec; struct other_child_rec { other_child_rec *next; @@ -317,14 +327,16 @@ static void reclaim_child_processes(int terminate) /* now see who is done */ not_dead_yet = 0; for (i = 0; i < max_daemons_limit; ++i) { - int pid = ap_scoreboard_image[i].pid; + int pid; - if (ap_scoreboard_image[i].status == SERVER_DEAD) + if (child_table[i].status == SERVER_DEAD) continue; + pid = child_table[i].pid; + waitret = waitpid(pid, &status, WNOHANG); if (waitret == pid || waitret == -1) { - ap_scoreboard_image[i].status = SERVER_DEAD; + child_table[i].status = SERVER_DEAD; continue; } ++not_dead_yet; @@ -1048,15 +1060,14 @@ static int make_child(server_rec *s, int slot, time_t now) /* ZZZ */ { int pid; - (void) ap_update_child_status(slot, SERVER_ALIVE); - if (slot + 1 > max_daemons_limit) { max_daemons_limit = slot + 1; } if (one_process) { set_signals(); - ap_scoreboard_image[slot].pid = getpid(); + child_table[slot].pid = getpid(); + child_table[slot].status = SERVER_ALIVE; child_main(slot); } @@ -1093,7 +1104,9 @@ static int make_child(server_rec *s, int slot, time_t now) /* ZZZ */ return 0; } /* else */ - ap_scoreboard_image[slot].pid = pid; + child_table[slot].pid = pid; + child_table[slot].status = SERVER_ALIVE; + return 0; } @@ -1103,7 +1116,7 @@ static int startup_children(int number_to_start) int i; for (i = 0; number_to_start && i < num_daemons; ++i) { - if (ap_scoreboard_image[i].status != SERVER_DEAD) { + if (child_table[i].status != SERVER_DEAD) { continue; } if (make_child(server_conf, i, 0) < 0) { @@ -1141,14 +1154,13 @@ static void perform_child_maintenance(void) ap_check_signals(); for (i = 0; i < num_daemons; ++i) { - unsigned char status = ap_scoreboard_image[i].status; - - if (status == SERVER_DEAD) { + if (child_table[i].status == SERVER_DEAD) { if (free_length < spawn_rate) { free_slots[free_length] = i; ++free_length; } - } else { + } + else { last_non_dead = i; } @@ -1182,16 +1194,23 @@ static void server_main_loop(int remaining_children_to_start) int child_slot; ap_wait_t status; int pid; + int i; while (!restart_pending && !shutdown_pending) { pid = wait_or_timeout(&status); if (pid >= 0) { process_child_status(pid, status); - /* non-fatal death... note that it's gone in the scoreboard. */ - child_slot = find_child_by_pid(pid); + /* non-fatal death... note that it's gone in the child table. */ + child_slot = -1; + for (i = 0; i < max_daemons_limit; ++i) { + if (child_table[i].pid == pid) { + child_slot = i; + break; + } + } if (child_slot >= 0) { - ap_update_child_status(child_slot, SERVER_DEAD); + child_table[child_slot].status = SERVER_DEAD; if (remaining_children_to_start && child_slot < num_daemons) { @@ -1210,9 +1229,9 @@ static void server_main_loop(int remaining_children_to_start) } else if (is_graceful) { /* Great, we've probably just lost a slot in the - * scoreboard. Somehow we don't know about this - * child. - */ + * child table. Somehow we don't know about this + * child. + */ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, server_conf, "long lost child came home! (pid %d)", pid); } @@ -1244,6 +1263,7 @@ static void server_main_loop(int remaining_children_to_start) int ap_mpm_run(pool *_pconf, pool *plog, server_rec *s) { int remaining_children_to_start; + int i; pconf = _pconf; server_conf = s; @@ -1270,8 +1290,11 @@ int ap_mpm_run(pool *_pconf, pool *plog, server_rec *s) } ap_log_pid(pconf, ap_pid_fname); SAFE_ACCEPT(accept_mutex_init(pconf, 1)); + /* Initialize the child table */ if (!is_graceful) { - reinit_scoreboard(pconf); + for (i = 0; i < HARD_SERVER_LIMIT; i++) { + child_table[i].status = SERVER_DEAD; + } } set_signals(); @@ -1350,8 +1373,8 @@ int ap_mpm_run(pool *_pconf, pool *plog, server_rec *s) */ for (i = 0; i < num_daemons; ++i) { - if (ap_scoreboard_image[i].status != SERVER_DEAD) { - ap_scoreboard_image[i].status = SERVER_DYING; + if (child_table[i].status != SERVER_DEAD) { + child_table[i].status = SERVER_DYING; } } /* give the children the signal to die */ diff --git a/server/mpm/dexter/scoreboard.c b/server/mpm/dexter/scoreboard.c deleted file mode 100644 index 54a3ff0295..0000000000 --- a/server/mpm/dexter/scoreboard.c +++ /dev/null @@ -1,45 +0,0 @@ -#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 "dexter.h" -#include "scoreboard.h" - -scoreboard ap_scoreboard_image[HARD_SERVER_LIMIT]; - -void reinit_scoreboard(pool *p) -{ - int i; - - for (i = 0; i < HARD_SERVER_LIMIT; i++) { - ap_scoreboard_image[i].status = SERVER_DEAD; - ap_scoreboard_image[i].pid = 0; - } -} - -API_EXPORT(int) find_child_by_pid(int pid) -{ - int i; - - for (i = 0; i < max_daemons_limit; ++i) - if (ap_scoreboard_image[i].pid == pid) - return i; - - return -1; -} - -int ap_update_child_status(int child_num, int status) -{ - int old_status; - - if (child_num < 0) - return -1; - - old_status = ap_scoreboard_image[child_num].status; - ap_scoreboard_image[child_num].status = status; - - return old_status; -} diff --git a/server/mpm/dexter/scoreboard.h b/server/mpm/dexter/scoreboard.h deleted file mode 100644 index 151f8374d6..0000000000 --- a/server/mpm/dexter/scoreboard.h +++ /dev/null @@ -1,94 +0,0 @@ -/* ==================================================================== - * Copyright (c) 1995-1999 The Apache Group. 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 - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/)." - * - * 4. The names "Apache Server" and "Apache Group" 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 names without prior written - * permission of the Apache Group. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the Apache Group - * for use in the Apache HTTP server project (http://www.apache.org/)." - * - * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``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 GROUP 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 Group and was originally based - * on public domain software written at the National Center for - * Supercomputing Applications, University of Illinois, Urbana-Champaign. - * For more information on the Apache Group and the Apache HTTP server - * project, please see . - * - */ - -#ifndef APACHE_SCOREBOARD_H -#define APACHE_SCOREBOARD_H -#ifdef __cplusplus -extern "C" { -#endif - -#include "mpm_default.h" /* For HARD_.*_LIMIT */ - -/* Scoreboard info on a process is, for now, kept very brief --- - * just status value and pid (the latter so that the caretaker process - * can properly update the scoreboard when a process dies). - * - * Status values: - */ - -#define SERVER_DEAD 0 -#define SERVER_ALIVE 1 /* Waiting for connection (or accept() lock) */ -#define SERVER_DYING 2 /* Waiting for connection (or accept() lock) */ -#define SERVER_NUM_STATUS 3 /* number of status settings */ - -typedef struct { - pid_t pid; - unsigned char status; -} scoreboard; - -void reinit_scoreboard(pool *p); - -API_EXPORT(int) find_child_by_pid(int pid); -int ap_update_child_status(int child_num, int status); - -API_VAR_EXPORT extern scoreboard ap_scoreboard_image[HARD_SERVER_LIMIT]; - -#ifdef __cplusplus -} -#endif - -#endif /* !APACHE_SCOREBOARD_H */ -- 2.40.0