Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita40814d

Browse files
committed
Handle invalid libpq sockets in more places
Also, make error messages consistent.From: Michael Paquier <michael.paquier@gmail.com>
1 parenta2fd62d commita40814d

File tree

7 files changed

+32
-9
lines changed

7 files changed

+32
-9
lines changed

‎src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ libpq_select(int timeout_ms)
331331
if (PQsocket(streamConn)<0)
332332
ereport(ERROR,
333333
(errcode_for_socket_access(),
334-
errmsg("socket not open")));
334+
errmsg("invalidsocket: %s",PQerrorMessage(streamConn))));
335335

336336
/* We use poll(2) if available, otherwise select(2) */
337337
{

‎src/bin/pg_basebackup/pg_recvlogical.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,14 @@ StreamLogicalLog(void)
360360
structtimevaltimeout;
361361
structtimeval*timeoutptr=NULL;
362362

363+
if (PQsocket(conn)<0)
364+
{
365+
fprintf(stderr,
366+
_("%s: invalid socket: %s"),
367+
progname,PQerrorMessage(conn));
368+
gotoerror;
369+
}
370+
363371
FD_ZERO(&input_mask);
364372
FD_SET(PQsocket(conn),&input_mask);
365373

‎src/bin/pg_basebackup/receivelog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,8 @@ CopyStreamPoll(PGconn *conn, long timeout_ms)
956956

957957
if (PQsocket(conn)<0)
958958
{
959-
fprintf(stderr,_("%s: socket not open"),progname);
959+
fprintf(stderr,_("%s: invalid socket: %s"),progname,
960+
PQerrorMessage(conn));
960961
return-1;
961962
}
962963

‎src/bin/pgbench/pgbench.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3797,7 +3797,7 @@ threadRun(void *arg)
37973797
sock=PQsocket(st->con);
37983798
if (sock<0)
37993799
{
3800-
fprintf(stderr,"bad socket: %s",PQerrorMessage(st->con));
3800+
fprintf(stderr,"invalid socket: %s",PQerrorMessage(st->con));
38013801
gotodone;
38023802
}
38033803

@@ -3867,7 +3867,8 @@ threadRun(void *arg)
38673867

38683868
if (sock<0)
38693869
{
3870-
fprintf(stderr,"bad socket: %s",PQerrorMessage(st->con));
3870+
fprintf(stderr,"invalid socket: %s",
3871+
PQerrorMessage(st->con));
38713872
gotodone;
38723873
}
38733874
if (FD_ISSET(sock,&input_mask)||

‎src/bin/scripts/vacuumdb.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void DisconnectDatabase(ParallelSlot *slot);
7070

7171
staticintselect_loop(intmaxFd,fd_set*workerset,bool*aborting);
7272

73-
staticvoidinit_slot(ParallelSlot*slot,PGconn*conn);
73+
staticvoidinit_slot(ParallelSlot*slot,PGconn*conn,constchar*progname);
7474

7575
staticvoidhelp(constchar*progname);
7676

@@ -421,14 +421,14 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
421421
* array contains the connection.
422422
*/
423423
slots= (ParallelSlot*)pg_malloc(sizeof(ParallelSlot)*concurrentCons);
424-
init_slot(slots,conn);
424+
init_slot(slots,conn,progname);
425425
if (parallel)
426426
{
427427
for (i=1;i<concurrentCons;i++)
428428
{
429429
conn=connectDatabase(dbname,host,port,username,prompt_password,
430430
progname, false, true);
431-
init_slot(slots+i,conn);
431+
init_slot(slots+i,conn,progname);
432432
}
433433
}
434434

@@ -917,11 +917,18 @@ select_loop(int maxFd, fd_set *workerset, bool *aborting)
917917
}
918918

919919
staticvoid
920-
init_slot(ParallelSlot*slot,PGconn*conn)
920+
init_slot(ParallelSlot*slot,PGconn*conn,constchar*progname)
921921
{
922922
slot->connection=conn;
923923
slot->isFree= true;
924924
slot->sock=PQsocket(conn);
925+
926+
if (slot->sock<0)
927+
{
928+
fprintf(stderr,_("%s: invalid socket: %s"),progname,
929+
PQerrorMessage(conn));
930+
exit(1);
931+
}
925932
}
926933

927934
staticvoid

‎src/interfaces/libpq/fe-misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
10581058
if (conn->sock==PGINVALID_SOCKET)
10591059
{
10601060
printfPQExpBuffer(&conn->errorMessage,
1061-
libpq_gettext("socket not open\n"));
1061+
libpq_gettext("invalid socket\n"));
10621062
return-1;
10631063
}
10641064

‎src/test/isolation/isolationtester.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,12 @@ try_complete_step(Step *step, int flags)
705705
PGresult*res;
706706
boolcanceled= false;
707707

708+
if (sock<0)
709+
{
710+
fprintf(stderr,"invalid socket: %s",PQerrorMessage(conn));
711+
exit_nicely();
712+
}
713+
708714
gettimeofday(&start_time,NULL);
709715
FD_ZERO(&read_set);
710716

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp