diff --git a/src/port/pipe.c b/src/port/pipe.c
index 9bbef1164e767aa8bf6794f1d3330c1a6cb0cc89..64f31d3e035ac6b5fc5beef4c4e10a6b92d4d35f 100644
--- a/src/port/pipe.c
+++ b/src/port/pipe.c
@@ -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);