Skip to content

Commit 82c3cd9

Browse files
committed
Factor out system call names from error messages
Instead, put them in via a format placeholder. This reduces the number of distinct translatable messages and also reduces the chances of typos during translation. We already did this for the system call arguments in a number of cases, so this is just the same thing taken a bit further. Discussion: https://www.postgresql.org/message-id/flat/92d6f545-5102-65d8-3c87-489f71ea0a37%40enterprisedb.com
1 parent 9486844 commit 82c3cd9

File tree

10 files changed

+55
-52
lines changed

10 files changed

+55
-52
lines changed

src/backend/libpq/pqcomm.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
485485
{
486486
ereport(LOG,
487487
(errcode_for_socket_access(),
488-
/* translator: first %s is IPv4, IPv6, or Unix */
489-
errmsg("setsockopt(SO_REUSEADDR) failed for %s address \"%s\": %m",
488+
/* translator: third %s is IPv4, IPv6, or Unix */
489+
errmsg("%s(%s) failed for %s address \"%s\": %m",
490+
"setsockopt", "SO_REUSEADDR",
490491
familyDesc, addrDesc)));
491492
closesocket(fd);
492493
continue;
@@ -502,8 +503,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
502503
{
503504
ereport(LOG,
504505
(errcode_for_socket_access(),
505-
/* translator: first %s is IPv4, IPv6, or Unix */
506-
errmsg("setsockopt(IPV6_V6ONLY) failed for %s address \"%s\": %m",
506+
/* translator: third %s is IPv4, IPv6, or Unix */
507+
errmsg("%s(%s) failed for %s address \"%s\": %m",
508+
"setsockopt", "IPV6_V6ONLY",
507509
familyDesc, addrDesc)));
508510
closesocket(fd);
509511
continue;
@@ -741,7 +743,7 @@ StreamConnection(pgsocket server_fd, Port *port)
741743
&port->laddr.salen) < 0)
742744
{
743745
ereport(LOG,
744-
(errmsg("getsockname() failed: %m")));
746+
(errmsg("%s() failed: %m", "getsockname")));
745747
return STATUS_ERROR;
746748
}
747749

@@ -761,7 +763,7 @@ StreamConnection(pgsocket server_fd, Port *port)
761763
(char *) &on, sizeof(on)) < 0)
762764
{
763765
ereport(LOG,
764-
(errmsg("setsockopt(%s) failed: %m", "TCP_NODELAY")));
766+
(errmsg("%s(%s) failed: %m", "setsockopt", "TCP_NODELAY")));
765767
return STATUS_ERROR;
766768
}
767769
#endif
@@ -770,7 +772,7 @@ StreamConnection(pgsocket server_fd, Port *port)
770772
(char *) &on, sizeof(on)) < 0)
771773
{
772774
ereport(LOG,
773-
(errmsg("setsockopt(%s) failed: %m", "SO_KEEPALIVE")));
775+
(errmsg("%s(%s) failed: %m", "setsockopt", "SO_KEEPALIVE")));
774776
return STATUS_ERROR;
775777
}
776778

