httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Slemko <ma...@znep.com>
Subject [PATCH] fix for server hanging on HUP
Date Sat, 08 Feb 1997 08:45:38 GMT
Below is patch that I expect to fix the problem of the server
hanging after a SIGHUP due to a child process not exiting.

I have not yet been able to test it here because I have to do it on 
a live server since I have been unable to simulate the condition...
perhaps I will get a chance to try it live tomorrow (backported to
1.1).

Note that this patch won't work on systems that don't have WNOHANG.
To apply in real life, it simply needs an ifdef around it so it will
use the old code if WNOHANG isn't defined.

I would appreciate it if anyone who is having the problem could try
this and let me know the results...

Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.116
diff -c -r1.116 http_main.c
*** http_main.c	1997/02/04 23:54:23	1.116
--- http_main.c	1997/02/08 08:38:29
***************
*** 1024,1032 ****
      sync_scoreboard_image();
      for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
  	int pid = scoreboard_image->servers[i].pid;
  
! 	if (pid != my_pid && pid != 0)
! 	    waitpid (scoreboard_image->servers[i].pid, &status, 0);
      }
  }
  
--- 1024,1063 ----
      sync_scoreboard_image();
      for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
  	int pid = scoreboard_image->servers[i].pid;
+ 	int tries = 0;
  
! 	if (pid != my_pid && pid != 0) {
! 	    if (waitpid (pid, &status, WNOHANG) == 0) {
! 		/* first time through, we assume it is just slow */
! 		switch (tries) {
! 		case 0:
! 		    /* first time through, we assume it is just slow */
! 		    break;
! 		case 1:
! 		    /* perhaps it missed the SIGHUP, lets try again */
! 		    log_printf(server_conf, "child process %d did not exit first try, sending another
SIGHUP", pid);
! 		    kill(pid, SIGHUP);
! 		    break;
! 		case 2:
! 		    /* ok, now it is being annoying */
! 		    log_printf(server_conf, "child process %d did not exit second try, sending a SIGTERM",
pid);
! 		    kill(pid, SIGTERM);
! 		    break;
! 		case 3:
! 		    /* die child scum */
! 		    log_printf(server_conf, "child process %d did not exit third try, sending a SIGKILL",
pid);
! 		    kill(pid, SIGKILL);
! 		    break;
! 		case 4:
! 		    /* gave it our best shot, but alas... */
! 		    log_printf(server_conf, "could not make child process %d exit; ignoring it", pid);
! 		    continue;
! 		    break;
! 		}
! 		tries++;
! 		sleep(2);
! 	    }
! 	}
      }
  }
  


Mime
View raw message