httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Jagielski <...@jaguNET.com>
Subject Suggested mod_status.c patch
Date Tue, 21 May 1996 19:34:58 GMT
I found this patchfile for the stat-module on hyperreal. It looked
pretty good and added some nice features. I've updated/modified/improved
it to be the beastie below. It patches cleanly against the current
CVS tree. I think it would be a good addition for 1.1b4.

Let me know, and if I get +1, I'll commit:
######################################################
Index: apache/src/http_core.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_core.c,v
retrieving revision 1.11
diff -c -r1.11 http_core.c
*** http_core.c	1996/04/11 02:56:17	1.11
--- http_core.c	1996/05/21 19:30:02
***************
*** 63,68 ****
--- 63,69 ----
  #include "http_log.h"
  #include "rfc1413.h"
  #include "util_md5.h"
+ #include "scoreboard.h"
  
  /* Server core module... This module provides support for really basic
   * server operations, including options and commands which control the
***************
*** 272,277 ****
--- 273,283 ----
  
      if (conn->remote_host == NULL && dir_conf->hostname_lookups)
      {
+ #ifdef STATUS
+ 	int old_stat = update_child_status(conn->child_num,
+ 						SERVER_BUSY_DNS,
+ 						(request_rec*)NULL);
+ #endif /* STATUS */
  	iaddr = &(conn->remote_addr.sin_addr);
  	hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr), AF_INET);
  	if (hptr != NULL)
***************
*** 296,301 ****
--- 302,310 ----
  	}
  /* if failed, set it to the NULL string to indicate error */
  	if (conn->remote_host == NULL) conn->remote_host = "";
+ #ifdef STATUS
+ 	(void)update_child_status(conn->child_num,old_stat,(request_rec*)NULL);
+ #endif /* STATUS */
      }
  
  /*
Index: apache/src/http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.27
diff -c -r1.27 http_main.c
*** http_main.c	1996/05/15 12:57:44	1.27
--- http_main.c	1996/05/21 19:30:03
***************
*** 657,667 ****
  #endif
  }
  
! void update_child_status (int child_num, int status, request_rec *r)
  {
      short_score new_score_rec;
      memcpy(&new_score_rec,&scoreboard_image[child_num],sizeof new_score_rec);
      new_score_rec.pid = getpid();
      new_score_rec.status = status;
  
  #if defined(STATUS)
--- 657,673 ----
  #endif
  }
  
! int update_child_status (int child_num, int status, request_rec *r)
  {
      short_score new_score_rec;
+     int old_status;
+ 
+     if (child_num < 0)
+ 	return scoreboard_image[child_num].status;
+     
      memcpy(&new_score_rec,&scoreboard_image[child_num],sizeof new_score_rec);
      new_score_rec.pid = getpid();
+     old_status = new_score_rec.status;
      new_score_rec.status = status;
  
  #if defined(STATUS)
***************
*** 695,700 ****
--- 701,713 ----
      lseek (scoreboard_fd, (long)child_num * sizeof(short_score), 0);
      force_write (scoreboard_fd, (char*)&new_score_rec, sizeof(short_score));
  #endif
+ 
+     return old_status;
+ }
+ 
+ int get_child_status (int child_num)
+ {
+     return scoreboard_image[child_num].status;
  }
  
  int count_busy_servers ()
***************
*** 704,710 ****
  
      for (i = 0; i < HARD_SERVER_MAX; ++i)
        if (scoreboard_image[i].status == SERVER_BUSY_READ ||
!               scoreboard_image[i].status == SERVER_BUSY_WRITE)
            ++res;
      return res;
  }
--- 717,726 ----
  
      for (i = 0; i < HARD_SERVER_MAX; ++i)
        if (scoreboard_image[i].status == SERVER_BUSY_READ ||
!               scoreboard_image[i].status == SERVER_BUSY_WRITE ||
!               scoreboard_image[i].status == SERVER_BUSY_KEEPALIVE ||
!               scoreboard_image[i].status == SERVER_BUSY_LOG ||
!               scoreboard_image[i].status == SERVER_BUSY_DNS)
            ++res;
      return res;
  }
***************
*** 1058,1064 ****
  
  conn_rec *new_connection (pool *p, server_rec *server, BUFF *inout,
  			  const struct sockaddr_in *remaddr,
! 			  const struct sockaddr_in *saddr)
  {
      conn_rec *conn = (conn_rec *)pcalloc (p, sizeof(conn_rec));
      
--- 1074,1081 ----
  
  conn_rec *new_connection (pool *p, server_rec *server, BUFF *inout,
  			  const struct sockaddr_in *remaddr,
! 			  const struct sockaddr_in *saddr,
! 			  int child_num)
  {
      conn_rec *conn = (conn_rec *)pcalloc (p, sizeof(conn_rec));
      
***************
*** 1067,1072 ****
--- 1084,1090 ----
       */
      
      conn = (conn_rec *)pcalloc(p, sizeof(conn_rec));