@@ -802,7 +804,7 @@ StreamConnection(pgsocket server_fd, Port *port)
802804
&optlen) < 0)
803805
{
804806
ereport(LOG,
805-
(errmsg("getsockopt(%s) failed: %m", "SO_SNDBUF")));
807+
(errmsg("%s(%s) failed: %m", "getsockopt", "SO_SNDBUF")));
806808
return STATUS_ERROR;
807809
}
808810
newopt = PQ_SEND_BUFFER_SIZE * 4;
@@ -812,7 +814,7 @@ StreamConnection(pgsocket server_fd, Port *port)
812814
sizeof(newopt)) < 0)
813815
{
814816
ereport(LOG,
815-
(errmsg("setsockopt(%s) failed: %m", "SO_SNDBUF")));
817+
(errmsg("%s(%s) failed: %m", "setsockopt", "SO_SNDBUF")));
816818
return STATUS_ERROR;
817819
}
818820
}
@@ -1594,8 +1596,8 @@ pq_setkeepaliveswin32(Port *port, int idle, int interval)
15941596
!= 0)
15951597
{
15961598
ereport(LOG,
1597-
(errmsg("WSAIoctl(%s) failed: %d",
1598-
"SIO_KEEPALIVE_VALS", WSAGetLastError())));
1599+
(errmsg("%s(%s) failed: error code %d",
1600+
"WSAIoctl", "SIO_KEEPALIVE_VALS", WSAGetLastError())));
15991601
return STATUS_ERROR;
16001602
}
16011603
if (port->keepalives_idle != idle)
@@ -1626,7 +1628,7 @@ pq_getkeepalivesidle(Port *port)
16261628
&size) < 0)
16271629
{
16281630
ereport(LOG,
1629-
(errmsg("getsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR)));
1631+
(errmsg("%s(%s) failed: %m", "getsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
16301632
port->default_keepalives_idle = -1; /* don't know */
16311633
}
16321634
#else /* WIN32 */
@@ -1671,7 +1673,7 @@ pq_setkeepalivesidle(int idle, Port *port)
16711673
(char *) &idle, sizeof(idle)) < 0)
16721674
{
16731675
ereport(LOG,
1674-
(errmsg("setsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR)));
1676+
(errmsg("%s(%s) failed: %m", "setsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
16751677
return STATUS_ERROR;
16761678
}
16771679

@@ -1711,7 +1713,7 @@ pq_getkeepalivesinterval(Port *port)
17111713
&size) < 0)
17121714
{
17131715
ereport(LOG,
1714-
(errmsg("getsockopt(%s) failed: %m", "TCP_KEEPINTVL")));
1716+
(errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPINTVL")));
17151717
port->default_keepalives_interval = -1; /* don't know */
17161718
}
17171719
#else
@@ -1755,7 +1757,7 @@ pq_setkeepalivesinterval(int interval, Port *port)
17551757
(char *) &interval, sizeof(interval)) < 0)
17561758
{
17571759
ereport(LOG,
1758-
(errmsg("setsockopt(%s) failed: %m", "TCP_KEEPINTVL")));
1760+
(errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPINTVL")));
17591761
return STATUS_ERROR;
17601762
}
17611763

@@ -1767,7 +1769,7 @@ pq_setkeepalivesinterval(int interval, Port *port)
17671769
if (interval != 0)
17681770
{
17691771
ereport(LOG,
1770-
(errmsg("setsockopt(%s) not supported", "TCP_KEEPINTVL")));
1772+
(errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPINTVL")));
17711773
return STATUS_ERROR;
17721774
}
17731775
#endif
@@ -1794,7 +1796,7 @@ pq_getkeepalivescount(Port *port)
17941796
&size) < 0)
17951797
{
17961798
ereport(LOG,
1797-
(errmsg("getsockopt(%s) failed: %m", "TCP_KEEPCNT")));
1799+
(errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPCNT")));
17981800
port->default_keepalives_count = -1; /* don't know */
17991801
}
18001802
}
@@ -1833,7 +1835,7 @@ pq_setkeepalivescount(int count, Port *port)
18331835
(char *) &count, sizeof(count)) < 0)
18341836
{
18351837
ereport(LOG,
1836-
(errmsg("setsockopt(%s) failed: %m", "TCP_KEEPCNT")));
1838+
(errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPCNT")));
18371839
return STATUS_ERROR;
18381840
}
18391841

@@ -1842,7 +1844,7 @@ pq_setkeepalivescount(int count, Port *port)
18421844
if (count != 0)
18431845
{
18441846
ereport(LOG,
1845-
(errmsg("setsockopt(%s) not supported", "TCP_KEEPCNT")));
1847+
(errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPCNT")));
18461848
return STATUS_ERROR;
18471849
}
18481850
#endif
@@ -1869,7 +1871,7 @@ pq_gettcpusertimeout(Port *port)
18691871
&size) < 0)
18701872
{
18711873
ereport(LOG,
1872-
(errmsg("getsockopt(%s) failed: %m", "TCP_USER_TIMEOUT")));
1874+
(errmsg("%s(%s) failed: %m", "getsockopt", "TCP_USER_TIMEOUT")));
18731875
port->default_tcp_user_timeout = -1; /* don't know */
18741876
}
18751877
}
@@ -1908,7 +1910,7 @@ pq_settcpusertimeout(int timeout, Port *port)
19081910
(char *) &timeout, sizeof(timeout)) < 0)
19091911
{
19101912
ereport(LOG,
1911-
(errmsg("setsockopt(%s) failed: %m", "TCP_USER_TIMEOUT")));
1913+
(errmsg("%s(%s) failed: %m", "setsockopt", "TCP_USER_TIMEOUT")));
19121914
return STATUS_ERROR;
19131915
}
19141916

@@ -1917,7 +1919,7 @@ pq_settcpusertimeout(int timeout, Port *port)
19171919
if (timeout != 0)
19181920
{
19191921
ereport(LOG,
1920-
(errmsg("setsockopt(%s) not supported", "TCP_USER_TIMEOUT")));
1922+
(errmsg("%s(%s) not supported", "setsockopt", "TCP_USER_TIMEOUT")));
19211923
return STATUS_ERROR;
19221924
}
19231925
#endif

src/backend/postmaster/pgstat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ pgstat_init(void)
618618
(char *) &old_rcvbuf, &rcvbufsize) < 0)
619619
{
620620
ereport(LOG,
621-
(errmsg("getsockopt(%s) failed: %m", "SO_RCVBUF")));
621+
(errmsg("%s(%s) failed: %m", "getsockopt", "SO_RCVBUF")));
622622
/* if we can't get existing size, always try to set it */
623623
old_rcvbuf = 0;
624624
}
@@ -629,7 +629,7 @@ pgstat_init(void)
629629
if (setsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
630630
(char *) &new_rcvbuf, sizeof(new_rcvbuf)) < 0)
631631
ereport(LOG,
632-
(errmsg("setsockopt(%s) failed: %m", "SO_RCVBUF")));
632+
(errmsg("%s(%s) failed: %m", "setsockopt", "SO_RCVBUF")));
633633
}
634634
}
635635

src/backend/storage/ipc/latch.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,8 @@ WaitEventAdjustEpoll(WaitEventSet *set, WaitEvent *event, int action)
10611061
if (rc < 0)
10621062
ereport(ERROR,
10631063
(errcode_for_socket_access(),
1064-
/* translator: %s is a syscall name, such as "poll()" */
1065-
errmsg("%s failed: %m",
1066-
"epoll_ctl()")));
1064+
errmsg("%s() failed: %m",
1065+
"epoll_ctl")));
10671066
}
10681067
#endif
10691068

@@ -1231,9 +1230,8 @@ WaitEventAdjustKqueue(WaitEventSet *set, WaitEvent *event, int old_events)
12311230
else
12321231
ereport(ERROR,
12331232
(errcode_for_socket_access(),
1234-
/* translator: %s is a syscall name, such as "poll()" */
1235-
errmsg("%s failed: %m",
1236-
"kevent()")));
1233+
errmsg("%s() failed: %m",
1234+
"kevent")));
12371235
}
12381236
else if (event->events == WL_POSTMASTER_DEATH &&
12391237
PostmasterPid != getppid() &&
@@ -1461,9 +1459,8 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
14611459
waiting = false;
14621460
ereport(ERROR,
14631461
(errcode_for_socket_access(),
1464-
/* translator: %s is a syscall name, such as "poll()" */
1465-
errmsg("%s failed: %m",
1466-
"epoll_wait()")));
1462+
errmsg("%s() failed: %m",
1463+
"epoll_wait")));
14671464
}
14681465
return 0;
14691466
}
@@ -1614,9 +1611,8 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
16141611
waiting = false;
16151612
ereport(ERROR,
16161613
(errcode_for_socket_access(),
1617-
/* translator: %s is a syscall name, such as "poll()" */
1618-
errmsg("%s failed: %m",
1619-
"kevent()")));
1614+
errmsg("%s() failed: %m",
1615+
"kevent")));
16201616
}
16211617
return 0;
16221618
}
@@ -1731,9 +1727,8 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
17311727
waiting = false;
17321728
ereport(ERROR,
17331729
(errcode_for_socket_access(),
1734-
/* translator: %s is a syscall name, such as "poll()" */
1735-
errmsg("%s failed: %m",
1736-
"poll()")));
1730+
errmsg("%s() failed: %m",
1731+
"poll")));
17371732
}
17381733
return 0;
17391734
}

src/bin/pg_basebackup/pg_recvlogical.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ StreamLogicalLog(void)
411411
}
412412
else if (r < 0)
413413
{
414-
pg_log_error("select() failed: %m");
414+
pg_log_error("%s() failed: %m", "select");
415415
goto error;
416416
}
417417

src/bin/pg_basebackup/receivelog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ CopyStreamPoll(PGconn *conn, long timeout_ms, pgsocket stop_socket)
897897
{
898898
if (errno == EINTR)
899899
return 0; /* Got a signal, so not an error */
900-
pg_log_error("select() failed: %m");
900+
pg_log_error("%s() failed: %m", "select");
901901
return -1;
902902
}
903903
if (ret > 0 && FD_ISSET(connsocket, &input_mask))

src/bin/pg_dump/parallel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ init_parallel_dump_utils(void)
251251
err = WSAStartup(MAKEWORD(2, 2), &wsaData);
252252
if (err != 0)
253253
{
254-
pg_log_error("WSAStartup failed: %d", err);
254+
pg_log_error("%s() failed: error code %d", "WSAStartup", err);
255255
exit_nicely(1);
256256
}
257257

