mirror of
https://github.com/postgres/postgres.git
synced 2025-04-20 00:42:27 +03:00
Use clearer notation for getnameinfo() return handling
Writing if (getnameinfo(...)) handle_error(); reads quite strangely, so use something like if (getnameinfo(...) != 0) handle_error(); instead.
This commit is contained in:
parent
77949a2913
commit
f4a9da0a15
@ -569,7 +569,7 @@ check_hostname(hbaPort *port, const char *hostname)
|
|||||||
if (pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
if (pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||||
remote_hostname, sizeof(remote_hostname),
|
remote_hostname, sizeof(remote_hostname),
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
0))
|
0) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
port->remote_hostname = pstrdup(remote_hostname);
|
port->remote_hostname = pstrdup(remote_hostname);
|
||||||
|
@ -3357,14 +3357,14 @@ BackendInitialize(Port *port)
|
|||||||
if (pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
if (pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||||
remote_host, sizeof(remote_host),
|
remote_host, sizeof(remote_host),
|
||||||
remote_port, sizeof(remote_port),
|
remote_port, sizeof(remote_port),
|
||||||
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV))
|
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV) != 0)
|
||||||
{
|
{
|
||||||
int ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
int ret = pg_getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||||
remote_host, sizeof(remote_host),
|
remote_host, sizeof(remote_host),
|
||||||
remote_port, sizeof(remote_port),
|
remote_port, sizeof(remote_port),
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
|
|
||||||
if (ret)
|
if (ret != 0)
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errmsg_internal("pg_getnameinfo_all() failed: %s",
|
(errmsg_internal("pg_getnameinfo_all() failed: %s",
|
||||||
gai_strerror(ret))));
|
gai_strerror(ret))));
|
||||||
|
@ -1093,7 +1093,7 @@ inet_client_addr(PG_FUNCTION_ARGS)
|
|||||||
remote_host, sizeof(remote_host),
|
remote_host, sizeof(remote_host),
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
if (ret)
|
if (ret != 0)
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
|
|
||||||
clean_ipv6_addr(port->raddr.addr.ss_family, remote_host);
|
clean_ipv6_addr(port->raddr.addr.ss_family, remote_host);
|
||||||
@ -1132,7 +1132,7 @@ inet_client_port(PG_FUNCTION_ARGS)
|
|||||||
NULL, 0,
|
NULL, 0,
|
||||||
remote_port, sizeof(remote_port),
|
remote_port, sizeof(remote_port),
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
if (ret)
|
if (ret != 0)
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
|
|
||||||
PG_RETURN_DATUM(DirectFunctionCall1(int4in, CStringGetDatum(remote_port)));
|
PG_RETURN_DATUM(DirectFunctionCall1(int4in, CStringGetDatum(remote_port)));
|
||||||
@ -1169,7 +1169,7 @@ inet_server_addr(PG_FUNCTION_ARGS)
|
|||||||
local_host, sizeof(local_host),
|
local_host, sizeof(local_host),
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
if (ret)
|
if (ret != 0)
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
|
|
||||||
clean_ipv6_addr(port->laddr.addr.ss_family, local_host);
|
clean_ipv6_addr(port->laddr.addr.ss_family, local_host);
|
||||||
@ -1208,7 +1208,7 @@ inet_server_port(PG_FUNCTION_ARGS)
|
|||||||
NULL, 0,
|
NULL, 0,
|
||||||
local_port, sizeof(local_port),
|
local_port, sizeof(local_port),
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
if (ret)
|
if (ret != 0)
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
|
|
||||||
PG_RETURN_DATUM(DirectFunctionCall1(int4in, CStringGetDatum(local_port)));
|
PG_RETURN_DATUM(DirectFunctionCall1(int4in, CStringGetDatum(local_port)));
|
||||||
|
@ -682,13 +682,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
|||||||
remote_host, sizeof(remote_host),
|
remote_host, sizeof(remote_host),
|
||||||
remote_port, sizeof(remote_port),
|
remote_port, sizeof(remote_port),
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
if (ret)
|
if (ret == 0)
|
||||||
{
|
|
||||||
nulls[9] = true;
|
|
||||||
nulls[10] = true;
|
|
||||||
nulls[11] = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
|
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
|
||||||
values[9] = DirectFunctionCall1(inet_in,
|
values[9] = DirectFunctionCall1(inet_in,
|
||||||
@ -699,6 +693,12 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
|||||||
nulls[10] = true;
|
nulls[10] = true;
|
||||||
values[11] = Int32GetDatum(atoi(remote_port));
|
values[11] = Int32GetDatum(atoi(remote_port));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nulls[9] = true;
|
||||||
|
nulls[10] = true;
|
||||||
|
nulls[11] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
|
else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
|
||||||
{
|
{
|
||||||
@ -939,7 +939,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
|
|||||||
remote_host, sizeof(remote_host),
|
remote_host, sizeof(remote_host),
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
if (ret)
|
if (ret != 0)
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
|
|
||||||
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
|
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
|
||||||
@ -988,7 +988,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
|
|||||||
NULL, 0,
|
NULL, 0,
|
||||||
remote_port, sizeof(remote_port),
|
remote_port, sizeof(remote_port),
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||||
if (ret)
|
if (ret != 0)
|
||||||
PG_RETURN_NULL();
|
PG_RETURN_NULL();
|
||||||
|
|
||||||
PG_RETURN_DATUM(DirectFunctionCall1(int4in,
|
PG_RETURN_DATUM(DirectFunctionCall1(int4in,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user