mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
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
This commit is contained in:
parent
9486844f30
commit
82c3cd9741
@ -485,8 +485,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
/* translator: first %s is IPv4, IPv6, or Unix */
|
||||
errmsg("setsockopt(SO_REUSEADDR) failed for %s address \"%s\": %m",
|
||||
/* translator: third %s is IPv4, IPv6, or Unix */
|
||||
errmsg("%s(%s) failed for %s address \"%s\": %m",
|
||||
"setsockopt", "SO_REUSEADDR",
|
||||
familyDesc, addrDesc)));
|
||||
closesocket(fd);
|
||||
continue;
|
||||
@ -502,8 +503,9 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
/* translator: first %s is IPv4, IPv6, or Unix */
|
||||
errmsg("setsockopt(IPV6_V6ONLY) failed for %s address \"%s\": %m",
|
||||
/* translator: third %s is IPv4, IPv6, or Unix */
|
||||
errmsg("%s(%s) failed for %s address \"%s\": %m",
|
||||
"setsockopt", "IPV6_V6ONLY",
|
||||
familyDesc, addrDesc)));
|
||||
closesocket(fd);
|
||||
continue;
|
||||
@ -741,7 +743,7 @@ StreamConnection(pgsocket server_fd, Port *port)
|
||||
&port->laddr.salen) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("getsockname() failed: %m")));
|
||||
(errmsg("%s() failed: %m", "getsockname")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@ -761,7 +763,7 @@ StreamConnection(pgsocket server_fd, Port *port)
|
||||
(char *) &on, sizeof(on)) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) failed: %m", "TCP_NODELAY")));
|
||||
(errmsg("%s(%s) failed: %m", "setsockopt", "TCP_NODELAY")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
#endif
|
||||
@ -770,7 +772,7 @@ StreamConnection(pgsocket server_fd, Port *port)
|
||||
(char *) &on, sizeof(on)) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) failed: %m", "SO_KEEPALIVE")));
|
||||
(errmsg("%s(%s) failed: %m", "setsockopt", "SO_KEEPALIVE")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@ -802,7 +804,7 @@ StreamConnection(pgsocket server_fd, Port *port)
|
||||
&optlen) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("getsockopt(%s) failed: %m", "SO_SNDBUF")));
|
||||
(errmsg("%s(%s) failed: %m", "getsockopt", "SO_SNDBUF")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
newopt = PQ_SEND_BUFFER_SIZE * 4;
|
||||
@ -812,7 +814,7 @@ StreamConnection(pgsocket server_fd, Port *port)
|
||||
sizeof(newopt)) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) failed: %m", "SO_SNDBUF")));
|
||||
(errmsg("%s(%s) failed: %m", "setsockopt", "SO_SNDBUF")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
@ -1594,8 +1596,8 @@ pq_setkeepaliveswin32(Port *port, int idle, int interval)
|
||||
!= 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("WSAIoctl(%s) failed: %d",
|
||||
"SIO_KEEPALIVE_VALS", WSAGetLastError())));
|
||||
(errmsg("%s(%s) failed: error code %d",
|
||||
"WSAIoctl", "SIO_KEEPALIVE_VALS", WSAGetLastError())));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if (port->keepalives_idle != idle)
|
||||
@ -1626,7 +1628,7 @@ pq_getkeepalivesidle(Port *port)
|
||||
&size) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("getsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR)));
|
||||
(errmsg("%s(%s) failed: %m", "getsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
|
||||
port->default_keepalives_idle = -1; /* don't know */
|
||||
}
|
||||
#else /* WIN32 */
|
||||
@ -1671,7 +1673,7 @@ pq_setkeepalivesidle(int idle, Port *port)
|
||||
(char *) &idle, sizeof(idle)) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) failed: %m", PG_TCP_KEEPALIVE_IDLE_STR)));
|
||||
(errmsg("%s(%s) failed: %m", "setsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@ -1711,7 +1713,7 @@ pq_getkeepalivesinterval(Port *port)
|
||||
&size) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("getsockopt(%s) failed: %m", "TCP_KEEPINTVL")));
|
||||
(errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPINTVL")));
|
||||
port->default_keepalives_interval = -1; /* don't know */
|
||||
}
|
||||
#else
|
||||
@ -1755,7 +1757,7 @@ pq_setkeepalivesinterval(int interval, Port *port)
|
||||
(char *) &interval, sizeof(interval)) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) failed: %m", "TCP_KEEPINTVL")));
|
||||
(errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPINTVL")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@ -1767,7 +1769,7 @@ pq_setkeepalivesinterval(int interval, Port *port)
|
||||
if (interval != 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) not supported", "TCP_KEEPINTVL")));
|
||||
(errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPINTVL")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
#endif
|
||||
@ -1794,7 +1796,7 @@ pq_getkeepalivescount(Port *port)
|
||||
&size) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("getsockopt(%s) failed: %m", "TCP_KEEPCNT")));
|
||||
(errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPCNT")));
|
||||
port->default_keepalives_count = -1; /* don't know */
|
||||
}
|
||||
}
|
||||
@ -1833,7 +1835,7 @@ pq_setkeepalivescount(int count, Port *port)
|
||||
(char *) &count, sizeof(count)) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) failed: %m", "TCP_KEEPCNT")));
|
||||
(errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPCNT")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@ -1842,7 +1844,7 @@ pq_setkeepalivescount(int count, Port *port)
|
||||
if (count != 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) not supported", "TCP_KEEPCNT")));
|
||||
(errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPCNT")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
#endif
|
||||
@ -1869,7 +1871,7 @@ pq_gettcpusertimeout(Port *port)
|
||||
&size) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("getsockopt(%s) failed: %m", "TCP_USER_TIMEOUT")));
|
||||
(errmsg("%s(%s) failed: %m", "getsockopt", "TCP_USER_TIMEOUT")));
|
||||
port->default_tcp_user_timeout = -1; /* don't know */
|
||||
}
|
||||
}
|
||||
@ -1908,7 +1910,7 @@ pq_settcpusertimeout(int timeout, Port *port)
|
||||
(char *) &timeout, sizeof(timeout)) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) failed: %m", "TCP_USER_TIMEOUT")));
|
||||
(errmsg("%s(%s) failed: %m", "setsockopt", "TCP_USER_TIMEOUT")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@ -1917,7 +1919,7 @@ pq_settcpusertimeout(int timeout, Port *port)
|
||||
if (timeout != 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) not supported", "TCP_USER_TIMEOUT")));
|
||||
(errmsg("%s(%s) not supported", "setsockopt", "TCP_USER_TIMEOUT")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
@ -618,7 +618,7 @@ retry2:
|
||||
(char *) &old_rcvbuf, &rcvbufsize) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("getsockopt(%s) failed: %m", "SO_RCVBUF")));
|
||||
(errmsg("%s(%s) failed: %m", "getsockopt", "SO_RCVBUF")));
|
||||
/* if we can't get existing size, always try to set it */
|
||||
old_rcvbuf = 0;
|
||||
}
|
||||
@ -629,7 +629,7 @@ retry2:
|
||||
if (setsockopt(pgStatSock, SOL_SOCKET, SO_RCVBUF,
|
||||
(char *) &new_rcvbuf, sizeof(new_rcvbuf)) < 0)
|
||||
ereport(LOG,
|
||||
(errmsg("setsockopt(%s) failed: %m", "SO_RCVBUF")));
|
||||
(errmsg("%s(%s) failed: %m", "setsockopt", "SO_RCVBUF")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1061,9 +1061,8 @@ WaitEventAdjustEpoll(WaitEventSet *set, WaitEvent *event, int action)
|
||||
if (rc < 0)
|
||||
ereport(ERROR,
|
||||
(errcode_for_socket_access(),
|
||||
/* translator: %s is a syscall name, such as "poll()" */
|
||||
errmsg("%s failed: %m",
|
||||
"epoll_ctl()")));
|
||||
errmsg("%s() failed: %m",
|
||||
"epoll_ctl")));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1231,9 +1230,8 @@ WaitEventAdjustKqueue(WaitEventSet *set, WaitEvent *event, int old_events)
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode_for_socket_access(),
|
||||
/* translator: %s is a syscall name, such as "poll()" */
|
||||
errmsg("%s failed: %m",
|
||||
"kevent()")));
|
||||
errmsg("%s() failed: %m",
|
||||
"kevent")));
|
||||
}
|
||||
else if (event->events == WL_POSTMASTER_DEATH &&
|
||||
PostmasterPid != getppid() &&
|
||||
@ -1461,9 +1459,8 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
|
||||
waiting = false;
|
||||
ereport(ERROR,
|
||||
(errcode_for_socket_access(),
|
||||
/* translator: %s is a syscall name, such as "poll()" */
|
||||
errmsg("%s failed: %m",
|
||||
"epoll_wait()")));
|
||||
errmsg("%s() failed: %m",
|
||||
"epoll_wait")));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1614,9 +1611,8 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
|
||||
waiting = false;
|
||||
ereport(ERROR,
|
||||
(errcode_for_socket_access(),
|
||||
/* translator: %s is a syscall name, such as "poll()" */
|
||||
errmsg("%s failed: %m",
|
||||
"kevent()")));
|
||||
errmsg("%s() failed: %m",
|
||||
"kevent")));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1731,9 +1727,8 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
|
||||
waiting = false;
|
||||
ereport(ERROR,
|
||||
(errcode_for_socket_access(),
|
||||
/* translator: %s is a syscall name, such as "poll()" */
|
||||
errmsg("%s failed: %m",
|
||||
"poll()")));
|
||||
errmsg("%s() failed: %m",
|
||||
"poll")));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ StreamLogicalLog(void)
|
||||
}
|
||||
else if (r < 0)
|
||||
{
|
||||
pg_log_error("select() failed: %m");
|
||||
pg_log_error("%s() failed: %m", "select");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -897,7 +897,7 @@ CopyStreamPoll(PGconn *conn, long timeout_ms, pgsocket stop_socket)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
return 0; /* Got a signal, so not an error */
|
||||
pg_log_error("select() failed: %m");
|
||||
pg_log_error("%s() failed: %m", "select");
|
||||
return -1;
|
||||
}
|
||||
if (ret > 0 && FD_ISSET(connsocket, &input_mask))
|
||||
|
@ -251,7 +251,7 @@ init_parallel_dump_utils(void)
|
||||
err = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (err != 0)
|
||||
{
|
||||
pg_log_error("WSAStartup failed: %d", err);
|
||||
pg_log_error("%s() failed: error code %d", "WSAStartup", err);
|
||||
exit_nicely(1);
|
||||
}
|
||||
|
||||
@ -1611,7 +1611,7 @@ getMessageFromWorker(ParallelState *pstate, bool do_wait, int *worker)
|
||||
}
|
||||
|
||||
if (i < 0)
|
||||
fatal("select() failed: %m");
|
||||
fatal("%s() failed: %m", "select");
|
||||
|
||||
for (i = 0; i < pstate->numWorkers; i++)
|
||||
{
|
||||
@ -1761,7 +1761,7 @@ pgpipe(int handles[2])
|
||||
}
|
||||
if (getsockname(s, (SOCKADDR *) &serv_addr, &len) == SOCKET_ERROR)
|
||||
{
|
||||
pg_log_error("pgpipe: getsockname() failed: error code %d",
|
||||
pg_log_error("pgpipe: %s() failed: error code %d", "getsockname",
|
||||
WSAGetLastError());
|
||||
closesocket(s);
|
||||
return -1;
|
||||
|
@ -297,7 +297,7 @@ reap_child(bool wait_for_child)
|
||||
#ifndef WIN32
|
||||
child = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
|
||||
if (child == (pid_t) -1)
|
||||
pg_fatal("waitpid() failed: %s\n", strerror(errno));
|
||||
pg_fatal("%s() failed: %s\n", "waitpid", strerror(errno));
|
||||
if (child == 0)
|
||||
return false; /* no children, or no dead children */
|
||||
if (work_status != 0)
|
||||
|
@ -406,7 +406,7 @@ pclose_check(FILE *stream)
|
||||
{
|
||||
/* pclose() itself failed, and hopefully set errno */
|
||||
log_error(errcode(ERRCODE_SYSTEM_ERROR),
|
||||
_("pclose failed: %m"));
|
||||
_("%s() failed: %m"), "pclose");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1863,7 +1863,8 @@ setKeepalivesIdle(PGconn *conn)
|
||||
char sebuf[PG_STRERROR_R_BUFLEN];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
libpq_gettext("%s(%s) failed: %s\n"),
|
||||
"setsockopt",
|
||||
PG_TCP_KEEPALIVE_IDLE_STR,
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
return 0;
|
||||
@ -1897,7 +1898,8 @@ setKeepalivesInterval(PGconn *conn)
|
||||
char sebuf[PG_STRERROR_R_BUFLEN];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
libpq_gettext("%s(%s) failed: %s\n"),
|
||||
"setsockopt",
|
||||
"TCP_KEEPINTVL",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
return 0;
|
||||
@ -1932,7 +1934,8 @@ setKeepalivesCount(PGconn *conn)
|
||||
char sebuf[PG_STRERROR_R_BUFLEN];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
libpq_gettext("%s(%s) failed: %s\n"),
|
||||
"setsockopt",
|
||||
"TCP_KEEPCNT",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
return 0;
|
||||
@ -2019,7 +2022,8 @@ setTCPUserTimeout(PGconn *conn)
|
||||
char sebuf[256];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
libpq_gettext("%s(%s) failed: %s\n"),
|
||||
"setsockopt",
|
||||
"TCP_USER_TIMEOUT",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
return 0;
|
||||
@ -2632,7 +2636,8 @@ keep_going: /* We will come back to here until there is
|
||||
(char *) &on, sizeof(on)) < 0)
|
||||
{
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
libpq_gettext("%s(%s) failed: %s\n"),
|
||||
"setsockopt",
|
||||
"SO_KEEPALIVE",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
err = 1;
|
||||
|
@ -1080,7 +1080,8 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
|
||||
char sebuf[PG_STRERROR_R_BUFLEN];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("select() failed: %s\n"),
|
||||
libpq_gettext("%s() failed: %s\n"),
|
||||
"select",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user