@@ -1611,7 +1611,7 @@ getMessageFromWorker(ParallelState *pstate, bool do_wait, int *worker)
16111611
}
16121612

16131613
if (i < 0)
1614-
fatal("select() failed: %m");
1614+
fatal("%s() failed: %m", "select");
16151615

16161616
for (i = 0; i < pstate->numWorkers; i++)
16171617
{
@@ -1761,7 +1761,7 @@ pgpipe(int handles[2])
17611761
}
17621762
if (getsockname(s, (SOCKADDR *) &serv_addr, &len) == SOCKET_ERROR)
17631763
{
1764-
pg_log_error("pgpipe: getsockname() failed: error code %d",
1764+
pg_log_error("pgpipe: %s() failed: error code %d", "getsockname",
17651765
WSAGetLastError());
17661766
closesocket(s);
17671767
return -1;

src/bin/pg_upgrade/parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ reap_child(bool wait_for_child)
297297
#ifndef WIN32
298298
child = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
299299
if (child == (pid_t) -1)
300-
pg_fatal("waitpid() failed: %s\n", strerror(errno));
300+
pg_fatal("%s() failed: %s\n", "waitpid", strerror(errno));
301301
if (child == 0)
302302
return false; /* no children, or no dead children */
303303
if (work_status != 0)

src/common/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pclose_check(FILE *stream)
406406
{
407407
/* pclose() itself failed, and hopefully set errno */
408408
log_error(errcode(ERRCODE_SYSTEM_ERROR),
409-
_("pclose failed: %m"));
409+
_("%s() failed: %m"), "pclose");
410410
}
411411
else
412412
{

src/interfaces/libpq/fe-connect.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,8 @@ setKeepalivesIdle(PGconn *conn)
18631863
char sebuf[PG_STRERROR_R_BUFLEN];
18641864

18651865
appendPQExpBuffer(&conn->errorMessage,
1866-
libpq_gettext("setsockopt(%s) failed: %s\n"),
1866+
libpq_gettext("%s(%s) failed: %s\n"),
1867+
"setsockopt",
18671868
PG_TCP_KEEPALIVE_IDLE_STR,
18681869
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
18691870
return 0;
@@ -1897,7 +1898,8 @@ setKeepalivesInterval(PGconn *conn)
18971898
char sebuf[PG_STRERROR_R_BUFLEN];
18981899

18991900
appendPQExpBuffer(&conn->errorMessage,
1900-
libpq_gettext("setsockopt(%s) failed: %s\n"),
1901+
libpq_gettext("%s(%s) failed: %s\n"),
1902+
"setsockopt",
19011903
"TCP_KEEPINTVL",
19021904
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
19031905
return 0;
@@ -1932,7 +1934,8 @@ setKeepalivesCount(PGconn *conn)
19321934
char sebuf[PG_STRERROR_R_BUFLEN];
19331935

19341936
appendPQExpBuffer(&conn->errorMessage,
1935-
libpq_gettext("setsockopt(%s) failed: %s\n"),
1937+
libpq_gettext("%s(%s) failed: %s\n"),
1938+
"setsockopt",
19361939
"TCP_KEEPCNT",
19371940
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
19381941
return 0;
@@ -2019,7 +2022,8 @@ setTCPUserTimeout(PGconn *conn)
20192022
char sebuf[256];
20202023

20212024
appendPQExpBuffer(&conn->errorMessage,
2022-
libpq_gettext("setsockopt(%s) failed: %s\n"),
2025+
libpq_gettext("%s(%s) failed: %s\n"),
2026+
"setsockopt",
20232027
"TCP_USER_TIMEOUT",
20242028
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
20252029
return 0;
@@ -2632,7 +2636,8 @@ PQconnectPoll(PGconn *conn)
26322636
(char *) &on, sizeof(on)) < 0)
26332637
{
26342638
appendPQExpBuffer(&conn->errorMessage,
2635-
libpq_gettext("setsockopt(%s) failed: %s\n"),
2639+
libpq_gettext("%s(%s) failed: %s\n"),
2640+
"setsockopt",
26362641
"SO_KEEPALIVE",
26372642
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
26382643
err = 1;

src/interfaces/libpq/fe-misc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,8 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
10801080
char sebuf[PG_STRERROR_R_BUFLEN];
10811081

10821082
appendPQExpBuffer(&conn->errorMessage,
1083-
libpq_gettext("select() failed: %s\n"),
1083+
libpq_gettext("%s() failed: %s\n"),
1084+
"select",
10841085
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
10851086
}
10861087

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy