88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.363 2008/10/23 16:17:19 mha Exp $
11+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.364 2008/10/27 09:42:31 mha Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -699,7 +699,7 @@ connectNoDelay(PGconn *conn)
699699{
700700char sebuf [256 ];
701701
702- printfPQExpBuffer (& conn -> errorMessage ,
702+ appendPQExpBuffer (& conn -> errorMessage ,
703703libpq_gettext ("could not set socket to TCP no delay mode: %s\n" ),
704704SOCK_STRERROR (SOCK_ERRNO ,sebuf ,sizeof (sebuf )));
705705return 0 ;
@@ -729,7 +729,7 @@ connectFailureMessage(PGconn *conn, int errorno)
729729NULL ,0 ,
730730service ,sizeof (service ),
731731NI_NUMERICSERV );
732- printfPQExpBuffer (& conn -> errorMessage ,
732+ appendPQExpBuffer (& conn -> errorMessage ,
733733libpq_gettext ("could not connect to server: %s\n"
734734"\tIs the server running locally and accepting\n"
735735"\tconnections on Unix domain socket \"%s\"?\n" ),
@@ -739,7 +739,7 @@ connectFailureMessage(PGconn *conn, int errorno)
739739else
740740#endif /* HAVE_UNIX_SOCKETS */
741741{
742- printfPQExpBuffer (& conn -> errorMessage ,
742+ appendPQExpBuffer (& conn -> errorMessage ,
743743libpq_gettext ("could not connect to server: %s\n"
744744"\tIs the server running on host \"%s\" and accepting\n"
745745"\tTCP/IP connections on port %s?\n" ),
@@ -829,11 +829,11 @@ connectDBStart(PGconn *conn)
829829if (ret || !addrs )
830830{
831831if (node )
832- printfPQExpBuffer (& conn -> errorMessage ,
832+ appendPQExpBuffer (& conn -> errorMessage ,
833833libpq_gettext ("could not translate host name \"%s\" to address: %s\n" ),
834834node ,gai_strerror (ret ));
835835else
836- printfPQExpBuffer (& conn -> errorMessage ,
836+ appendPQExpBuffer (& conn -> errorMessage ,
837837libpq_gettext ("could not translate Unix-domain socket path \"%s\" to address: %s\n" ),
838838portstr ,gai_strerror (ret ));
839839if (addrs )
@@ -924,6 +924,8 @@ connectDBComplete(PGconn *conn)
924924switch (flag )
925925{
926926case PGRES_POLLING_OK :
927+ /* Reset stored error messages since we now have a working connection */
928+ resetPQExpBuffer (& conn -> errorMessage );
927929return 1 ;/* success! */
928930
929931case PGRES_POLLING_READING :
@@ -1033,7 +1035,7 @@ PQconnectPoll(PGconn *conn)
10331035break ;
10341036
10351037default :
1036- printfPQExpBuffer (& conn -> errorMessage ,
1038+ appendPQExpBuffer (& conn -> errorMessage ,
10371039libpq_gettext (
10381040"invalid connection state, "
10391041"probably indicative of memory corruption\n"
@@ -1077,7 +1079,7 @@ PQconnectPoll(PGconn *conn)
10771079conn -> addr_cur = addr_cur -> ai_next ;
10781080continue ;
10791081}
1080- printfPQExpBuffer (& conn -> errorMessage ,
1082+ appendPQExpBuffer (& conn -> errorMessage ,
10811083libpq_gettext ("could not create socket: %s\n" ),
10821084SOCK_STRERROR (SOCK_ERRNO ,sebuf ,sizeof (sebuf )));
10831085break ;
@@ -1100,7 +1102,7 @@ PQconnectPoll(PGconn *conn)
11001102}
11011103if (!pg_set_noblock (conn -> sock ))
11021104{
1103- printfPQExpBuffer (& conn -> errorMessage ,
1105+ appendPQExpBuffer (& conn -> errorMessage ,
11041106libpq_gettext ("could not set socket to non-blocking mode: %s\n" ),
11051107SOCK_STRERROR (SOCK_ERRNO ,sebuf ,sizeof (sebuf )));
11061108closesocket (conn -> sock );
@@ -1112,7 +1114,7 @@ PQconnectPoll(PGconn *conn)
11121114#ifdef F_SETFD
11131115if (fcntl (conn -> sock ,F_SETFD ,FD_CLOEXEC )== -1 )
11141116{
1115- printfPQExpBuffer (& conn -> errorMessage ,
1117+ appendPQExpBuffer (& conn -> errorMessage ,
11161118libpq_gettext ("could not set socket to close-on-exec mode: %s\n" ),
11171119SOCK_STRERROR (SOCK_ERRNO ,sebuf ,sizeof (sebuf )));
11181120closesocket (conn -> sock );
@@ -1199,7 +1201,7 @@ PQconnectPoll(PGconn *conn)
11991201if (getsockopt (conn -> sock ,SOL_SOCKET ,SO_ERROR ,
12001202 (char * )& optval ,& optlen )== -1 )
12011203{
1202- printfPQExpBuffer (& conn -> errorMessage ,
1204+ appendPQExpBuffer (& conn -> errorMessage ,
12031205libpq_gettext ("could not get socket error status: %s\n" ),
12041206SOCK_STRERROR (SOCK_ERRNO ,sebuf ,sizeof (sebuf )));
12051207gotoerror_return ;
@@ -1237,7 +1239,7 @@ PQconnectPoll(PGconn *conn)
12371239(struct sockaddr * )& conn -> laddr .addr ,
12381240& conn -> laddr .salen )< 0 )
12391241{
1240- printfPQExpBuffer (& conn -> errorMessage ,
1242+ appendPQExpBuffer (& conn -> errorMessage ,
12411243libpq_gettext ("could not get client address from socket: %s\n" ),
12421244SOCK_STRERROR (SOCK_ERRNO ,sebuf ,sizeof (sebuf )));
12431245gotoerror_return ;
@@ -1281,7 +1283,7 @@ PQconnectPoll(PGconn *conn)
12811283pv = htonl (NEGOTIATE_SSL_CODE );
12821284if (pqPacketSend (conn ,0 ,& pv ,sizeof (pv ))!= STATUS_OK )
12831285{
1284- printfPQExpBuffer (& conn -> errorMessage ,
1286+ appendPQExpBuffer (& conn -> errorMessage ,
12851287libpq_gettext ("could not send SSL negotiation packet: %s\n" ),
12861288SOCK_STRERROR (SOCK_ERRNO ,sebuf ,sizeof (sebuf )));
12871289gotoerror_return ;
@@ -1303,6 +1305,7 @@ PQconnectPoll(PGconn *conn)
13031305EnvironmentOptions );
13041306if (!startpacket )
13051307{
1308+ /* will not appendbuffer here, since it's likely to also run out of memory */
13061309printfPQExpBuffer (& conn -> errorMessage ,
13071310libpq_gettext ("out of memory\n" ));
13081311gotoerror_return ;
@@ -1316,7 +1319,7 @@ PQconnectPoll(PGconn *conn)
13161319 */
13171320if (pqPacketSend (conn ,0 ,startpacket ,packetlen )!= STATUS_OK )
13181321{
1319- printfPQExpBuffer (& conn -> errorMessage ,
1322+ appendPQExpBuffer (& conn -> errorMessage ,
13201323libpq_gettext ("could not send startup packet: %s\n" ),
13211324SOCK_STRERROR (SOCK_ERRNO ,sebuf ,sizeof (sebuf )));
13221325free (startpacket );
@@ -1381,7 +1384,7 @@ PQconnectPoll(PGconn *conn)
13811384if (conn -> sslmode [0 ]== 'r' )/* "require" */
13821385{
13831386/* Require SSL, but server does not want it */
1384- printfPQExpBuffer (& conn -> errorMessage ,
1387+ appendPQExpBuffer (& conn -> errorMessage ,
13851388libpq_gettext ("server does not support SSL, but SSL was required\n" ));
13861389gotoerror_return ;
13871390}
@@ -1398,7 +1401,7 @@ PQconnectPoll(PGconn *conn)
13981401if (conn -> sslmode [0 ]== 'r' )/* "require" */
13991402{
14001403/* Require SSL, but server is too old */
1401- printfPQExpBuffer (& conn -> errorMessage ,
1404+ appendPQExpBuffer (& conn -> errorMessage ,
14021405libpq_gettext ("server does not support SSL, but SSL was required\n" ));
14031406gotoerror_return ;
14041407}
@@ -1414,7 +1417,7 @@ PQconnectPoll(PGconn *conn)
14141417}
14151418else
14161419{
1417- printfPQExpBuffer (& conn -> errorMessage ,
1420+ appendPQExpBuffer (& conn -> errorMessage ,
14181421libpq_gettext ("received invalid response to SSL negotiation: %c\n" ),
14191422SSLok );
14201423gotoerror_return ;
@@ -1489,7 +1492,7 @@ PQconnectPoll(PGconn *conn)
14891492 */
14901493if (!(beresp == 'R' || beresp == 'E' ))
14911494{
1492- printfPQExpBuffer (& conn -> errorMessage ,
1495+ appendPQExpBuffer (& conn -> errorMessage ,
14931496libpq_gettext (
14941497"expected authentication request from "
14951498"server, but received %c\n" ),
@@ -1522,7 +1525,7 @@ PQconnectPoll(PGconn *conn)
15221525 */
15231526if (beresp == 'R' && (msgLength < 8 || msgLength > 2000 ))
15241527{
1525- printfPQExpBuffer (& conn -> errorMessage ,
1528+ appendPQExpBuffer (& conn -> errorMessage ,
15261529libpq_gettext (
15271530"expected authentication request from "
15281531"server, but received %c\n" ),
@@ -1534,7 +1537,7 @@ PQconnectPoll(PGconn *conn)
15341537{
15351538/* Handle error from a pre-3.0 server */
15361539conn -> inCursor = conn -> inStart + 1 ;/* reread data */
1537- if (pqGets (& conn -> errorMessage ,conn ))
1540+ if (pqGets_append (& conn -> errorMessage ,conn ))
15381541{
15391542/* We'll come back when there is more data */
15401543return PGRES_POLLING_READING ;
@@ -1601,7 +1604,7 @@ PQconnectPoll(PGconn *conn)
16011604}
16021605else
16031606{
1604- if (pqGets (& conn -> errorMessage ,conn ))
1607+ if (pqGets_append (& conn -> errorMessage ,conn ))
16051608{
16061609/* We'll come back when there is more data */
16071610return PGRES_POLLING_READING ;
@@ -1788,7 +1791,7 @@ PQconnectPoll(PGconn *conn)
17881791if (res )
17891792{
17901793if (res -> resultStatus != PGRES_FATAL_ERROR )
1791- printfPQExpBuffer (& conn -> errorMessage ,
1794+ appendPQExpBuffer (& conn -> errorMessage ,
17921795libpq_gettext ("unexpected message from server during startup\n" ));
17931796
17941797/*
@@ -1855,7 +1858,7 @@ PQconnectPoll(PGconn *conn)
18551858return PGRES_POLLING_OK ;
18561859
18571860default :
1858- printfPQExpBuffer (& conn -> errorMessage ,
1861+ appendPQExpBuffer (& conn -> errorMessage ,
18591862libpq_gettext (
18601863"invalid connection state %c, "
18611864"probably indicative of memory corruption\n"