httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject [PATCH] improve scoreboard file support w/graceful
Date Sat, 26 Apr 1997 09:45:57 GMT
Ok I'll stop fixing things so we can get 1.2b9 out the door.  But... well.

Deal with EINTR while reading/writing scoreboard file.

Fix scoreboard file support during graceful restart.

There are still race conditions involving the scoreboard and graceful
(or non-graceful) restart.  In particular while using -HUP it's possible
to get it to "bind: Address already in use".  And while using -USR1
it's possible to see "long lost child came home!" (indicating that the
scoreboard was missing that child).  But they're even worse without
this patch.

Dean

Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.139
diff -c -3 -r1.139 http_main.c
*** http_main.c	1997/04/24 23:35:20	1.139
--- http_main.c	1997/04/26 09:40:28
***************
*** 73,83 ****
   *      Extensive rework for Apache.
   */
  
- /* XXX: systems without HAVE_SHMGET or HAVE_MMAP do not reliably update
-  * the scoreboard because a received signal might interrupt the scoreboard
-  * calls.
-  */
- 
  #define CORE_PRIVATE
  
  #include "httpd.h"
--- 73,78 ----
***************
*** 804,814 ****
  }
  
  #else
  static scoreboard _scoreboard_image;
  static scoreboard *scoreboard_image=&_scoreboard_image;
- static int have_scoreboard_fname = 0;
  static int scoreboard_fd;
  
  static int force_write (int fd, char *buffer, int bufsz)
  {
      int rv, orig_sz = bufsz;
--- 799,812 ----
  }
  
  #else
+ #define SCOREBOARD_FILE
  static scoreboard _scoreboard_image;
  static scoreboard *scoreboard_image=&_scoreboard_image;
  static int scoreboard_fd;
  
+ /* XXX: things are seriously screwed if we ever have to do a partial
+  * read or write ... we could get a corrupted scoreboard
+  */
  static int force_write (int fd, char *buffer, int bufsz)
  {
      int rv, orig_sz = bufsz;
***************
*** 819,825 ****
  	    buffer += rv;
  	    bufsz -= rv;
  	}
!     } while (rv > 0 && bufsz > 0);
  
      return rv < 0? rv : orig_sz - bufsz;
  }
--- 817,823 ----
  	    buffer += rv;
  	    bufsz -= rv;
  	}
!     } while ((rv > 0 && bufsz > 0) || (rv == -1 && errno == EINTR));
  
      return rv < 0? rv : orig_sz - bufsz;
  }
***************
*** 834,840 ****
  	    buffer += rv;
  	    bufsz -= rv;
  	}
!     } while (rv > 0 && bufsz > 0);
      
      return rv < 0? rv : orig_sz - bufsz;
  }
--- 832,838 ----
  	    buffer += rv;
  	    bufsz -= rv;
  	}
!     } while ((rv > 0 && bufsz > 0) || (rv == -1 && errno == EINTR));
      
      return rv < 0? rv : orig_sz - bufsz;
  }
***************
*** 847,853 ****
      if(scoreboard_image)
  	exit_gen=scoreboard_image->global.exit_generation;
  	
! #if defined(HAVE_SHMGET) || defined(HAVE_MMAP)
      if (scoreboard_image == NULL)
      {
  	setup_shared_mem();
--- 845,851 ----
      if(scoreboard_image)
  	exit_gen=scoreboard_image->global.exit_generation;
  	
! #ifndef SCOREBOARD_FILE
      if (scoreboard_image == NULL)
      {
  	setup_shared_mem();
***************
*** 857,864 ****
  #else
      scoreboard_fname = server_root_relative (p, scoreboard_fname);
  
-     have_scoreboard_fname = 1;
-     
  #ifdef __EMX__
      /* OS/2 needs binary mode set. */
      scoreboard_fd = popenf(p, scoreboard_fname, O_CREAT|O_BINARY|O_RDWR, 0644);
--- 855,860 ----
***************
*** 882,888 ****
  /* called by child */
  void reopen_scoreboard (pool *p)
  {
! #if !defined(HAVE_MMAP) && !defined(HAVE_SHMGET)
      if (scoreboard_fd != -1) pclosef (p, scoreboard_fd);
      
  #ifdef __EMX__    
--- 878,884 ----
  /* called by child */
  void reopen_scoreboard (pool *p)
  {
! #ifdef SCOREBOARD_FILE
      if (scoreboard_fd != -1) pclosef (p, scoreboard_fd);
      
  #ifdef __EMX__    
***************
*** 918,924 ****
  
  void cleanup_scoreboard ()
  {
! #if !defined(HAVE_MMAP) && !defined(HAVE_SHMGET)
      unlink (scoreboard_fname);
  #endif
  }
--- 914,920 ----
  
  void cleanup_scoreboard ()
  {
! #ifdef SCOREBOARD_FILE
      unlink (scoreboard_fname);
  #endif
  }
***************
*** 936,942 ****
  
  void sync_scoreboard_image ()
  {
! #if !defined(HAVE_MMAP) && !defined(HAVE_SHMGET)
      lseek (scoreboard_fd, 0L, 0);
      force_read (scoreboard_fd, (char*)scoreboard_image,
  		sizeof(*scoreboard_image));
--- 932,938 ----
  
  void sync_scoreboard_image ()
  {
! #ifdef SCOREBOARD_FILE
      lseek (scoreboard_fd, 0L, 0);
      force_read (scoreboard_fd, (char*)scoreboard_image,
  		sizeof(*scoreboard_image));
***************
*** 987,993 ****
      }
  #endif
  
! #if defined(HAVE_MMAP) || defined(HAVE_SHMGET)
      memcpy(&scoreboard_image->servers[child_num], &new_score_rec, sizeof new_score_rec);
  #else
      lseek (scoreboard_fd, (long)child_num * sizeof(short_score), 0);
--- 983,989 ----
      }
  #endif
  
! #ifndef SCOREBOARD_FILE
      memcpy(&scoreboard_image->servers[child_num], &new_score_rec, sizeof new_score_rec);
  #else
      lseek (scoreboard_fd, (long)child_num * sizeof(short_score), 0);
***************
*** 999,1005 ****
  
  void update_scoreboard_global()
      {
! #if !defined(HAVE_MMAP) && !defined(HAVE_SHMGET)
      lseek(scoreboard_fd,
  	  (char *)&scoreboard_image->global-(char *)scoreboard_image,0);
      force_write(scoreboard_fd,(char *)&scoreboard_image->global,
--- 995,1001 ----
  
  void update_scoreboard_global()
      {
! #ifdef SCOREBOARD_FILE
      lseek(scoreboard_fd,
  	  (char *)&scoreboard_image->global-(char *)scoreboard_image,0);
      force_write(scoreboard_fd,(char *)&scoreboard_image->global,
***************
*** 1067,1073 ****
      times(&new_score_rec.times);
  
  
! #if defined(HAVE_MMAP) || defined(HAVE_SHMGET)
      memcpy(&scoreboard_image->servers[child_num], &new_score_rec, sizeof(short_score));
  #else
      lseek (scoreboard_fd, (long)child_num * sizeof(short_score), 0);
--- 1063,1069 ----
      times(&new_score_rec.times);
  
  
! #ifndef SCOREBOARD_FILE
      memcpy(&scoreboard_image->servers[child_num], &new_score_rec, sizeof(short_score));
  #else
      lseek (scoreboard_fd, (long)child_num * sizeof(short_score), 0);
***************
*** 2128,2133 ****
--- 2124,2134 ----
  	if (!is_graceful) {
  	    restart_time = time(NULL);
  	}
+ #ifdef SCOREBOARD_FILE
+ 	else {
+ 	    kill_cleanups_for_fd (pconf, scoreboard_fd);
+ 	}
+ #endif
  	clear_pool (pconf);
  	ptrans = make_sub_pool (pconf);
  
***************
*** 2138,2143 ****
--- 2139,2150 ----
  	if (!is_graceful) {
  	    reinit_scoreboard(pconf);
  	}
+ #ifdef SCOREBOARD_FILE
+ 	else {
+ 	    scoreboard_fname = server_root_relative (pconf, scoreboard_fname);
+ 	    note_cleanups_for_fd (pconf, scoreboard_fd);
+ 	}
+ #endif
  
  	default_server_hostnames (server_conf);
  
***************
*** 2284,2292 ****
  	    if (ap_killpg(pgrp, SIGUSR1) < 0) {
  		log_unixerr ("killpg SIGUSR1", NULL, NULL, server_conf);
  	    }
  	    /* This is mostly for debugging... so that we know what is still
! 	     * gracefully dealing with existing request.
! 	     * XXX: clean this up a bit?
  	     */
  	    sync_scoreboard_image();
  	    for (i = 0; i < daemons_limit; ++i ) {
--- 2291,2301 ----
  	    if (ap_killpg(pgrp, SIGUSR1) < 0) {
  		log_unixerr ("killpg SIGUSR1", NULL, NULL, server_conf);
  	    }
+ #ifndef SCOREBOARD_FILE
  	    /* This is mostly for debugging... so that we know what is still
! 	     * gracefully dealing with existing request.  But we can't really
! 	     * do it if we're in a SCOREBOARD_FILE because it'll cause
! 	     * corruption too easily.
  	     */
  	    sync_scoreboard_image();
  	    for (i = 0; i < daemons_limit; ++i ) {
***************
*** 2294,2303 ****
  		    scoreboard_image->servers[i].status = SERVER_GRACEFUL;
  		}
  	    }
- #if !defined(HAVE_MMAP) && !defined(HAVE_SHMGET)
- 	    lseek (scoreboard_fd, 0L, 0);
- 	    force_write (scoreboard_fd, (char*)scoreboard_image,
- 			sizeof(*scoreboard_image));
  #endif
  	}
  	else {
--- 2303,2308 ----


Mime
View raw message