From a28d04e6eec0cc90f728eabef53fe0af446c3b7f Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 11 Jun 2004 03:48:35 +0000 Subject: [PATCH] This patch updates pgpipe() on win32 to log exactly which part of the 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 | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/port/pipe.c b/src/port/pipe.c index 9bbef1164e..64f31d3e03 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);