lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lynx-dev NSL_FORK patch for "too many processes"


From: Bela Lubkin
Subject: lynx-dev NSL_FORK patch for "too many processes"
Date: Tue, 6 Oct 1998 03:50:25 -0700

This will probably fix David Combs' problem (even if it wasn't actually
caused by NSL_FORK at all!)

Patch applies to Lynx versions 2.8.1dev.26 -> 29 and 2.8.1pre.1 -> 8.

BTW, the new variable "dns_patience" represents how many seconds we're
willing to wait for DNS to respond.  I made it a variable as a
placeholder for the fact that it ought to be tunable (in .lynxrc /
options screen, I suppose).  Tunability can wait for 2.8.2 unless Tom
feels like throwing in a set of the standard options code...

>Bela<

*** HTTCP.c.orig        Sun Oct  4 18:27:15 1998
--- HTTCP.c     Tue Oct  6 03:45:38 1998
***************
*** 307,310 ****
--- 307,323 ----
  #endif /* !DECNET */
  
+ #ifdef NSL_FORK
+ /*
+ **  Function to allow us to be killed with a normal signal (not
+ **  SIGKILL), but don't go through normal libc exit() processing, which
+ **  would screw up parent's stdio.  -BL
+ */
+ PRIVATE void quench ARGS1(
+       int,    sig GCC_UNUSED)
+ {
+     _exit(2);
+ }
+ #endif /* NSL_FORK */
+ 
  /*    Parse a network node address and port
  **    -------------------------------------
***************
*** 433,440 ****
            **  control variables.
            */
!           pid_t fpid, waitret = (pid_t)0;
            int pfd[2], cstat, cst1 = 0, cycle = 0;
            fd_set readfds;
            struct timeval timeout;
  
            pipe(pfd);
--- 446,468 ----
            **  control variables.
            */
!           pid_t fpid, waitret;
            int pfd[2], cstat, cst1 = 0, cycle = 0;
            fd_set readfds;
            struct timeval timeout;
+           int dns_patience = 30; /* how many seconds will we wait for DNS? */
+ 
+           /*
+           **  Reap any children that have terminated since last time
+           **  through.  This might include children that we killed,
+           **  then waited with WNOHANG before they were actually ready
+           **  to be reaped.  (Should be max of 1 in this state, but
+           **  the loop is safe if waitpid() is implemented correctly:
+           **  returns 0 when children exist but none have exited; -1
+           **  with errno == ECHILD when no children.)  -BL
+           */
+           do {
+               waitret = waitpid(-1, 0, WNOHANG);
+           } while (waitret > 0 || (waitret == -1 && errno == EINTR));
+           waitret = 0;
  
            pipe(pfd);
***************
*** 444,447 ****
--- 472,481 ----
                /*
                **  Child - for the long call.
+               **
+               **  Make sure parent can kill us at will.  -BL
+               */
+               (void) signal(SIGTERM, quench);
+ 
+               /*
                **  Child won't use read side.  -BL
                */
***************
*** 483,487 ****
            close(pfd[1]);      /* parent won't use write side -BL */
  
!           while (cycle < 50) {
                /*
                **  Avoid infinite loop in the face of the unexpected.  -BL
--- 517,521 ----
            close(pfd[1]);      /* parent won't use write side -BL */
  
!           while (cycle < dns_patience) {
                /*
                **  Avoid infinite loop in the face of the unexpected.  -BL
***************
*** 532,536 ****
                    waitret = waitpid(fpid, &cst1, WNOHANG);
                    if (!WIFEXITED(cst1) && !WIFSIGNALED(cst1)) {
!                       kill(fpid, SIGKILL);
                        waitret = waitpid(fpid, &cst1, WNOHANG);
                    }
--- 566,570 ----
                    waitret = waitpid(fpid, &cst1, WNOHANG);
                    if (!WIFEXITED(cst1) && !WIFSIGNALED(cst1)) {
!                       kill(fpid, SIGTERM);
                        waitret = waitpid(fpid, &cst1, WNOHANG);
                    }
***************
*** 549,554 ****
                if (HTCheckForInterrupt()) {
                    CTRACE(tfp, "HTParseInet: INTERRUPTED gethostbyname.\n");
!                   kill(fpid , SIGKILL);
!                   waitpid(fpid, NULL, 0);
                    FREE(host);
                    close(pfd[0]);
--- 583,588 ----
                if (HTCheckForInterrupt()) {
                    CTRACE(tfp, "HTParseInet: INTERRUPTED gethostbyname.\n");
!                   kill(fpid, SIGTERM);
!                   waitpid(fpid, NULL, WNOHANG);
                    FREE(host);
                    close(pfd[0]);
***************
*** 558,561 ****
--- 592,596 ----
            close(pfd[0]);
            if (waitret <= 0) {
+               kill(fpid, SIGTERM);
                waitret = waitpid(fpid, &cst1, WNOHANG);
            }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]