+     conn->child_num = child_num;
      
      conn->pool = p;
      conn->local_addr = *saddr;
***************
*** 1077,1082 ****
--- 1095,1101 ----
      conn->remote_addr = *remaddr;
      conn->remote_ip = pstrdup (conn->pool,
  			       inet_ntoa(conn->remote_addr.sin_addr));
+ 
      return conn;
  }
  
***************
*** 1102,1108 ****
      child_num = child_num_arg;
      requests_this_child = 0;
      reopen_scoreboard (pconf);
!     update_child_status (child_num, SERVER_READY, (request_rec*)NULL);
  
      /* Only try to switch if we're running as root */
      if(!geteuid() && setuid(user_id) == -1) {
--- 1121,1127 ----
      child_num = child_num_arg;
      requests_this_child = 0;
      reopen_scoreboard (pconf);
!     (void)update_child_status (child_num, SERVER_READY, (request_rec*)NULL);
  
      /* Only try to switch if we're running as root */
      if(!geteuid() && setuid(user_id) == -1) {
***************
*** 1140,1146 ****
  	}
  
  	clen=sizeof(sa_client);
! 	update_child_status (child_num, SERVER_READY, (request_rec*)NULL);
  	
  	accept_mutex_on();  /* Lock around "accept", if necessary */
  
--- 1159,1165 ----
  	}
  
  	clen=sizeof(sa_client);
! 	(void)update_child_status (child_num, SERVER_READY, (request_rec*)NULL);
  	
  	accept_mutex_on();  /* Lock around "accept", if necessary */
  
***************
*** 1177,1183 ****
  	    continue;
  	}
  	
! 	update_child_status (child_num, SERVER_BUSY_READ, (request_rec*)NULL);
  	conn_io = bcreate(ptrans, B_RDWR);
  	dupped_csd = csd;
  #if defined(NEED_DUPPED_CSD)
--- 1196,1202 ----
  	    continue;
  	}
  	
! 	(void)update_child_status (child_num, SERVER_BUSY_READ, (request_rec*)NULL);
  	conn_io = bcreate(ptrans, B_RDWR);
  	dupped_csd = csd;
  #if defined(NEED_DUPPED_CSD)
***************
*** 1190,1199 ****
  
  	current_conn = new_connection (ptrans, server_conf, conn_io,
  				       (struct sockaddr_in *)&sa_client,
! 				       (struct sockaddr_in *)&sa_server);
  	
  	r = read_request (current_conn);
! 	update_child_status (child_num, SERVER_BUSY_WRITE, r);
  	if (r) process_request (r); /* else premature EOF --- ignore */
  
  #if defined(STATUS)
--- 1209,1219 ----
  
  	current_conn = new_connection (ptrans, server_conf, conn_io,
  				       (struct sockaddr_in *)&sa_client,
! 				       (struct sockaddr_in *)&sa_server,
! 				       child_num);
  	
  	r = read_request (current_conn);
! 	(void)update_child_status (child_num, SERVER_BUSY_WRITE, r);
  	if (r) process_request (r); /* else premature EOF --- ignore */
  
  #if defined(STATUS)
