httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Terbush <ra...@zyzzyva.com>
Subject Patches to be commited
Date Sun, 21 Jul 1996 20:09:56 GMT

I'm going through some patches that have been submitted to
the project. I'll be forwarding these to the list soliciting
votes for inclusion.


------- Forwarded Message

From: Steve Nuchia <steve@research.oknet.com>
Message-Id: <199607021515.KAA04130@research.oknet.com>
Subject: some fixes for apache 1.0
To: apache-bugs@apache.org, problem@bsdi.com
Date: Tue, 2 Jul 1996 10:15:54 -0500 (CDT)
Cc: bsdi-user@bsdi.com
X-Mailer: ELM [version 2.4 PL25]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Here's a patch for apache 1.0 as distributed by BSDI with the 2.1 release.

There are three key things here:

1) Clip the administrative server limit to the compiled-in server limit.
   Otherwise you leak servers if the conf file gives a larger limit than
   the compile-time option.

2) Clear junk bits in the scoreboard entry (by making it come from
   a static variable) and add a leak-detection field.

3) Recode the child-spawning loop so it will
	a) start more than one server per second
	b) not use child numbers >= scoreboard size,
	   eliminating another child leak.

I have been running these patches with >100 virtual sites on a
single server for several months.  (www.sccsi.com)


*** http_core.c	Tue Dec  5 17:32:53 1995
- --- /usr/src/isp/apache/apache_1.0.0/src/http_core.c	Mon Jan 29 19:29:27 1996
***************
*** 61,66 ****
- --- 61,67 ----
  
  #include "http_main.h"		/* For the default_handler below... */
  #include "http_log.h"
+ #include "scoreboard.h"
  
  /* Server core module... This module provides support for really basic
   * server operations, including options and commands which control the
***************
*** 541,546 ****
- --- 542,548 ----
  
  char *set_server_limit (cmd_parms *cmd, void *dummy, char *arg) {
      daemons_limit = atoi (arg);
+     if ( daemons_limit > HARD_SERVER_MAX ) daemons_limit = HARD_SERVER_MAX;
      return NULL;
  }
  
*** http_main.c	Mon Dec 11 10:22:59 1995
- --- /usr/src/isp/apache/apache_1.0.0/src/http_main.c	Mon Jan 29 20:46:17 1996
***************
*** 419,432 ****
  		sizeof(scoreboard_image));
  }
  
! void update_child_status (int child_num, int status)
  {
!     short_score new_score_rec;
!     new_score_rec.pid = getpid();
!     new_score_rec.status = status;
  
      lseek (scoreboard_fd, (long)child_num * sizeof(short_score), 0);
!     force_write (scoreboard_fd, (char*)&new_score_rec, sizeof(short_score));
  }
  
  int count_idle_servers ()
- --- 417,431 ----
  		sizeof(scoreboard_image));
  }
  
! void update_child_status (int child_num, int status, int incr)
  {
!     short_score *my_score = scoreboard_image + child_num;
!     my_score->pid = getpid();
!     my_score->count += incr;
!     my_score->status = status;
  
      lseek (scoreboard_fd, (long)child_num * sizeof(short_score), 0);
!     force_write (scoreboard_fd, (char*)my_score, sizeof(short_score));
  }
  
  int count_idle_servers ()
***************
*** 435,442 ****
      int res = 0;
  
      for (i = 0; i < HARD_SERVER_MAX; ++i)
! 	if (scoreboard_image[i].status == SERVER_READY
! 	  || scoreboard_image[i].status == SERVER_STARTING)
  	    ++res;
  
      return res;
- --- 434,440 ----
      int res = 0;
  
      for (i = 0; i < HARD_SERVER_MAX; ++i)
! 	if (scoreboard_image[i].status == SERVER_READY)
  	    ++res;
  
      return res;
***************
*** 732,743 ****
      struct sockaddr sa_server;
      struct sockaddr sa_client;
  
      csd = -1;
      dupped_csd = -1;
      child_num = child_num_arg;
      requests_this_child = 0;
      reopen_scoreboard (pconf);
!     update_child_status (child_num, SERVER_READY);
  
      /* Only try to switch if we're running as root */
      if(!geteuid() && setuid(user_id) == -1) {
- --- 730,741 ----
      str1ct sockaddr sa_server;
      struct sockaddr sa_client;
  
      csd = -1;
      dupped_csd = -1;
      child_num = child_num_arg;
      requests_this_child = 0;
      reopen_scoreboard (pconf);
!     update_child_status (child_num, SERVER_READY, 0);
  
      /* Only try to switch if we're running as root */
      if(!geteuid() && setuid(user_id) == -1) {
***************
*** 773,779 ****
  	}
  
  	clen=sizeof(sa_client);
! 	update_child_status (child_num, SERVER_READY);
  	
  	accept_mutex_on();  /* Lock around "accept", if necessary */
  	
- --- 777,783 ----
  	}
  
  	clen=sizeof(sa_client);
