httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <...@gonzo.ben.algroup.co.uk>
Subject NEED_WAITPID
Date Thu, 12 Dec 1996 17:46:58 GMT
Here's a proposed patch to deal with non-existent waipid() and also clean up
the possibly defunct BROKEN_WAIT (I haven't completely removed it in case we
need it).

Cheers,

Ben.

Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.95
diff -c -r1.95 http_main.c
*** http_main.c 1996/12/10 01:11:58     1.95
--- http_main.c 1996/12/12 18:48:04
***************
*** 941,962 ****
      }
  }

! #ifdef BROKEN_WAIT
  /*
  Some systems appear to fail to deliver dead children to wait() at times.
! This sorts them out.
  */
! void reap_children()
      {
      int status,n;

      for(n=0 ; n < HARD_SERVER_LIMIT ; ++n)
        if(scoreboard_image->servers[n].status != SERVER_DEAD
           && waitpid(scoreboard_image->servers[n].pid,&status,WNOHANG) ==
-1
           && errno == ECHILD)
            {
            update_child_status(n,SERVER_DEAD,NULL);
            }
      }
  #endif

--- 941,968 ----
      }
  }

! #if defined(BROKEN_WAIT) || defined(NEED_WAITPID)
  /*
  Some systems appear to fail to deliver dead children to wait() at times.
! This sorts them out. In fact, this may have been caused by a race condition
! in wait_or_timeout(). But this routine is still useful for systems with no
! waitpid().
  */
! int reap_children()
      {
      int status,n;
+     int ret=0;

      for(n=0 ; n < HARD_SERVER_LIMIT ; ++n)
        if(scoreboard_image->servers[n].status != SERVER_DEAD
           && waitpid(scoreboard_image->servers[n].pid,&status,WNOHANG) ==
-1
           && errno == ECHILD)
            {
+           sync_scoreboard_image();
            update_child_status(n,SERVER_DEAD,NULL);
+           ret=1;
            }
+     return ret;
      }
  #endif

***************
*** 968,973 ****
--- 974,980 ----

  static int wait_or_timeout(int *status)
      {
+ #ifndef NEED_WAITPID
      int ret;

      ret=waitpid(-1,status,WNOHANG);
***************
*** 977,982 ****
        return -1;
        }
      return ret;
+ #else
+     if(!reap_children())
+       sleep(1);
+     return -1;
+ #endif
      }

  #else
Index: conf.h
===================================================================
RCS file: /export/home/cvs/apache/src/conf.h,v
retrieving revision 1.59
diff -c -r1.59 conf.h
*** conf.h      1996/12/12 16:45:32     1.59
--- conf.h      1996/12/12 18:48:11
***************
*** 94,100 ****
  #define HAVE_SHMGET
  #define HAVE_CRYPT_H
  #define NO_LONG_DOUBLE
+     if(!reap_children())
+       sleep(1);
+     return -1;
+ #endif
      }

  #else
Index: conf.h
===================================================================
RCS file: /export/home/cvs/apache/src/conf.h,v
retrieving revision 1.59
diff -c -r1.59 conf.h
*** conf.h      1996/12/12 16:45:32     1.59
--- conf.h      1996/12/12 18:48:11
***************
*** 94,100 ****
  #define HAVE_SHMGET
  #define HAVE_CRYPT_H
  #define NO_LONG_DOUBLE
- #define BROKEN_WAIT

  #elif defined(HPUX) || defined(HPUX10)
  #define HAVE_SYS_RESOURCE_H
--- 94,99 ----

Cheers,

Ben.

-- 
Ben Laurie                Phone: +44 (181) 994 6435  Email: ben@algroup.co.uk
Freelance Consultant and  Fax:   +44 (181) 994 6472
Technical Director        URL: http://www.algroup.co.uk/Apache-SSL
A.L. Digital Ltd,         Apache Group member (http://www.apache.org)
London, England.          Apache-SSL author

Mime
View raw message