***************
*** 1202,1210 ****
  	while (r && current_conn->keepalive) {
  	  bflush(conn_io);
  	  destroy_pool(r->pool);
! 	  update_child_status (child_num, SERVER_BUSY_READ, (request_rec*)NULL);
  	  r = read_request (current_conn);
! 	  update_child_status (child_num, SERVER_BUSY_WRITE, r);
  	  if (r) process_request (r);
  
  #if defined(STATUS)
--- 1222,1230 ----
  	while (r && current_conn->keepalive) {
  	  bflush(conn_io);
  	  destroy_pool(r->pool);
! 	  (void)update_child_status (child_num, SERVER_BUSY_KEEPALIVE, (request_rec*)NULL);
  	  r = read_request (current_conn);
! 	  (void)update_child_status (child_num, SERVER_BUSY_WRITE, r);
  	  if (r) process_request (r);
  
  #if defined(STATUS)
***************
*** 1381,1398 ****
  	    /* 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,
! 	     (request_rec*)NULL);
          }
  
  	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,(request_rec*)NULL);
  	    make_child(server_conf, child_slot);
! 	    }
      }
  
  } /* standalone_main */
--- 1401,1419 ----
  	    /* Child died... note that it's gone in the scoreboard. */
  	    sync_scoreboard_image();
  	    child_slot = find_child_by_pid (pid);
! 	    if (child_slot >= 0)
! 		(void)update_child_status (child_slot, SERVER_DEAD,
! 		 (request_rec*)NULL);
          }
  
  	sync_scoreboard_image();
  	if ((count_idle_servers() < daemons_min_free)
! 	 && (child_slot = find_free_child_num()) >= 0
! 	 && child_slot <= daemons_limit) {
! 	    (void)update_child_status(child_slot,SERVER_STARTING,
! 	     (request_rec*)NULL);
  	    make_child(server_conf, child_slot);
! 	}
      }
  
  } /* standalone_main */
***************
*** 1491,1497 ****
  	bpushfd(cio, fileno(stdin), fileno(stdout));
  	conn = new_connection (ptrans, server_conf, cio,
  			       (struct sockaddr_in *)&sa_client,
! 			       (struct sockaddr_in *)&sa_server);
  	r = read_request (conn);
  	if (r) process_request (r); /* else premature EOF (ignore) */
  
--- 1512,1518 ----
  	bpushfd(cio, fileno(stdin), fileno(stdout));
  	conn = new_connection (ptrans, server_conf, cio,
  			       (struct sockaddr_in *)&sa_client,
! 			       (struct sockaddr_in *)&sa_server,-1);
  	r = read_request (conn);
  	if (r) process_request (r); /* else premature EOF (ignore) */
  
Index: apache/src/http_main.h
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.h,v
retrieving revision 1.2
diff -c -r1.2 http_main.h
*** http_main.h	1996/02/22 11:46:48	1.2
--- http_main.h	1996/05/21 19:30:03
***************
*** 91,93 ****
--- 91,99 ----
  void soft_timeout (char *, request_rec *);
  void kill_timeout (request_rec *);     
  void reset_timeout (request_rec *);
+ 
+ void sync_scoreboard_image ();
+ int update_child_status (int child_num, int status, request_rec *r);
+ int get_child_status (int child_num);
+ int count_busy_servers ();
+ int count_idle_servers ();
Index: apache/src/http_request.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_request.c,v
retrieving revision 1.6
diff -c -r1.6 http_request.c
*** http_request.c	1996/04/09 23:06:03	1.6
--- http_request.c	1996/05/21 19:30:04
***************
*** 70,75 ****
--- 70,76 ----
  #include "http_protocol.h"
  #include "http_log.h"
  #include "http_main.h"
+ #include "scoreboard.h"
  
  /*****************************************************************
   *
***************
*** 737,744 ****
--- 738,753 ----
  
  void process_request (request_rec *r)
  {
+     int old_stat;
      process_request_internal (r);
+ #ifdef STATUS
+     old_stat = update_child_status (r->connection->child_num, SERVER_BUSY_LOG,
+      r);
+ #endif /* STATUS */
      log_transaction (r);
+ #ifdef STATUS
+     (void)update_child_status (r->connection->child_num, old_stat, r);
+ #endif /* STATUS */
  }
  
  table *rename_original_env (pool *p, table *t)
Index: apache/src/httpd.h
===================================================================
RCS file: /export/home/cvs/apache/src/httpd.h,v
retrieving revision 1.19
diff -c -r1.19 httpd.h
*** httpd.h	1996/05/15 12:57:45	1.19
--- httpd.h	1996/05/21 19:30:04
***************
*** 394,400 ****
    server_rec *server;
    
    /* Information about the connection itself */
!   
    BUFF *client;			/* Connetion to the guy */
    int aborted;			/* Are we still talking? */
    
--- 394,401 ----
    server_rec *server;
    
    /* Information about the connection itself */
! 
!   int child_num;                /* The number of the child handling conn_rec */
    BUFF *client;			/* Connetion to the guy */
    int aborted;			/* Are we still talking? */
    
Index: apache/src/mod_cgi.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_cgi.c,v
retrieving revision 1.7
diff -c -r1.7 mod_cgi.c
*** mod_cgi.c	1996/04/25 05:18:26	1.7
--- mod_cgi.c	1996/05/21 19:30:06
***************
*** 275,282 ****
      
  #else
       if (!spawn_child (r->connection->pool, cgi_child, (void *)&cld,
! 		      nph ? just_wait : kill_after_timeout,
! 		      &script_out, nph ? NULL : &script_in)) {
          log_reason ("couldn't spawn child process", r->filename, r);
          return SERVER_ERROR;
      }
--- 275,282 ----
      
  #else
       if (!spawn_child (r->connection->pool, cgi_child, (void *)&cld,
! 		       nph ? just_wait : kill_after_timeout, 
! 		       &script_out, nph ? NULL : &script_in)) {
          log_reason ("couldn't spawn child process", r->filename, r);
          return SERVER_ERROR;
      }
Index: apache/src/mod_status.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_status.c,v
retrieving revision 1.16
diff -c -r1.16 mod_status.c
*** mod_status.c	1996/05/13 20:22:01	1.16
--- mod_status.c	1996/05/21 19:30:07
***************
*** 75,80 ****
--- 75,82 ----
   * 09.4.96  Added message for non-STATUS compiled version
   * 18.4.96  Added per child and per slot counters [Jim Jagielski]
   * 01.5.96  Table format, cleanup, even more spiffy data [Chuck Murcko/Jim J.]
+  * 21.5.96  Additional Status codes (DNS and LOGGING only enabled if
+              extended STATUS is enabled) [George Burgyan/Jim J.]
   */
  
  #include "httpd.h"
***************
*** 191,197 ****
      int no_table_report=0;
      server_rec *server = r->server;
      short_score score_record;
!     char status[]="???????";
      char buffer[200];
      char stat_buffer[HARD_SERVER_MAX];
      clock_t tu,ts,tcu,tcs;
--- 193,199 ----
      int no_table_report=0;
      server_rec *server = r->server;
      short_score score_record;
!     char status[]="??????????";
      char buffer[200];
      char stat_buffer[HARD_SERVER_MAX];
      clock_t tu,ts,tcu,tcs;
***************
*** 203,208 ****
--- 205,213 ----
      status[SERVER_STARTING]='S';
      status[SERVER_BUSY_READ]='R';
      status[SERVER_BUSY_WRITE]='W';
+     status[SERVER_BUSY_KEEPALIVE]='K';
+     status[SERVER_BUSY_LOG]='L';
+     status[SERVER_BUSY_DNS]='D';
  
      if (r->method_number != M_GET) return NOT_IMPLEMENTED;
      r->content_type = "text/html";
***************
*** 255,261 ****
          if (res == SERVER_READY)
  	    ready++;
          else if (res == SERVER_BUSY_READ || res==SERVER_BUSY_WRITE || 
! 		 res == SERVER_STARTING)
  	    busy++;
  #if defined(STATUS)
          lres = score_record.access_count;
--- 260,267 ----
          if (res == SERVER_READY)
  	    ready++;
          else if (res == SERVER_BUSY_READ || res==SERVER_BUSY_WRITE || 
! 		 res == SERVER_STARTING || res==SERVER_BUSY_KEEPALIVE ||
! 		 res == SERVER_BUSY_LOG || res==SERVER_BUSY_DNS)
  	    busy++;
  #if defined(STATUS)
          lres = score_record.access_count;
***************
*** 387,397 ****
      else 
      {
  	rputs("</PRE>\n",r);
! 	rputs("Key: \n",r);
  	rputs("\"<code>_</code>\" Waiting for Connection, \n",r);
! 	rputs("\"<code>S</code>\" Starting up, \n",r);
  	rputs("\"<code>R</code>\" Reading Request, \n",r);
! 	rputs("\"<code>W</code>\" Sending Reply<p>\n",r);
          sprintf(buffer,"\n%d requests currently being processed, %d idle servers\n",busy,ready);
  	rputs(buffer,r);
      }
--- 393,406 ----
      else 
      {
  	rputs("</PRE>\n",r);
! 	rputs("Key:<br> \n",r);
  	rputs("\"<code>_</code>\" Waiting for Connection, \n",r);
! 	rputs("\"<code>S</code>\" Starting up,<br> \n",r);
  	rputs("\"<code>R</code>\" Reading Request, \n",r);
! 	rputs("\"<code>W</code>\" Sending Reply,<br> \n",r);
! 	rputs("\"<code>K</code>\" Keepalive (read), \n",r);
! 	rputs("\"<code>D</code>\" DNS Lookup, \n",r);
! 	rputs("\"<code>L</code>\" Logging<p>\n",r);
          sprintf(buffer,"\n%d requests currently being processed, %d idle servers\n",busy,ready);
  	rputs(buffer,r);
      }
***************
*** 438,443 ****
--- 447,461 ----
  		        case SERVER_BUSY_WRITE:
  		            rputs("<b>Write</b>",r);
  		            break;
+ 		        case SERVER_BUSY_KEEPALIVE:
+ 		            rputs("<b>Keepalive</b>",r);
+ 		            break;
+ 		        case SERVER_BUSY_LOG:
+ 		            rputs("<b>Logging</b>",r);
+ 		            break;
+ 		        case SERVER_BUSY_DNS:
+ 		            rputs("<b>DNS lookup</b>",r);
+ 		            break;
  		        case SERVER_DEAD:
  		            rputs("Dead",r);
  		            break;
***************
*** 479,484 ****
--- 497,511 ----
  		        case SERVER_BUSY_WRITE:
  		            rputs("<td><b>W</b>",r);
  		            break;
+ 		        case SERVER_BUSY_KEEPALIVE:
+ 		            rputs("<td><b>K</b>",r);
+ 		            break;
+ 		        case SERVER_BUSY_LOG:
+ 		            rputs("<td><b>L</b>",r);
+ 		            break;
+ 		        case SERVER_BUSY_DNS:
+ 		            rputs("<td><b>D</b>",r);
+ 		            break;
  		        case SERVER_DEAD:
  		            rputs("<td>.",r);
  		            break;
***************
*** 524,529 ****
--- 551,558 ----
      rputs("you need to recompile Apache adding the <code>-DSTATUS</code> \n",r);
      rputs("directive on the <code>CFLAGS</code> line in the \n",r);
      rputs("<code>Configuration</code> file.\n",r);
+     rputs("<code>DNS</code> and <code>LOGGING</code> status \n",r);
+     rputs("also requires the <code>-DSTATUS</code> directive. \n",r);
  
  #endif /* STATUS */
  
Index: apache/src/scoreboard.h
===================================================================
RCS file: /export/home/cvs/apache/src/scoreboard.h,v
retrieving revision 1.9
diff -c -r1.9 scoreboard.h
*** scoreboard.h	1996/05/07 18:29:35	1.9
--- scoreboard.h	1996/05/21 19:30:07
***************
*** 63,73 ****
--- 63,77 ----
   * Status values:
   */
  
+ #define SERVER_UNKNOWN (-1)	/* should never be in this state */
  #define SERVER_DEAD 0
  #define SERVER_READY 1          /* Waiting for connection (or accept() lock) */
  #define SERVER_STARTING 3       /* Server Starting up */
  #define SERVER_BUSY_READ 2      /* Reading a client request */
  #define SERVER_BUSY_WRITE 4     /* Processing a client request */
+ #define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */
+ #define SERVER_BUSY_LOG 6       /* Logging the request */
+ #define SERVER_BUSY_DNS 7       /* Looking up a hostname */
  
  typedef struct {
      pid_t pid;
-- 
Jim Jagielski  << jim@jaguNET.com >>   |      "That's a Smith & Wesson,
  **  jaguNET Access Services  **      |       and you've had your six" 
      Email: info@jaguNET.com          |             - James Bond
++    http://www.jaguNET.com/         +++      Voice/Fax: 410-931-3157       ++

Mime
View raw message