8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -699,7 +699,7 @@ connectNoDelay(PGconn *conn)
699
699
{
700
700
char sebuf [256 ];
701
701
702
- printfPQExpBuffer (& conn -> errorMessage ,
702
+ appendPQExpBuffer (& conn -> errorMessage ,
703
703
libpq_gettext ("could not set socket to TCP no delay mode: %s\n" ),
704
704
SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
705
705
return 0 ;
@@ -729,7 +729,7 @@ connectFailureMessage(PGconn *conn, int errorno)
729
729
NULL , 0 ,
730
730
service , sizeof (service ),
731
731
NI_NUMERICSERV );
732
- printfPQExpBuffer (& conn -> errorMessage ,
732
+ appendPQExpBuffer (& conn -> errorMessage ,
733
733
libpq_gettext ("could not connect to server: %s\n"
734
734
"\tIs the server running locally and accepting\n"
735
735
"\tconnections on Unix domain socket \"%s\"?\n" ),
@@ -739,7 +739,7 @@ connectFailureMessage(PGconn *conn, int errorno)
739
739
else
740
740
#endif /* HAVE_UNIX_SOCKETS */
741
741
{
742
- printfPQExpBuffer (& conn -> errorMessage ,
742
+ appendPQExpBuffer (& conn -> errorMessage ,
743
743
libpq_gettext ("could not connect to server: %s\n"
744
744
"\tIs the server running on host \"%s\" and accepting\n"
745
745
"\tTCP/IP connections on port %s?\n" ),
@@ -829,11 +829,11 @@ connectDBStart(PGconn *conn)
829
829
if (ret || !addrs )
830
830
{
831
831
if (node )
832
- printfPQExpBuffer (& conn -> errorMessage ,
832
+ appendPQExpBuffer (& conn -> errorMessage ,
833
833
libpq_gettext ("could not translate host name \"%s\" to address: %s\n" ),
834
834
node , gai_strerror (ret ));
835
835
else
836
- printfPQExpBuffer (& conn -> errorMessage ,
836
+ appendPQExpBuffer (& conn -> errorMessage ,
837
837
libpq_gettext ("could not translate Unix-domain socket path \"%s\" to address: %s\n" ),
838
838
portstr , gai_strerror (ret ));
839
839
if (addrs )
@@ -924,6 +924,8 @@ connectDBComplete(PGconn *conn)
924
924
switch (flag )
925
925
{
926
926
case PGRES_POLLING_OK :
927
+ /* Reset stored error messages since we now have a working connection */
928
+ resetPQExpBuffer (& conn -> errorMessage );
927
929
return 1 ; /* success! */
928
930
929
931
case PGRES_POLLING_READING :
@@ -1033,7 +1035,7 @@ PQconnectPoll(PGconn *conn)
1033
1035
break ;
1034
1036
1035
1037
default :
1036
- printfPQExpBuffer (& conn -> errorMessage ,
1038
+ appendPQExpBuffer (& conn -> errorMessage ,
1037
1039
libpq_gettext (
1038
1040
"invalid connection state, "
1039
1041
"probably indicative of memory corruption\n"
@@ -1077,7 +1079,7 @@ PQconnectPoll(PGconn *conn)
1077
1079
conn -> addr_cur = addr_cur -> ai_next ;
1078
1080
continue ;
1079
1081
}
1080
- printfPQExpBuffer (& conn -> errorMessage ,
1082
+ appendPQExpBuffer (& conn -> errorMessage ,
1081
1083
libpq_gettext ("could not create socket: %s\n" ),
1082
1084
SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1083
1085
break ;
@@ -1100,7 +1102,7 @@ PQconnectPoll(PGconn *conn)
1100
1102
}
1101
1103
if (!pg_set_noblock (conn -> sock ))
1102
1104
{
1103
- printfPQExpBuffer (& conn -> errorMessage ,
1105
+ appendPQExpBuffer (& conn -> errorMessage ,
1104
1106
libpq_gettext ("could not set socket to non-blocking mode: %s\n" ),
1105
1107
SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1106
1108
closesocket (conn -> sock );
@@ -1112,7 +1114,7 @@ PQconnectPoll(PGconn *conn)
1112
1114
#ifdef F_SETFD
1113
1115
if (fcntl (conn -> sock , F_SETFD , FD_CLOEXEC ) == -1 )
1114
1116
{
1115
- printfPQExpBuffer (& conn -> errorMessage ,
1117
+ appendPQExpBuffer (& conn -> errorMessage ,
1116
1118
libpq_gettext ("could not set socket to close-on-exec mode: %s\n" ),
1117
1119
SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1118
1120
closesocket (conn -> sock );
@@ -1199,7 +1201,7 @@ PQconnectPoll(PGconn *conn)
1199
1201
if (getsockopt (conn -> sock , SOL_SOCKET , SO_ERROR ,
1200
1202
(char * ) & optval , & optlen ) == -1 )
1201
1203
{
1202
- printfPQExpBuffer (& conn -> errorMessage ,
1204
+ appendPQExpBuffer (& conn -> errorMessage ,
1203
1205
libpq_gettext ("could not get socket error status: %s\n" ),
1204
1206
SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1205
1207
goto error_return ;
@@ -1237,7 +1239,7 @@ PQconnectPoll(PGconn *conn)
1237
1239
(struct sockaddr * ) & conn -> laddr .addr ,
1238
1240
& conn -> laddr .salen ) < 0 )
1239
1241
{
1240
- printfPQExpBuffer (& conn -> errorMessage ,
1242
+ appendPQExpBuffer (& conn -> errorMessage ,
1241
1243
libpq_gettext ("could not get client address from socket: %s\n" ),
1242
1244
SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1243
1245
goto error_return ;
@@ -1281,7 +1283,7 @@ PQconnectPoll(PGconn *conn)
1281
1283
pv = htonl (NEGOTIATE_SSL_CODE );
1282
1284
if (pqPacketSend (conn , 0 , & pv , sizeof (pv )) != STATUS_OK )
1283
1285
{
1284
- printfPQExpBuffer (& conn -> errorMessage ,
1286
+ appendPQExpBuffer (& conn -> errorMessage ,
1285
1287
libpq_gettext ("could not send SSL negotiation packet: %s\n" ),
1286
1288
SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1287
1289
goto error_return ;
@@ -1303,6 +1305,7 @@ PQconnectPoll(PGconn *conn)
1303
1305
EnvironmentOptions );
1304
1306
if (!startpacket )
1305
1307
{
1308
+ /* will not appendbuffer here, since it's likely to also run out of memory */
1306
1309
printfPQExpBuffer (& conn -> errorMessage ,
1307
1310
libpq_gettext ("out of memory\n" ));
1308
1311
goto error_return ;
@@ -1316,7 +1319,7 @@ PQconnectPoll(PGconn *conn)
1316
1319
*/
1317
1320
if (pqPacketSend (conn , 0 , startpacket , packetlen ) != STATUS_OK )
1318
1321
{
1319
- printfPQExpBuffer (& conn -> errorMessage ,
1322
+ appendPQExpBuffer (& conn -> errorMessage ,
1320
1323
libpq_gettext ("could not send startup packet: %s\n" ),
1321
1324
SOCK_STRERROR (SOCK_ERRNO , sebuf , sizeof (sebuf )));
1322
1325
free (startpacket );
@@ -1381,7 +1384,7 @@ PQconnectPoll(PGconn *conn)
1381
1384
if (conn -> sslmode [0 ] == 'r' ) /* "require" */
1382
1385
{
1383
1386
/* Require SSL, but server does not want it */
1384
- printfPQExpBuffer (& conn -> errorMessage ,
1387
+ appendPQExpBuffer (& conn -> errorMessage ,
1385
1388
libpq_gettext ("server does not support SSL, but SSL was required\n" ));
1386
1389
goto error_return ;
1387
1390
}
@@ -1398,7 +1401,7 @@ PQconnectPoll(PGconn *conn)
1398
1401
if (conn -> sslmode [0 ] == 'r' ) /* "require" */
1399
1402
{
1400
1403
/* Require SSL, but server is too old */
1401
- printfPQExpBuffer (& conn -> errorMessage ,
1404
+ appendPQExpBuffer (& conn -> errorMessage ,
1402
1405
libpq_gettext ("server does not support SSL, but SSL was required\n" ));
1403
1406
goto error_return ;
1404
1407
}
@@ -1414,7 +1417,7 @@ PQconnectPoll(PGconn *conn)
1414
1417
}
1415
1418
else
1416
1419
{
1417
- printfPQExpBuffer (& conn -> errorMessage ,
1420
+ appendPQExpBuffer (& conn -> errorMessage ,
1418
1421
libpq_gettext ("received invalid response to SSL negotiation: %c\n" ),
1419
1422
SSLok );
1420
1423
goto error_return ;
@@ -1489,7 +1492,7 @@ PQconnectPoll(PGconn *conn)
1489
1492
*/
1490
1493
if (!(beresp == 'R' || beresp == 'E' ))
1491
1494
{
1492
- printfPQExpBuffer (& conn -> errorMessage ,
1495
+ appendPQExpBuffer (& conn -> errorMessage ,
1493
1496
libpq_gettext (
1494
1497
"expected authentication request from "
1495
1498
"server, but received %c\n" ),
@@ -1522,7 +1525,7 @@ PQconnectPoll(PGconn *conn)
1522
1525
*/
1523
1526
if (beresp == 'R' && (msgLength < 8 || msgLength > 2000 ))
1524
1527
{
1525
- printfPQExpBuffer (& conn -> errorMessage ,
1528
+ appendPQExpBuffer (& conn -> errorMessage ,
1526
1529
libpq_gettext (
1527
1530
"expected authentication request from "
1528
1531
"server, but received %c\n" ),
@@ -1534,7 +1537,7 @@ PQconnectPoll(PGconn *conn)
1534
1537
{
1535
1538
/* Handle error from a pre-3.0 server */
1536
1539
conn -> inCursor = conn -> inStart + 1 ; /* reread data */
1537
- if (pqGets (& conn -> errorMessage , conn ))
1540
+ if (pqGets_append (& conn -> errorMessage , conn ))
1538
1541
{
1539
1542
/* We'll come back when there is more data */
1540
1543
return PGRES_POLLING_READING ;
@@ -1601,7 +1604,7 @@ PQconnectPoll(PGconn *conn)
1601
1604
}
1602
1605
else
1603
1606
{
1604
- if (pqGets (& conn -> errorMessage , conn ))
1607
+ if (pqGets_append (& conn -> errorMessage , conn ))
1605
1608
{
1606
1609
/* We'll come back when there is more data */
1607
1610
return PGRES_POLLING_READING ;
@@ -1788,7 +1791,7 @@ PQconnectPoll(PGconn *conn)
1788
1791
if (res )
1789
1792
{
1790
1793
if (res -> resultStatus != PGRES_FATAL_ERROR )
1791
- printfPQExpBuffer (& conn -> errorMessage ,
1794
+ appendPQExpBuffer (& conn -> errorMessage ,
1792
1795
libpq_gettext ("unexpected message from server during startup\n" ));
1793
1796
1794
1797
/*
@@ -1855,7 +1858,7 @@ PQconnectPoll(PGconn *conn)
1855
1858
return PGRES_POLLING_OK ;
1856
1859
1857
1860
default :
1858
- printfPQExpBuffer (& conn -> errorMessage ,
1861
+ appendPQExpBuffer (& conn -> errorMessage ,
1859
1862
libpq_gettext (
1860
1863
"invalid connection state %c, "
1861
1864
"probably indicative of memory corruption\n"
0 commit comments