! 	update_child_status (child_num, SERVER_READY, 0);
  	
  	accept_mutex_on();  /* Lock around "accept", if necessary */
  	
***************
*** 796,802 ****
  	    dupped_csd = csd;	/* Oh well... */
  	}
  #endif
! 	update_child_status (child_num, SERVER_BUSY);
  	conn_in = pfdopen (ptrans, csd, "r");
  	conn_out = pfdopen (ptrans, dupped_csd, "w");
  
- --- 800,806 ----
  	    dupped_csd = csd;	/* Oh well... */
  	}
  #endif
! 	update_child_status (child_num, SERVER_BUSY, 0);
  	conn_in = pfdopen (ptrans, csd, "r");
  	conn_out = pfdopen (ptrans, dupped_csd, "w");
  
***************
*** 834,841 ****
- --- 838,848 ----
  	child_main (child_num);
      }
  
+     update_child_status (child_num, SERVER_BUSY, 1);
+ 
      if ((pid = fork()) == -1) {
  	log_error("Unable to fork new process", server_conf);
+ 	update_child_status (child_num, SERVER_DEAD, -1);
  	return;
      } 
      
***************
*** 946,969 ****
      log_error ("Server configured -- resuming normal operations", server_conf);
      
      while (1) {
! 	int status, child_slot;
  	int pid = wait_or_timeout(&status);
  	
  	if (pid >= 0) {
  	    /* Child died... note that it's gone in the scoreboard. */
  	    sync_scoreboard_image();
  	    child_slot = find_child_by_pid (pid);
! 	    if (child_slot >= 0) update_child_status (child_slot, SERVER_DEAD);
          }
  
  	sync_scoreboard_image();
! 	if ((count_idle_servers() < daemons_min_free)
  	    && (child_slot = find_free_child_num()) >= 0
! 	    && child_slot <= daemons_limit)
! 	    {
! 	    update_child_status(child_slot,SERVER_STARTING);
! 	    make_child(server_conf, child_slot);
! 	    }
      }
  
  } /* standalone_main */
- --- 961,983 ----
      log_error ("Server configured -- resuming normal operations", server_conf);
      
      while (1) {
! 	int status, child_slot, needed;
  	int pid = wait_or_timeout(&status);
  	
  	if (pid >= 0) {
  	    /* Child died... note that it's gone in the scoreboard. */
  	    sync_scoreboard_image();
  	    child_slot = find_child_by_pid (pid);
! 	    if (child_slot >= 0) update_child_status (child_slot, SERVER_DEAD, -1);
! 	    else log_error ("Child not found", server_conf);
          }
  
  	sync_scoreboard_image();
! 	needed = daemons_min_free - count_idle_servers();
! 	while ( needed-- > 0
  	    && (child_slot = find_free_child_num()) >= 0
! 	    && child_slot < daemons_limit )
! 		make_child(server_conf, child_slot);
      }
  
  } /* standalone_main */
*** scoreboard.h	Mon Dec 11 10:23:01 1995
- --- /usr/src/isp/apache/apache_1.0.0/src/scoreboard.h	Mon Jan 29 20:40:09 1996
***************
*** 65,74 ****
  #define SERVER_DEAD 0		/* Unused scoreboard entry */
  #define SERVER_READY 1		/* Waiting for connection (or accept() lock) */
  #define SERVER_BUSY 2		/* Processing a client request */
- - #define SERVER_STARTING 3	/* Launched, but not yet live */
  
  typedef struct {
      pid_t pid;
      char status;
  } short_score;
  
- --- 65,74 ----
  #define SERVER_DEAD 0		/* Unused scoreboard entry */
  #define SERVER_READY 1		/* Waiting for connection (or accept() lock) */
  #define SERVER_BUSY 2		/* Processing a client request */
  
  typedef struct {
      pid_t pid;
+     char count;
      char status;
  } short_score;
  

- ----- End of forwarded message from Steve Nuchia -----

- -- 
Rob Hartill (robh@imdb.com)
The Internet Movie Database (IMDb)  http://www.imdb.com/
           ...more movie info than you can poke a stick at.

------- End of Forwarded Message




Mime
View raw message