This patch updates pgpipe() on win32 to log exactly which part of the
authorBruce Momjian <bruce@momjian.us>
Fri, 11 Jun 2004 03:48:35 +0000 (03:48 +0000)
committerBruce Momjian <bruce@momjian.us>
Fri, 11 Jun 2004 03:48:35 +0000 (03:48 +0000)
call fails when it does. (As it is now, there is no way to figure out
the point of error). Shouldn't be a problem since it's most defintily
not a performance-critical path (only called on pgstat startup ATM).

This should help us debug the pipe error message that's on the win32
status page (which I myself have never been able to reproduce, and thus
haven't figured out a better way to debug yet)

Magnus Hagander

src/port/pipe.c

index 9bbef1164e767aa8bf6794f1d3330c1a6cb0cc89..64f31d3e035ac6b5fc5beef4c4e10a6b92d4d35f 100644 (file)
@@ -10,7 +10,7 @@
  * must be replaced with recv/send.
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/port/pipe.c,v 1.4 2004/05/18 20:18:59 momjian Exp $
+ *   $PostgreSQL: pgsql/src/port/pipe.c,v 1.5 2004/06/11 03:48:35 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -28,24 +28,49 @@ pgpipe(int handles[2])
    handles[0] = handles[1] = INVALID_SOCKET;
 
    if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
+   {
+       ereport(LOG,(errmsg_internal("pgpipe failed to create socket: %ui",WSAGetLastError())));
        return -1;
+   }
 
    memset((void *) &serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(0);
    serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-   if (bind(s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR ||
-       listen(s, 1) == SOCKET_ERROR ||
-       getsockname(s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR ||
-       (handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
+   if (bind(s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR) 
+   {
+       ereport(LOG,(errmsg_internal("pgpipe failed to bind: %ui",WSAGetLastError())));
+       closesocket(s);
+       return -1;
+   }
+   if (listen(s, 1) == SOCKET_ERROR)
+   {
+       ereport(LOG,(errmsg_internal("pgpipe failed to listen: %ui",WSAGetLastError())));
+       closesocket(s);
+       return -1;
+   }
+   if (getsockname(s, (SOCKADDR *) & serv_addr, &len) == SOCKET_ERROR) 
+   {
+       ereport(LOG,(errmsg_internal("pgpipe failed to getsockname: %ui",WSAGetLastError())));
+       closesocket(s);
+       return -1;
+   }
+   if ((handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
    {
+       ereport(LOG,(errmsg_internal("pgpipe failed to create socket 2: %ui",WSAGetLastError())));
        closesocket(s);
        return -1;
    }
 
-   if (connect(handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR ||
-       (handles[0] = accept(s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET)
+   if (connect(handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
+   {
+       ereport(LOG,(errmsg_internal("pgpipe failed to connect socket: %ui",WSAGetLastError())));
+       closesocket(s);
+       return -1;
+   }
+   if ((handles[0] = accept(s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET)
    {
+       ereport(LOG,(errmsg_internal("pgpipe failed to accept socket: %ui",WSAGetLastError())));
        closesocket(handles[1]);
        handles[1] = INVALID_SOCKET;
        closesocket(s);