*** buffer.c.prealb	Tue Dec  6 06:56:45 2005
--- buffer.c	Tue Dec  6 07:10:54 2005
***************
*** 1412,1433 ****
      }
  
      return 0;
  }
  
  
- 
  static int
  stdio_buffer_shutdown (buf)
      struct buffer *buf;
  {
      struct stdio_buffer_closure *bc = buf->closure;
      struct stat s;
      int closefp = 1;
  
      /* Must be a pipe or a socket.  What could go wrong? */
!     assert (fstat (fileno (bc->fp), &s) != -1);
  
      /* Flush the buffer if we can */
      if (buf->flush)
      {
  	buf_flush (buf, 1);
--- 1412,1445 ----
      }
  
      return 0;
  }
  
+ /**
+  * alb - fix for disconnected clients on AIX systems.
+  *
+  * It's possible for the client to be gone at this point, which on AIX
+  * will cause the assertion previously present here to fail -- on an
+  * AIX system, fstat() will return -1 if the client has gone away.
+  *
+  * In addition, error() was being called in here with 1 as the first
+  * parameter, which instructs the server to shutdown.  However, we're
+  * here because we are shutting down, and the result was an infinite
+  * recursion.
+  */
  
  static int
  stdio_buffer_shutdown (buf)
      struct buffer *buf;
  {
      struct stdio_buffer_closure *bc = buf->closure;
      struct stat s;
      int closefp = 1;
  
      /* Must be a pipe or a socket.  What could go wrong? */
!     /* assert (fstat ( fileno (bc->fp), &s ) != -1);     */
!     int stat_rc = fstat(fileno(bc->fp), &s);  
  
      /* Flush the buffer if we can */
      if (buf->flush)
      {
  	buf_flush (buf, 1);
***************
*** 1446,1464 ****
  	if (current_parsed_root->method != server_method)
  # endif
  # ifndef NO_SOCKET_TO_FD
  	{
  	    /* shutdown() sockets */
! 	    if (S_ISSOCK (s.st_mode))
  		shutdown (fileno (bc->fp), 0);
  	}
  # endif /* NO_SOCKET_TO_FD */
  # ifdef START_RSH_WITH_POPEN_RW
  	/* Can't be set with SHUTDOWN_SERVER defined */
  	else if (pclose (bc->fp) == EOF)
  	{
! 	    error (1, errno, "closing connection to %s",
  		   current_parsed_root->hostname);
  	    closefp = 0;
  	}
  # endif /* START_RSH_WITH_POPEN_RW */
  
--- 1458,1476 ----
  	if (current_parsed_root->method != server_method)
  # endif
  # ifndef NO_SOCKET_TO_FD
  	{
  	    /* shutdown() sockets */
! 	    if ((stat_rc != -1) && (S_ISSOCK(s.st_mode)))
  		shutdown (fileno (bc->fp), 0);
  	}
  # endif /* NO_SOCKET_TO_FD */
  # ifdef START_RSH_WITH_POPEN_RW
  	/* Can't be set with SHUTDOWN_SERVER defined */
  	else if (pclose (bc->fp) == EOF)
  	{
! 	    error (0, errno, "closing connection to %s",
  		   current_parsed_root->hostname);
  	    closefp = 0;
  	}
  # endif /* START_RSH_WITH_POPEN_RW */
  
***************
*** 1474,1484 ****
  	    SHUTDOWN_SERVER (fileno (bc->fp));
  	else
  # endif
  # ifndef NO_SOCKET_TO_FD
  	/* shutdown() sockets */
! 	if (S_ISSOCK (s.st_mode))
  	    shutdown (fileno (bc->fp), 1);
  # else
  	{
  	/* I'm not sure I like this empty block, but the alternative
  	 * is a another nested NO_SOCKET_TO_FD switch above.
--- 1486,1496 ----
  	    SHUTDOWN_SERVER (fileno (bc->fp));
  	else
  # endif
  # ifndef NO_SOCKET_TO_FD
  	/* shutdown() sockets */
! 	if ((stat_rc != -1) && (S_ISSOCK(s.st_mode))) 
  	    shutdown (fileno (bc->fp), 1);
  # else
  	{
  	/* I'm not sure I like this empty block, but the alternative
  	 * is a another nested NO_SOCKET_TO_FD switch above.
***************
*** 1495,1505 ****
  	{
              /* Syslog this? */
  	}
  # ifdef CLIENT_SUPPORT
  	else
!             error (1, errno,
                     "closing down connection to %s",
                     current_parsed_root->hostname);
  # endif /* CLIENT_SUPPORT */
      }
  
--- 1507,1517 ----
  	{
              /* Syslog this? */
  	}
  # ifdef CLIENT_SUPPORT
  	else
!             error (0, errno,
                     "closing down connection to %s",
                     current_parsed_root->hostname);
  # endif /* CLIENT_SUPPORT */
      }
  
***************
*** 1510,1520 ****
  
  	do
  	    w = waitpid (bc->child_pid, (int *) 0, 0);
  	while (w == -1 && errno == EINTR);
  	if (w == -1)
! 	    error (1, errno, "waiting for process %d", bc->child_pid);
      }
      return 0;
  }
  
  
--- 1522,1532 ----
  
  	do
  	    w = waitpid (bc->child_pid, (int *) 0, 0);
  	while (w == -1 && errno == EINTR);
  	if (w == -1)
! 	    error (0, errno, "waiting for process %d", bc->child_pid);
      }
      return 0;
  }
  
  
