PostgreSQL Source Code  git master
pqcomm.c File Reference
#include "postgres.h"
#include <poll.h>
#include <signal.h>
#include <fcntl.h>
#include <grp.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <utime.h>
#include "common/ip.h"
#include "libpq/libpq.h"
#include "miscadmin.h"
#include "port/pg_bswap.h"
#include "storage/ipc.h"
#include "utils/guc_hooks.h"
#include "utils/memutils.h"
Include dependency graph for pqcomm.c:

Go to the source code of this file.

Macros

#define PQ_SEND_BUFFER_SIZE   8192
 
#define PQ_RECV_BUFFER_SIZE   8192
 

Functions

static void socket_comm_reset (void)
 
static void socket_close (int code, Datum arg)
 
static void socket_set_nonblocking (bool nonblocking)
 
static int socket_flush (void)
 
static int socket_flush_if_writable (void)
 
static bool socket_is_send_pending (void)
 
static int socket_putmessage (char msgtype, const char *s, size_t len)
 
static void socket_putmessage_noblock (char msgtype, const char *s, size_t len)
 
static int internal_putbytes (const char *s, size_t len)
 
static int internal_flush (void)
 
static int Lock_AF_UNIX (const char *unixSocketDir, const char *unixSocketPath)
 
static int Setup_AF_UNIX (const char *sock_path)
 
void pq_init (void)
 
int StreamServerPort (int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSocket[], int MaxListen)
 
int StreamConnection (pgsocket server_fd, Port *port)
 
void StreamClose (pgsocket sock)
 
void TouchSocketFiles (void)
 
void RemoveSocketFiles (void)
 
static int pq_recvbuf (void)
 
int pq_getbyte (void)
 
int pq_peekbyte (void)
 
int pq_getbyte_if_available (unsigned char *c)
 
int pq_getbytes (char *s, size_t len)
 
static int pq_discardbytes (size_t len)
 
bool pq_buffer_has_data (void)
 
void pq_startmsgread (void)
 
void pq_endmsgread (void)
 
bool pq_is_reading_msg (void)
 
int pq_getmessage (StringInfo s, int maxlen)
 
int pq_putmessage_v2 (char msgtype, const char *s, size_t len)
 
int pq_getkeepalivesidle (Port *port)
 
int pq_setkeepalivesidle (int idle, Port *port)
 
int pq_getkeepalivesinterval (Port *port)
 
int pq_setkeepalivesinterval (int interval, Port *port)
 
int pq_getkeepalivescount (Port *port)
 
int pq_setkeepalivescount (int count, Port *port)
 
int pq_gettcpusertimeout (Port *port)
 
int pq_settcpusertimeout (int timeout, Port *port)
 
void assign_tcp_keepalives_idle (int newval, void *extra)
 
const char * show_tcp_keepalives_idle (void)
 
void assign_tcp_keepalives_interval (int newval, void *extra)
 
const char * show_tcp_keepalives_interval (void)
 
void assign_tcp_keepalives_count (int newval, void *extra)
 
const char * show_tcp_keepalives_count (void)
 
void assign_tcp_user_timeout (int newval, void *extra)
 
const char * show_tcp_user_timeout (void)
 
bool pq_check_connection (void)
 

Variables

int Unix_socket_permissions
 
char * Unix_socket_group
 
static Listsock_paths = NIL
 
static char * PqSendBuffer
 
static int PqSendBufferSize
 
static int PqSendPointer
 
static int PqSendStart
 
static char PqRecvBuffer [PQ_RECV_BUFFER_SIZE]
 
static int PqRecvPointer
 
static int PqRecvLength
 
static bool PqCommBusy
 
static bool PqCommReadingMsg
 
static const PQcommMethods PqCommSocketMethods
 
const PQcommMethodsPqCommMethods = &PqCommSocketMethods
 
WaitEventSetFeBeWaitSet
 

Macro Definition Documentation

◆ PQ_RECV_BUFFER_SIZE

#define PQ_RECV_BUFFER_SIZE   8192

Definition at line 120 of file pqcomm.c.

◆ PQ_SEND_BUFFER_SIZE

#define PQ_SEND_BUFFER_SIZE   8192

Definition at line 119 of file pqcomm.c.

Function Documentation

◆ assign_tcp_keepalives_count()

void assign_tcp_keepalives_count ( int  newval,
void *  extra 
)

Definition at line 1983 of file pqcomm.c.

1984 {
1985  /* See comments in assign_tcp_keepalives_idle */
1987 }
struct Port * MyProcPort
Definition: globals.c:47
#define newval
int pq_setkeepalivescount(int count, Port *port)
Definition: pqcomm.c:1804

References MyProcPort, newval, and pq_setkeepalivescount().

◆ assign_tcp_keepalives_idle()

void assign_tcp_keepalives_idle ( int  newval,
void *  extra 
)

Definition at line 1927 of file pqcomm.c.

1928 {
1929  /*
1930  * The kernel API provides no way to test a value without setting it; and
1931  * once we set it we might fail to unset it. So there seems little point
1932  * in fully implementing the check-then-assign GUC API for these
1933  * variables. Instead we just do the assignment on demand.
1934  * pq_setkeepalivesidle reports any problems via ereport(LOG).
1935  *
1936  * This approach means that the GUC value might have little to do with the
1937  * actual kernel value, so we use a show_hook that retrieves the kernel
1938  * value rather than trusting GUC's copy.
1939  */
1941 }
int pq_setkeepalivesidle(int idle, Port *port)
Definition: pqcomm.c:1640

References MyProcPort, newval, and pq_setkeepalivesidle().

◆ assign_tcp_keepalives_interval()

void assign_tcp_keepalives_interval ( int  newval,
void *  extra 
)

Definition at line 1960 of file pqcomm.c.

1961 {
1962  /* See comments in assign_tcp_keepalives_idle */
1964 }
int pq_setkeepalivesinterval(int interval, Port *port)
Definition: pqcomm.c:1725

References MyProcPort, newval, and pq_setkeepalivesinterval().

◆ assign_tcp_user_timeout()

void assign_tcp_user_timeout ( int  newval,
void *  extra 
)

Definition at line 2006 of file pqcomm.c.

2007 {
2008  /* See comments in assign_tcp_keepalives_idle */
2010 }
int pq_settcpusertimeout(int timeout, Port *port)
Definition: pqcomm.c:1879

References MyProcPort, newval, and pq_settcpusertimeout().

◆ internal_flush()

static int internal_flush ( void  )
static

Definition at line 1335 of file pqcomm.c.

1336 {
1337  static int last_reported_send_errno = 0;
1338 
1339  char *bufptr = PqSendBuffer + PqSendStart;
1340  char *bufend = PqSendBuffer + PqSendPointer;
1341 
1342  while (bufptr < bufend)
1343  {
1344  int r;
1345 
1346  r = secure_write(MyProcPort, bufptr, bufend - bufptr);
1347 
1348  if (r <= 0)
1349  {
1350  if (errno == EINTR)
1351  continue; /* Ok if we were interrupted */
1352 
1353  /*
1354  * Ok if no data writable without blocking, and the socket is in
1355  * non-blocking mode.
1356  */
1357  if (errno == EAGAIN ||
1358  errno == EWOULDBLOCK)
1359  {
1360  return 0;
1361  }
1362 
1363  /*
1364  * Careful: an ereport() that tries to write to the client would
1365  * cause recursion to here, leading to stack overflow and core
1366  * dump! This message must go *only* to the postmaster log.
1367  *
1368  * If a client disconnects while we're in the midst of output, we
1369  * might write quite a bit of data before we get to a safe query
1370  * abort point. So, suppress duplicate log messages.
1371  */
1372  if (errno != last_reported_send_errno)
1373  {
1374  last_reported_send_errno = errno;
1377  errmsg("could not send data to client: %m")));
1378  }
1379 
1380  /*
1381  * We drop the buffered data anyway so that processing can
1382  * continue, even though we'll probably quit soon. We also set a
1383  * flag that'll cause the next CHECK_FOR_INTERRUPTS to terminate
1384  * the connection.
1385  */
1386  PqSendStart = PqSendPointer = 0;
1388  InterruptPending = 1;
1389  return EOF;
1390  }
1391 
1392  last_reported_send_errno = 0; /* reset after any successful send */
1393  bufptr += r;
1394  PqSendStart += r;
1395  }
1396 
1397  PqSendStart = PqSendPointer = 0;
1398  return 0;
1399 }
ssize_t secure_write(Port *port, void *ptr, size_t len)
Definition: be-secure.c:258
int errcode_for_socket_access(void)
Definition: elog.c:952
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define COMMERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:149
volatile sig_atomic_t InterruptPending
Definition: globals.c:30
volatile sig_atomic_t ClientConnectionLost
Definition: globals.c:34
static int PqSendStart
Definition: pqcomm.c:125
static int PqSendPointer
Definition: pqcomm.c:124
static char * PqSendBuffer
Definition: pqcomm.c:122
#define EINTR
Definition: win32_port.h:376
#define EWOULDBLOCK
Definition: win32_port.h:382
#define EAGAIN
Definition: win32_port.h:374

References ClientConnectionLost, COMMERROR, EAGAIN, EINTR, ereport, errcode_for_socket_access(), errmsg(), EWOULDBLOCK, InterruptPending, MyProcPort, PqSendBuffer, PqSendPointer, PqSendStart, and secure_write().

Referenced by internal_putbytes(), socket_flush(), and socket_flush_if_writable().

◆ internal_putbytes()

static int internal_putbytes ( const char *  s,
size_t  len 
)
static

Definition at line 1282 of file pqcomm.c.

1283 {
1284  size_t amount;
1285 
1286  while (len > 0)
1287  {
1288  /* If buffer is full, then flush it out */
1290  {
1291  socket_set_nonblocking(false);
1292  if (internal_flush())
1293  return EOF;
1294  }
1295  amount = PqSendBufferSize - PqSendPointer;
1296  if (amount > len)
1297  amount = len;
1298  memcpy(PqSendBuffer + PqSendPointer, s, amount);
1299  PqSendPointer += amount;
1300  s += amount;
1301  len -= amount;
1302  }
1303  return 0;
1304 }
const void size_t len
static int internal_flush(void)
Definition: pqcomm.c:1335
static void socket_set_nonblocking(bool nonblocking)
Definition: pqcomm.c:898
static int PqSendBufferSize
Definition: pqcomm.c:123

References internal_flush(), len, PqSendBuffer, PqSendBufferSize, PqSendPointer, and socket_set_nonblocking().

Referenced by pq_putmessage_v2(), and socket_putmessage().

◆ Lock_AF_UNIX()

static int Lock_AF_UNIX ( const char *  unixSocketDir,
const char *  unixSocketPath 
)
static

Definition at line 590 of file pqcomm.c.

591 {
592  /* no lock file for abstract sockets */
593  if (unixSocketPath[0] == '@')
594  return STATUS_OK;
595 
596  /*
597  * Grab an interlock file associated with the socket file.
598  *
599  * Note: there are two reasons for using a socket lock file, rather than
600  * trying to interlock directly on the socket itself. First, it's a lot
601  * more portable, and second, it lets us remove any pre-existing socket
602  * file without race conditions.
603  */
604  CreateSocketLockFile(unixSocketPath, true, unixSocketDir);
605 
606  /*
607  * Once we have the interlock, we can safely delete any pre-existing
608  * socket file to avoid failure at bind() time.
609  */
610  (void) unlink(unixSocketPath);
611 
612  /*
613  * Remember socket file pathnames for later maintenance.
614  */
615  sock_paths = lappend(sock_paths, pstrdup(unixSocketPath));
616 
617  return STATUS_OK;
618 }
#define STATUS_OK
Definition: c.h:1159
List * lappend(List *list, void *datum)
Definition: list.c:338
char * pstrdup(const char *in)
Definition: mcxt.c:1624
void CreateSocketLockFile(const char *socketfile, bool amPostmaster, const char *socketDir)
Definition: miscinit.c:1468
static List * sock_paths
Definition: pqcomm.c:110

References CreateSocketLockFile(), lappend(), pstrdup(), sock_paths, and STATUS_OK.

Referenced by StreamServerPort().

◆ pq_buffer_has_data()

bool pq_buffer_has_data ( void  )

Definition at line 1133 of file pqcomm.c.

1134 {
1135  return (PqRecvPointer < PqRecvLength);
1136 }
static int PqRecvLength
Definition: pqcomm.c:129
static int PqRecvPointer
Definition: pqcomm.c:128

References PqRecvLength, and PqRecvPointer.

Referenced by ProcessStartupPacket().

◆ pq_check_connection()

bool pq_check_connection ( void  )

Definition at line 2029 of file pqcomm.c.

2030 {
2031  WaitEvent events[FeBeWaitSetNEvents];
2032  int rc;
2033 
2034  /*
2035  * It's OK to modify the socket event filter without restoring, because
2036  * all FeBeWaitSet socket wait sites do the same.
2037  */
2039 
2040 retry:
2041  rc = WaitEventSetWait(FeBeWaitSet, 0, events, lengthof(events), 0);
2042  for (int i = 0; i < rc; ++i)
2043  {
2044  if (events[i].events & WL_SOCKET_CLOSED)
2045  return false;
2046  if (events[i].events & WL_LATCH_SET)
2047  {
2048  /*
2049  * A latch event might be preventing other events from being
2050  * reported. Reset it and poll again. No need to restore it
2051  * because no code should expect latches to survive across
2052  * CHECK_FOR_INTERRUPTS().
2053  */
2055  goto retry;
2056  }
2057  }
2058 
2059  return true;
2060 }
#define lengthof(array)
Definition: c.h:772
struct Latch * MyLatch
Definition: globals.c:58
int i
Definition: isn.c:73
void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch)
Definition: latch.c:1008
int WaitEventSetWait(WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
Definition: latch.c:1383
void ResetLatch(Latch *latch)
Definition: latch.c:699
#define WL_SOCKET_CLOSED
Definition: latch.h:137
#define WL_LATCH_SET
Definition: latch.h:125
#define FeBeWaitSetNEvents
Definition: libpq.h:65
#define FeBeWaitSetSocketPos
Definition: libpq.h:63
WaitEventSet * FeBeWaitSet
Definition: pqcomm.c:164

References FeBeWaitSet, FeBeWaitSetNEvents, FeBeWaitSetSocketPos, i, lengthof, ModifyWaitEvent(), MyLatch, ResetLatch(), WaitEventSetWait(), WL_LATCH_SET, and WL_SOCKET_CLOSED.

Referenced by ProcessInterrupts().

◆ pq_discardbytes()

static int pq_discardbytes ( size_t  len)
static

Definition at line 1104 of file pqcomm.c.

1105 {
1106  size_t amount;
1107 
1109 
1110  while (len > 0)
1111  {
1112  while (PqRecvPointer >= PqRecvLength)
1113  {
1114  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1115  return EOF; /* Failed to recv data */
1116  }
1117  amount = PqRecvLength - PqRecvPointer;
1118  if (amount > len)
1119  amount = len;
1120  PqRecvPointer += amount;
1121  len -= amount;
1122  }
1123  return 0;
1124 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static int pq_recvbuf(void)
Definition: pqcomm.c:915
static bool PqCommReadingMsg
Definition: pqcomm.c:135

References Assert(), len, pq_recvbuf(), PqCommReadingMsg, PqRecvLength, and PqRecvPointer.

Referenced by pq_getmessage().

◆ pq_endmsgread()

void pq_endmsgread ( void  )

Definition at line 1170 of file pqcomm.c.

1171 {
1173 
1174  PqCommReadingMsg = false;
1175 }

References Assert(), and PqCommReadingMsg.

Referenced by ProcessRepliesIfAny(), and ProcessStartupPacket().

◆ pq_getbyte()

int pq_getbyte ( void  )

Definition at line 976 of file pqcomm.c.

977 {
979 
980  while (PqRecvPointer >= PqRecvLength)
981  {
982  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
983  return EOF; /* Failed to recv data */
984  }
985  return (unsigned char) PqRecvBuffer[PqRecvPointer++];
986 }
static char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
Definition: pqcomm.c:127

References Assert(), pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.

Referenced by CheckSASLAuth(), CopyGetData(), recv_password_packet(), and SocketBackend().

◆ pq_getbyte_if_available()

int pq_getbyte_if_available ( unsigned char *  c)

Definition at line 1016 of file pqcomm.c.

1017 {
1018  int r;
1019 
1021 
1023  {
1025  return 1;
1026  }
1027 
1028  /* Put the socket into non-blocking mode */
1029  socket_set_nonblocking(true);
1030 
1031  r = secure_read(MyProcPort, c, 1);
1032  if (r < 0)
1033  {
1034  /*
1035  * Ok if no data available without blocking or interrupted (though
1036  * EINTR really shouldn't happen with a non-blocking socket). Report
1037  * other errors.
1038  */
1039  if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
1040  r = 0;
1041  else
1042  {
1043  /*
1044  * Careful: an ereport() that tries to write to the client would
1045  * cause recursion to here, leading to stack overflow and core
1046  * dump! This message must go *only* to the postmaster log.
1047  */
1050  errmsg("could not receive data from client: %m")));
1051  r = EOF;
1052  }
1053  }
1054  else if (r == 0)
1055  {
1056  /* EOF detected */
1057  r = EOF;
1058  }
1059 
1060  return r;
1061 }
ssize_t secure_read(Port *port, void *ptr, size_t len)
Definition: be-secure.c:145
char * c

References Assert(), COMMERROR, EAGAIN, EINTR, ereport, errcode_for_socket_access(), errmsg(), EWOULDBLOCK, MyProcPort, PqCommReadingMsg, PqRecvBuffer, PqRecvLength, PqRecvPointer, secure_read(), and socket_set_nonblocking().

Referenced by ProcessRepliesIfAny().

◆ pq_getbytes()

int pq_getbytes ( char *  s,
size_t  len 
)

Definition at line 1070 of file pqcomm.c.

1071 {
1072  size_t amount;
1073 
1075 
1076  while (len > 0)
1077  {
1078  while (PqRecvPointer >= PqRecvLength)
1079  {
1080  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1081  return EOF; /* Failed to recv data */
1082  }
1083  amount = PqRecvLength - PqRecvPointer;
1084  if (amount > len)
1085  amount = len;
1086  memcpy(s, PqRecvBuffer + PqRecvPointer, amount);
1087  PqRecvPointer += amount;
1088  s += amount;
1089  len -= amount;
1090  }
1091  return 0;
1092 }

References Assert(), len, pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.

Referenced by pq_getmessage(), and ProcessStartupPacket().

◆ pq_getkeepalivescount()

int pq_getkeepalivescount ( Port port)

Definition at line 1774 of file pqcomm.c.

1775 {
1776 #ifdef TCP_KEEPCNT
1777  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1778  return 0;
1779 
1780  if (port->keepalives_count != 0)
1781  return port->keepalives_count;
1782 
1783  if (port->default_keepalives_count == 0)
1784  {
1785  socklen_t size = sizeof(port->default_keepalives_count);
1786 
1787  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1788  (char *) &port->default_keepalives_count,
1789  &size) < 0)
1790  {
1791  ereport(LOG,
1792  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPCNT")));
1793  port->default_keepalives_count = -1; /* don't know */
1794  }
1795  }
1796 
1797  return port->default_keepalives_count;
1798 #else
1799  return 0;
1800 #endif
1801 }
#define LOG
Definition: elog.h:31
static int port
Definition: pg_regress.c:90
unsigned int socklen_t
Definition: port.h:40

References ereport, errmsg(), LOG, and port.

Referenced by pq_setkeepalivescount(), and show_tcp_keepalives_count().

◆ pq_getkeepalivesidle()

int pq_getkeepalivesidle ( Port port)

Definition at line 1605 of file pqcomm.c.

1606 {
1607 #if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1608  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1609  return 0;
1610 
1611  if (port->keepalives_idle != 0)
1612  return port->keepalives_idle;
1613 
1614  if (port->default_keepalives_idle == 0)
1615  {
1616 #ifndef WIN32
1617  socklen_t size = sizeof(port->default_keepalives_idle);
1618 
1619  if (getsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
1620  (char *) &port->default_keepalives_idle,
1621  &size) < 0)
1622  {
1623  ereport(LOG,
1624  (errmsg("%s(%s) failed: %m", "getsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
1625  port->default_keepalives_idle = -1; /* don't know */
1626  }
1627 #else /* WIN32 */
1628  /* We can't get the defaults on Windows, so return "don't know" */
1629  port->default_keepalives_idle = -1;
1630 #endif /* WIN32 */
1631  }
1632 
1633  return port->default_keepalives_idle;
1634 #else
1635  return 0;
1636 #endif
1637 }

References ereport, errmsg(), LOG, and port.

Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().

◆ pq_getkeepalivesinterval()

int pq_getkeepalivesinterval ( Port port)

Definition at line 1690 of file pqcomm.c.

1691 {
1692 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1693  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1694  return 0;
1695 
1696  if (port->keepalives_interval != 0)
1697  return port->keepalives_interval;
1698 
1699  if (port->default_keepalives_interval == 0)
1700  {
1701 #ifndef WIN32
1702  socklen_t size = sizeof(port->default_keepalives_interval);
1703 
1704  if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1705  (char *) &port->default_keepalives_interval,
1706  &size) < 0)
1707  {
1708  ereport(LOG,
1709  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_KEEPINTVL")));
1710  port->default_keepalives_interval = -1; /* don't know */
1711  }
1712 #else
1713  /* We can't get the defaults on Windows, so return "don't know" */
1714  port->default_keepalives_interval = -1;
1715 #endif /* WIN32 */
1716  }
1717 
1718  return port->default_keepalives_interval;
1719 #else
1720  return 0;
1721 #endif
1722 }

References ereport, errmsg(), LOG, and port.

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

◆ pq_getmessage()

int pq_getmessage ( StringInfo  s,
int  maxlen 
)

Definition at line 1208 of file pqcomm.c.

1209 {
1210  int32 len;
1211 
1213 
1214  resetStringInfo(s);
1215 
1216  /* Read message length word */
1217  if (pq_getbytes((char *) &len, 4) == EOF)
1218  {
1220  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1221  errmsg("unexpected EOF within message length word")));
1222  return EOF;
1223  }
1224 
1225  len = pg_ntoh32(len);
1226 
1227  if (len < 4 || len > maxlen)
1228  {
1230  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1231  errmsg("invalid message length")));
1232  return EOF;
1233  }
1234 
1235  len -= 4; /* discount length itself */
1236 
1237  if (len > 0)
1238  {
1239  /*
1240  * Allocate space for message. If we run out of room (ridiculously
1241  * large message), we will elog(ERROR), but we want to discard the
1242  * message body so as not to lose communication sync.
1243  */
1244  PG_TRY();
1245  {
1246  enlargeStringInfo(s, len);
1247  }
1248  PG_CATCH();
1249  {
1250  if (pq_discardbytes(len) == EOF)
1252  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1253  errmsg("incomplete message from client")));
1254 
1255  /* we discarded the rest of the message so we're back in sync. */
1256  PqCommReadingMsg = false;
1257  PG_RE_THROW();
1258  }
1259  PG_END_TRY();
1260 
1261  /* And grab the message */
1262  if (pq_getbytes(s->data, len) == EOF)
1263  {
1265  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1266  errmsg("incomplete message from client")));
1267  return EOF;
1268  }
1269  s->len = len;
1270  /* Place a trailing null per StringInfo convention */
1271  s->data[len] = '\0';
1272  }
1273 
1274  /* finished reading the message. */
1275  PqCommReadingMsg = false;
1276 
1277  return 0;
1278 }
signed int int32
Definition: c.h:478
int errcode(int sqlerrcode)
Definition: elog.c:858
#define PG_RE_THROW()
Definition: elog.h:411
#define PG_TRY(...)
Definition: elog.h:370
#define PG_END_TRY(...)
Definition: elog.h:395
#define PG_CATCH(...)
Definition: elog.h:380
#define pg_ntoh32(x)
Definition: pg_bswap.h:125
static int pq_discardbytes(size_t len)
Definition: pqcomm.c:1104
int pq_getbytes(char *s, size_t len)
Definition: pqcomm.c:1070
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:75
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:283

References Assert(), COMMERROR, StringInfoData::data, enlargeStringInfo(), ereport, errcode(), errmsg(), StringInfoData::len, len, PG_CATCH, PG_END_TRY, pg_ntoh32, PG_RE_THROW, PG_TRY, pq_discardbytes(), pq_getbytes(), PqCommReadingMsg, and resetStringInfo().

Referenced by CheckSASLAuth(), CopyGetData(), ProcessRepliesIfAny(), recv_password_packet(), and SocketBackend().

◆ pq_gettcpusertimeout()

int pq_gettcpusertimeout ( Port port)

Definition at line 1849 of file pqcomm.c.

1850 {
1851 #ifdef TCP_USER_TIMEOUT
1852  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1853  return 0;
1854 
1855  if (port->tcp_user_timeout != 0)
1856  return port->tcp_user_timeout;
1857 
1858  if (port->default_tcp_user_timeout == 0)
1859  {
1860  socklen_t size = sizeof(port->default_tcp_user_timeout);
1861 
1862  if (getsockopt(port->sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
1863  (char *) &port->default_tcp_user_timeout,
1864  &size) < 0)
1865  {
1866  ereport(LOG,
1867  (errmsg("%s(%s) failed: %m", "getsockopt", "TCP_USER_TIMEOUT")));
1868  port->default_tcp_user_timeout = -1; /* don't know */
1869  }
1870  }
1871 
1872  return port->default_tcp_user_timeout;
1873 #else
1874  return 0;
1875 #endif
1876 }

References ereport, errmsg(), LOG, and port.

Referenced by pq_settcpusertimeout(), and show_tcp_user_timeout().

◆ pq_init()

void pq_init ( void  )

Definition at line 172 of file pqcomm.c.

173 {
174  int socket_pos PG_USED_FOR_ASSERTS_ONLY;
175  int latch_pos PG_USED_FOR_ASSERTS_ONLY;
176 
177  /* initialize state variables */
181  PqCommBusy = false;
182  PqCommReadingMsg = false;
183 
184  /* set up process-exit hook to close the socket */
186 
187  /*
188  * In backends (as soon as forked) we operate the underlying socket in
189  * nonblocking mode and use latches to implement blocking semantics if
190  * needed. That allows us to provide safely interruptible reads and
191  * writes.
192  *
193  * Use COMMERROR on failure, because ERROR would try to send the error to
194  * the client, which might require changing the mode again, leading to
195  * infinite recursion.
196  */
197 #ifndef WIN32
200  (errmsg("could not set socket to nonblocking mode: %m")));
201 #endif
202 
203 #ifndef WIN32
204 
205  /* Don't give the socket to any subprograms we execute. */
206  if (fcntl(MyProcPort->sock, F_SETFD, FD_CLOEXEC) < 0)
207  elog(FATAL, "fcntl(F_SETFD) failed on socket: %m");
208 #endif
209 
212  MyProcPort->sock, NULL, NULL);
214  MyLatch, NULL);
216  NULL, NULL);
217 
218  /*
219  * The event positions match the order we added them, but let's sanity
220  * check them to be sure.
221  */
222  Assert(socket_pos == FeBeWaitSetSocketPos);
223  Assert(latch_pos == FeBeWaitSetLatchPos);
224 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:166
#define FATAL
Definition: elog.h:41
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:305
WaitEventSet * CreateWaitEventSet(MemoryContext context, int nevents)
Definition: latch.c:723
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data)
Definition: latch.c:922
#define WL_POSTMASTER_DEATH
Definition: latch.h:129
#define WL_SOCKET_WRITEABLE
Definition: latch.h:127
#define FeBeWaitSetLatchPos
Definition: libpq.h:64
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1005
bool pg_set_noblock(pgsocket sock)
Definition: noblock.c:25
#define PGINVALID_SOCKET
Definition: port.h:31
#define PQ_SEND_BUFFER_SIZE
Definition: pqcomm.c:119
static bool PqCommBusy
Definition: pqcomm.c:134
static void socket_close(int code, Datum arg)
Definition: pqcomm.c:250
pgsocket sock
Definition: libpq-be.h:147

References AddWaitEventToSet(), Assert(), COMMERROR, CreateWaitEventSet(), elog(), ereport, errmsg(), FATAL, FeBeWaitSet, FeBeWaitSetLatchPos, FeBeWaitSetNEvents, FeBeWaitSetSocketPos, MemoryContextAlloc(), MyLatch, MyProcPort, on_proc_exit(), pg_set_noblock(), PG_USED_FOR_ASSERTS_ONLY, PGINVALID_SOCKET, PQ_SEND_BUFFER_SIZE, PqCommBusy, PqCommReadingMsg, PqRecvLength, PqRecvPointer, PqSendBuffer, PqSendBufferSize, PqSendPointer, PqSendStart, Port::sock, socket_close(), TopMemoryContext, WL_LATCH_SET, WL_POSTMASTER_DEATH, and WL_SOCKET_WRITEABLE.

Referenced by BackendInitialize().

◆ pq_is_reading_msg()

bool pq_is_reading_msg ( void  )

Definition at line 1186 of file pqcomm.c.

1187 {
1188  return PqCommReadingMsg;
1189 }

References PqCommReadingMsg.

Referenced by PostgresMain().

◆ pq_peekbyte()

int pq_peekbyte ( void  )

Definition at line 995 of file pqcomm.c.

996 {
998 
999  while (PqRecvPointer >= PqRecvLength)
1000  {
1001  if (pq_recvbuf()) /* If nothing in buffer, then recv some */
1002  return EOF; /* Failed to recv data */
1003  }
1004  return (unsigned char) PqRecvBuffer[PqRecvPointer];
1005 }

References Assert(), pq_recvbuf(), PqCommReadingMsg, PqRecvBuffer, PqRecvLength, and PqRecvPointer.

◆ pq_putmessage_v2()

int pq_putmessage_v2 ( char  msgtype,
const char *  s,
size_t  len 
)

Definition at line 1534 of file pqcomm.c.

1535 {
1536  Assert(msgtype != 0);
1537 
1538  if (PqCommBusy)
1539  return 0;
1540  PqCommBusy = true;
1541  if (internal_putbytes(&msgtype, 1))
1542  goto fail;
1543 
1544  if (internal_putbytes(s, len))
1545  goto fail;
1546  PqCommBusy = false;
1547  return 0;
1548 
1549 fail:
1550  PqCommBusy = false;
1551  return EOF;
1552 }
static int internal_putbytes(const char *s, size_t len)
Definition: pqcomm.c:1282

References Assert(), internal_putbytes(), len, and PqCommBusy.

Referenced by send_message_to_frontend().

◆ pq_recvbuf()

static int pq_recvbuf ( void  )
static

Definition at line 915 of file pqcomm.c.

916 {
917  if (PqRecvPointer > 0)
918  {
920  {
921  /* still some unread data, left-justify it in the buffer */
925  PqRecvPointer = 0;
926  }
927  else
929  }
930 
931  /* Ensure that we're in blocking mode */
932  socket_set_nonblocking(false);
933 
934  /* Can fill buffer from PqRecvLength and upwards */
935  for (;;)
936  {
937  int r;
938 
941 
942  if (r < 0)
943  {
944  if (errno == EINTR)
945  continue; /* Ok if interrupted */
946 
947  /*
948  * Careful: an ereport() that tries to write to the client would
949  * cause recursion to here, leading to stack overflow and core
950  * dump! This message must go *only* to the postmaster log.
951  */
954  errmsg("could not receive data from client: %m")));
955  return EOF;
956  }
957  if (r == 0)
958  {
959  /*
960  * EOF detected. We used to write a log message here, but it's
961  * better to expect the ultimate caller to do that.
962  */
963  return EOF;
964  }
965  /* r contains number of bytes read, so just incr length */
966  PqRecvLength += r;
967  return 0;
968  }
969 }
#define PQ_RECV_BUFFER_SIZE
Definition: pqcomm.c:120

References COMMERROR, EINTR, ereport, errcode_for_socket_access(), errmsg(), MyProcPort, PQ_RECV_BUFFER_SIZE, PqRecvBuffer, PqRecvLength, PqRecvPointer, secure_read(), and socket_set_nonblocking().

Referenced by pq_discardbytes(), pq_getbyte(), pq_getbytes(), and pq_peekbyte().

◆ pq_setkeepalivescount()

int pq_setkeepalivescount ( int  count,
Port port 
)

Definition at line 1804 of file pqcomm.c.

1805 {
1806  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1807  return STATUS_OK;
1808 
1809 #ifdef TCP_KEEPCNT
1810  if (count == port->keepalives_count)
1811  return STATUS_OK;
1812 
1813  if (port->default_keepalives_count <= 0)
1814  {
1815  if (pq_getkeepalivescount(port) < 0)
1816  {
1817  if (count == 0)
1818  return STATUS_OK; /* default is set but unknown */
1819  else
1820  return STATUS_ERROR;
1821  }
1822  }
1823 
1824  if (count == 0)
1825  count = port->default_keepalives_count;
1826 
1827  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
1828  (char *) &count, sizeof(count)) < 0)
1829  {
1830  ereport(LOG,
1831  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPCNT")));
1832  return STATUS_ERROR;
1833  }
1834 
1835  port->keepalives_count = count;
1836 #else
1837  if (count != 0)
1838  {
1839  ereport(LOG,
1840  (errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPCNT")));
1841  return STATUS_ERROR;
1842  }
1843 #endif
1844 
1845  return STATUS_OK;
1846 }
#define STATUS_ERROR
Definition: c.h:1160
int pq_getkeepalivescount(Port *port)
Definition: pqcomm.c:1774

References ereport, errmsg(), LOG, port, pq_getkeepalivescount(), STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_count(), and StreamConnection().

◆ pq_setkeepalivesidle()

int pq_setkeepalivesidle ( int  idle,
Port port 
)

Definition at line 1640 of file pqcomm.c.

1641 {
1642  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1643  return STATUS_OK;
1644 
1645 /* check SIO_KEEPALIVE_VALS here, not just WIN32, as some toolchains lack it */
1646 #if defined(PG_TCP_KEEPALIVE_IDLE) || defined(SIO_KEEPALIVE_VALS)
1647  if (idle == port->keepalives_idle)
1648  return STATUS_OK;
1649 
1650 #ifndef WIN32
1651  if (port->default_keepalives_idle <= 0)
1652  {
1653  if (pq_getkeepalivesidle(port) < 0)
1654  {
1655  if (idle == 0)
1656  return STATUS_OK; /* default is set but unknown */
1657  else
1658  return STATUS_ERROR;
1659  }
1660  }
1661 
1662  if (idle == 0)
1663  idle = port->default_keepalives_idle;
1664 
1665  if (setsockopt(port->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
1666  (char *) &idle, sizeof(idle)) < 0)
1667  {
1668  ereport(LOG,
1669  (errmsg("%s(%s) failed: %m", "setsockopt", PG_TCP_KEEPALIVE_IDLE_STR)));
1670  return STATUS_ERROR;
1671  }
1672 
1673  port->keepalives_idle = idle;
1674 #else /* WIN32 */
1675  return pq_setkeepaliveswin32(port, idle, port->keepalives_interval);
1676 #endif
1677 #else
1678  if (idle != 0)
1679  {
1680  ereport(LOG,
1681  (errmsg("setting the keepalive idle time is not supported")));
1682  return STATUS_ERROR;
1683  }
1684 #endif
1685 
1686  return STATUS_OK;
1687 }
int pq_getkeepalivesidle(Port *port)
Definition: pqcomm.c:1605

References ereport, errmsg(), LOG, port, pq_getkeepalivesidle(), STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_idle(), and StreamConnection().

◆ pq_setkeepalivesinterval()

int pq_setkeepalivesinterval ( int  interval,
Port port 
)

Definition at line 1725 of file pqcomm.c.

1726 {
1727  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1728  return STATUS_OK;
1729 
1730 #if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
1731  if (interval == port->keepalives_interval)
1732  return STATUS_OK;
1733 
1734 #ifndef WIN32
1735  if (port->default_keepalives_interval <= 0)
1736  {
1737  if (pq_getkeepalivesinterval(port) < 0)
1738  {
1739  if (interval == 0)
1740  return STATUS_OK; /* default is set but unknown */
1741  else
1742  return STATUS_ERROR;
1743  }
1744  }
1745 
1746  if (interval == 0)
1747  interval = port->default_keepalives_interval;
1748 
1749  if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
1750  (char *) &interval, sizeof(interval)) < 0)
1751  {
1752  ereport(LOG,
1753  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_KEEPINTVL")));
1754  return STATUS_ERROR;
1755  }
1756 
1757  port->keepalives_interval = interval;
1758 #else /* WIN32 */
1759  return pq_setkeepaliveswin32(port, port->keepalives_idle, interval);
1760 #endif
1761 #else
1762  if (interval != 0)
1763  {
1764  ereport(LOG,
1765  (errmsg("%s(%s) not supported", "setsockopt", "TCP_KEEPINTVL")));
1766  return STATUS_ERROR;
1767  }
1768 #endif
1769 
1770  return STATUS_OK;
1771 }
int pq_getkeepalivesinterval(Port *port)
Definition: pqcomm.c:1690

References ereport, errmsg(), LOG, port, pq_getkeepalivesinterval(), STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_keepalives_interval(), and StreamConnection().

◆ pq_settcpusertimeout()

int pq_settcpusertimeout ( int  timeout,
Port port 
)

Definition at line 1879 of file pqcomm.c.

1880 {
1881  if (port == NULL || port->laddr.addr.ss_family == AF_UNIX)
1882  return STATUS_OK;
1883 
1884 #ifdef TCP_USER_TIMEOUT
1885  if (timeout == port->tcp_user_timeout)
1886  return STATUS_OK;
1887 
1888  if (port->default_tcp_user_timeout <= 0)
1889  {
1890  if (pq_gettcpusertimeout(port) < 0)
1891  {
1892  if (timeout == 0)
1893  return STATUS_OK; /* default is set but unknown */
1894  else
1895  return STATUS_ERROR;
1896  }
1897  }
1898 
1899  if (timeout == 0)
1900  timeout = port->default_tcp_user_timeout;
1901 
1902  if (setsockopt(port->sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
1903  (char *) &timeout, sizeof(timeout)) < 0)
1904  {
1905  ereport(LOG,
1906  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_USER_TIMEOUT")));
1907  return STATUS_ERROR;
1908  }
1909 
1910  port->tcp_user_timeout = timeout;
1911 #else
1912  if (timeout != 0)
1913  {
1914  ereport(LOG,
1915  (errmsg("%s(%s) not supported", "setsockopt", "TCP_USER_TIMEOUT")));
1916  return STATUS_ERROR;
1917  }
1918 #endif
1919 
1920  return STATUS_OK;
1921 }
int pq_gettcpusertimeout(Port *port)
Definition: pqcomm.c:1849

References ereport, errmsg(), LOG, port, pq_gettcpusertimeout(), STATUS_ERROR, and STATUS_OK.

Referenced by assign_tcp_user_timeout(), and StreamConnection().

◆ pq_startmsgread()

void pq_startmsgread ( void  )

Definition at line 1146 of file pqcomm.c.

1147 {
1148  /*
1149  * There shouldn't be a read active already, but let's check just to be
1150  * sure.
1151  */
1152  if (PqCommReadingMsg)
1153  ereport(FATAL,
1154  (errcode(ERRCODE_PROTOCOL_VIOLATION),
1155  errmsg("terminating connection because protocol synchronization was lost")));
1156 
1157  PqCommReadingMsg = true;
1158 }

References ereport, errcode(), errmsg(), FATAL, and PqCommReadingMsg.

Referenced by CheckSASLAuth(), CopyGetData(), ProcessRepliesIfAny(), ProcessStartupPacket(), recv_password_packet(), and SocketBackend().

◆ RemoveSocketFiles()

void RemoveSocketFiles ( void  )

Definition at line 865 of file pqcomm.c.

866 {
867  ListCell *l;
868 
869  /* Loop through all created sockets... */
870  foreach(l, sock_paths)
871  {
872  char *sock_path = (char *) lfirst(l);
873 
874  /* Ignore any error. */
875  (void) unlink(sock_path);
876  }
877  /* Since we're about to exit, no need to reclaim storage */
878  sock_paths = NIL;
879 }
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68

References lfirst, NIL, and sock_paths.

Referenced by CloseServerPorts().

◆ Setup_AF_UNIX()

static int Setup_AF_UNIX ( const char *  sock_path)
static

Definition at line 625 of file pqcomm.c.

626 {
627  /* no file system permissions for abstract sockets */
628  if (sock_path[0] == '@')
629  return STATUS_OK;
630 
631  /*
632  * Fix socket ownership/permission if requested. Note we must do this
633  * before we listen() to avoid a window where unwanted connections could
634  * get accepted.
635  */
637  if (Unix_socket_group[0] != '\0')
638  {
639 #ifdef WIN32
640  elog(WARNING, "configuration item unix_socket_group is not supported on this platform");
641 #else
642  char *endptr;
643  unsigned long val;
644  gid_t gid;
645 
646  val = strtoul(Unix_socket_group, &endptr, 10);
647  if (*endptr == '\0')
648  { /* numeric group id */
649  gid = val;
650  }
651  else
652  { /* convert group name to id */
653  struct group *gr;
654 
655  gr = getgrnam(Unix_socket_group);
656  if (!gr)
657  {
658  ereport(LOG,
659  (errmsg("group \"%s\" does not exist",
661  return STATUS_ERROR;
662  }
663  gid = gr->gr_gid;
664  }
665  if (chown(sock_path, -1, gid) == -1)
666  {
667  ereport(LOG,
669  errmsg("could not set group of file \"%s\": %m",
670  sock_path)));
671  return STATUS_ERROR;
672  }
673 #endif
674  }
675 
676  if (chmod(sock_path, Unix_socket_permissions) == -1)
677  {
678  ereport(LOG,
680  errmsg("could not set permissions of file \"%s\": %m",
681  sock_path)));
682  return STATUS_ERROR;
683  }
684  return STATUS_OK;
685 }
int errcode_for_file_access(void)
Definition: elog.c:881
#define WARNING
Definition: elog.h:36
long val
Definition: informix.c:664
int Unix_socket_permissions
Definition: pqcomm.c:106
char * Unix_socket_group
Definition: pqcomm.c:107
int gid_t
Definition: win32_port.h:247

References Assert(), elog(), ereport, errcode_for_file_access(), errmsg(), LOG, STATUS_ERROR, STATUS_OK, Unix_socket_group, Unix_socket_permissions, val, and WARNING.

Referenced by StreamServerPort().

◆ show_tcp_keepalives_count()

const char* show_tcp_keepalives_count ( void  )

Definition at line 1993 of file pqcomm.c.

1994 {
1995  /* See comments in assign_tcp_keepalives_idle */
1996  static char nbuf[16];
1997 
1998  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
1999  return nbuf;
2000 }
#define snprintf
Definition: port.h:238

References MyProcPort, pq_getkeepalivescount(), and snprintf.

◆ show_tcp_keepalives_idle()

const char* show_tcp_keepalives_idle ( void  )

Definition at line 1947 of file pqcomm.c.

1948 {
1949  /* See comments in assign_tcp_keepalives_idle */
1950  static char nbuf[16];
1951 
1952  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
1953  return nbuf;
1954 }

References MyProcPort, pq_getkeepalivesidle(), and snprintf.

◆ show_tcp_keepalives_interval()

const char* show_tcp_keepalives_interval ( void  )

Definition at line 1970 of file pqcomm.c.

1971 {
1972  /* See comments in assign_tcp_keepalives_idle */
1973  static char nbuf[16];
1974 
1975  snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
1976  return nbuf;
1977 }

References MyProcPort, pq_getkeepalivesinterval(), and snprintf.

◆ show_tcp_user_timeout()

const char* show_tcp_user_timeout ( void  )

Definition at line 2016 of file pqcomm.c.

2017 {
2018  /* See comments in assign_tcp_keepalives_idle */
2019  static char nbuf[16];
2020 
2021  snprintf(nbuf, sizeof(nbuf), "%d", pq_gettcpusertimeout(MyProcPort));
2022  return nbuf;
2023 }

References MyProcPort, pq_gettcpusertimeout(), and snprintf.

◆ socket_close()

static void socket_close ( int  code,
Datum  arg 
)
static

Definition at line 250 of file pqcomm.c.

251 {
252  /* Nothing to do in a standalone backend, where MyProcPort is NULL. */
253  if (MyProcPort != NULL)
254  {
255 #ifdef ENABLE_GSS
256  /*
257  * Shutdown GSSAPI layer. This section does nothing when interrupting
258  * BackendInitialize(), because pg_GSS_recvauth() makes first use of
259  * "ctx" and "cred".
260  *
261  * Note that we don't bother to free MyProcPort->gss, since we're
262  * about to exit anyway.
263  */
264  if (MyProcPort->gss)
265  {
266  OM_uint32 min_s;
267 
268  if (MyProcPort->gss->ctx != GSS_C_NO_CONTEXT)
269  gss_delete_sec_context(&min_s, &MyProcPort->gss->ctx, NULL);
270 
271  if (MyProcPort->gss->cred != GSS_C_NO_CREDENTIAL)
272  gss_release_cred(&min_s, &MyProcPort->gss->cred);
273  }
274 #endif /* ENABLE_GSS */
275 
276  /*
277  * Cleanly shut down SSL layer. Nowhere else does a postmaster child
278  * call this, so this is safe when interrupting BackendInitialize().
279  */
281 
282  /*
283  * Formerly we did an explicit close() here, but it seems better to
284  * leave the socket open until the process dies. This allows clients
285  * to perform a "synchronous close" if they care --- wait till the
286  * transport layer reports connection closure, and you can be sure the
287  * backend has exited.
288  *
289  * We do set sock to PGINVALID_SOCKET to prevent any further I/O,
290  * though.
291  */
293  }
294 }
void secure_close(Port *port)
Definition: be-secure.c:133
void * gss
Definition: libpq-be.h:210

References Port::gss, MyProcPort, PGINVALID_SOCKET, secure_close(), and Port::sock.

Referenced by pq_init().

◆ socket_comm_reset()

static void socket_comm_reset ( void  )
static

Definition at line 235 of file pqcomm.c.

236 {
237  /* Do not throw away pending data, but do reset the busy flag */
238  PqCommBusy = false;
239 }

References PqCommBusy.

◆ socket_flush()

static int socket_flush ( void  )
static

Definition at line 1313 of file pqcomm.c.

1314 {
1315  int res;
1316 
1317  /* No-op if reentrant call */
1318  if (PqCommBusy)
1319  return 0;
1320  PqCommBusy = true;
1321  socket_set_nonblocking(false);
1322  res = internal_flush();
1323  PqCommBusy = false;
1324  return res;
1325 }

References internal_flush(), PqCommBusy, res, and socket_set_nonblocking().

◆ socket_flush_if_writable()

static int socket_flush_if_writable ( void  )
static

Definition at line 1408 of file pqcomm.c.

1409 {
1410  int res;
1411 
1412  /* Quick exit if nothing to do */
1413  if (PqSendPointer == PqSendStart)
1414  return 0;
1415 
1416  /* No-op if reentrant call */
1417  if (PqCommBusy)
1418  return 0;
1419 
1420  /* Temporarily put the socket into non-blocking mode */
1421  socket_set_nonblocking(true);
1422 
1423  PqCommBusy = true;
1424  res = internal_flush();
1425  PqCommBusy = false;
1426  return res;
1427 }

References internal_flush(), PqCommBusy, PqSendPointer, PqSendStart, res, and socket_set_nonblocking().

◆ socket_is_send_pending()

static bool socket_is_send_pending ( void  )
static

Definition at line 1434 of file pqcomm.c.

1435 {
1436  return (PqSendStart < PqSendPointer);
1437 }

References PqSendPointer, and PqSendStart.

◆ socket_putmessage()

static int socket_putmessage ( char  msgtype,
const char *  s,
size_t  len 
)
static

Definition at line 1464 of file pqcomm.c.

1465 {
1466  uint32 n32;
1467 
1468  Assert(msgtype != 0);
1469 
1470  if (PqCommBusy)
1471  return 0;
1472  PqCommBusy = true;
1473  if (internal_putbytes(&msgtype, 1))
1474  goto fail;
1475 
1476  n32 = pg_hton32((uint32) (len + 4));
1477  if (internal_putbytes((char *) &n32, 4))
1478  goto fail;
1479 
1480  if (internal_putbytes(s, len))
1481  goto fail;
1482  PqCommBusy = false;
1483  return 0;
1484 
1485 fail:
1486  PqCommBusy = false;
1487  return EOF;
1488 }
unsigned int uint32
Definition: c.h:490
#define pg_hton32(x)
Definition: pg_bswap.h:121

References Assert(), internal_putbytes(), len, pg_hton32, and PqCommBusy.

◆ socket_putmessage_noblock()

static void socket_putmessage_noblock ( char  msgtype,
const char *  s,
size_t  len 
)
static

Definition at line 1497 of file pqcomm.c.

1498 {
1500  int required;
1501 
1502  /*
1503  * Ensure we have enough space in the output buffer for the message header
1504  * as well as the message itself.
1505  */
1506  required = PqSendPointer + 1 + 4 + len;
1507  if (required > PqSendBufferSize)
1508  {
1511  }
1512  res = pq_putmessage(msgtype, s, len);
1513  Assert(res == 0); /* should not fail when the message fits in
1514  * buffer */
1515 }
#define pq_putmessage(msgtype, s, len)
Definition: libpq.h:49
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1456

References Assert(), len, PG_USED_FOR_ASSERTS_ONLY, pq_putmessage, PqSendBuffer, PqSendBufferSize, PqSendPointer, repalloc(), generate_unaccent_rules::required, and res.

◆ socket_set_nonblocking()

static void socket_set_nonblocking ( bool  nonblocking)
static

Definition at line 898 of file pqcomm.c.

899 {
900  if (MyProcPort == NULL)
901  ereport(ERROR,
902  (errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
903  errmsg("there is no client connection")));
904 
905  MyProcPort->noblock = nonblocking;
906 }
#define ERROR
Definition: elog.h:39
bool noblock
Definition: libpq-be.h:148

References ereport, errcode(), errmsg(), ERROR, MyProcPort, and Port::noblock.

Referenced by internal_putbytes(), pq_getbyte_if_available(), pq_recvbuf(), socket_flush(), and socket_flush_if_writable().

◆ StreamClose()

void StreamClose ( pgsocket  sock)

Definition at line 832 of file pqcomm.c.

833 {
834  closesocket(sock);
835 }
#define closesocket
Definition: port.h:349

References closesocket.

Referenced by ClosePostmasterPorts(), CloseServerPorts(), ConnCreate(), and ServerLoop().

◆ StreamConnection()

int StreamConnection ( pgsocket  server_fd,
Port port 
)

Definition at line 698 of file pqcomm.c.

699 {
700  /* accept connection and fill in the client (remote) address */
701  port->raddr.salen = sizeof(port->raddr.addr);
702  if ((port->sock = accept(server_fd,
703  (struct sockaddr *) &port->raddr.addr,
704  &port->raddr.salen)) == PGINVALID_SOCKET)
705  {
706  ereport(LOG,
708  errmsg("could not accept new connection: %m")));
709 
710  /*
711  * If accept() fails then postmaster.c will still see the server
712  * socket as read-ready, and will immediately try again. To avoid
713  * uselessly sucking lots of CPU, delay a bit before trying again.
714  * (The most likely reason for failure is being out of kernel file
715  * table slots; we can do little except hope some will get freed up.)
716  */
717  pg_usleep(100000L); /* wait 0.1 sec */
718  return STATUS_ERROR;
719  }
720 
721  /* fill in the server (local) address */
722  port->laddr.salen = sizeof(port->laddr.addr);
723  if (getsockname(port->sock,
724  (struct sockaddr *) &port->laddr.addr,
725  &port->laddr.salen) < 0)
726  {
727  ereport(LOG,
728  (errmsg("%s() failed: %m", "getsockname")));
729  return STATUS_ERROR;
730  }
731 
732  /* select NODELAY and KEEPALIVE options if it's a TCP connection */
733  if (port->laddr.addr.ss_family != AF_UNIX)
734  {
735  int on;
736 #ifdef WIN32
737  int oldopt;
738  int optlen;
739  int newopt;
740 #endif
741 
742 #ifdef TCP_NODELAY
743  on = 1;
744  if (setsockopt(port->sock, IPPROTO_TCP, TCP_NODELAY,
745  (char *) &on, sizeof(on)) < 0)
746  {
747  ereport(LOG,
748  (errmsg("%s(%s) failed: %m", "setsockopt", "TCP_NODELAY")));
749  return STATUS_ERROR;
750  }
751 #endif
752  on = 1;
753  if (setsockopt(port->sock, SOL_SOCKET, SO_KEEPALIVE,
754  (char *) &on, sizeof(on)) < 0)
755  {
756  ereport(LOG,
757  (errmsg("%s(%s) failed: %m", "setsockopt", "SO_KEEPALIVE")));
758  return STATUS_ERROR;
759  }
760 
761 #ifdef WIN32
762 
763  /*
764  * This is a Win32 socket optimization. The OS send buffer should be
765  * large enough to send the whole Postgres send buffer in one go, or
766  * performance suffers. The Postgres send buffer can be enlarged if a
767  * very large message needs to be sent, but we won't attempt to
768  * enlarge the OS buffer if that happens, so somewhat arbitrarily
769  * ensure that the OS buffer is at least PQ_SEND_BUFFER_SIZE * 4.
770  * (That's 32kB with the current default).
771  *
772  * The default OS buffer size used to be 8kB in earlier Windows
773  * versions, but was raised to 64kB in Windows 2012. So it shouldn't
774  * be necessary to change it in later versions anymore. Changing it
775  * unnecessarily can even reduce performance, because setting
776  * SO_SNDBUF in the application disables the "dynamic send buffering"
777  * feature that was introduced in Windows 7. So before fiddling with
778  * SO_SNDBUF, check if the current buffer size is already large enough
779  * and only increase it if necessary.
780  *
781  * See https://support.microsoft.com/kb/823764/EN-US/ and
782  * https://msdn.microsoft.com/en-us/library/bb736549%28v=vs.85%29.aspx
783  */
784  optlen = sizeof(oldopt);
785  if (getsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &oldopt,
786  &optlen) < 0)
787  {
788  ereport(LOG,
789  (errmsg("%s(%s) failed: %m", "getsockopt", "SO_SNDBUF")));
790  return STATUS_ERROR;
791  }
792  newopt = PQ_SEND_BUFFER_SIZE * 4;
793  if (oldopt < newopt)
794  {
795  if (setsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &newopt,
796  sizeof(newopt)) < 0)
797  {
798  ereport(LOG,
799  (errmsg("%s(%s) failed: %m", "setsockopt", "SO_SNDBUF")));
800  return STATUS_ERROR;
801  }
802  }
803 #endif
804 
805  /*
806  * Also apply the current keepalive parameters. If we fail to set a
807  * parameter, don't error out, because these aren't universally
808  * supported. (Note: you might think we need to reset the GUC
809  * variables to 0 in such a case, but it's not necessary because the
810  * show hooks for these variables report the truth anyway.)
811  */
816  }
817 
818  return STATUS_OK;
819 }
int tcp_keepalives_idle
Definition: guc_tables.c:519
int tcp_keepalives_interval
Definition: guc_tables.c:520
int tcp_keepalives_count
Definition: guc_tables.c:521
int tcp_user_timeout
Definition: guc_tables.c:522
void pg_usleep(long microsec)
Definition: signal.c:53
#define accept(s, addr, addrlen)
Definition: win32_port.h:497

References accept, ereport, errcode_for_socket_access(), errmsg(), LOG, pg_usleep(), PGINVALID_SOCKET, port, PQ_SEND_BUFFER_SIZE, pq_setkeepalivescount(), pq_setkeepalivesidle(), pq_setkeepalivesinterval(), pq_settcpusertimeout(), STATUS_ERROR, STATUS_OK, tcp_keepalives_count, tcp_keepalives_idle, tcp_keepalives_interval, and tcp_user_timeout.

Referenced by ConnCreate().

◆ StreamServerPort()

int StreamServerPort ( int  family,
const char *  hostName,
unsigned short  portNumber,
const char *  unixSocketDir,
pgsocket  ListenSocket[],
int  MaxListen 
)

Definition at line 321 of file pqcomm.c.

324 {
325  pgsocket fd;
326  int err;
327  int maxconn;
328  int ret;
329  char portNumberStr[32];
330  const char *familyDesc;
331  char familyDescBuf[64];
332  const char *addrDesc;
333  char addrBuf[NI_MAXHOST];
334  char *service;
335  struct addrinfo *addrs = NULL,
336  *addr;
337  struct addrinfo hint;
338  int listen_index = 0;
339  int added = 0;
340  char unixSocketPath[MAXPGPATH];
341 #if !defined(WIN32) || defined(IPV6_V6ONLY)
342  int one = 1;
343 #endif
344 
345  /* Initialize hint structure */
346  MemSet(&hint, 0, sizeof(hint));
347  hint.ai_family = family;
348  hint.ai_flags = AI_PASSIVE;
349  hint.ai_socktype = SOCK_STREAM;
350 
351  if (family == AF_UNIX)
352  {
353  /*
354  * Create unixSocketPath from portNumber and unixSocketDir and lock
355  * that file path
356  */
357  UNIXSOCK_PATH(unixSocketPath, portNumber, unixSocketDir);
358  if (strlen(unixSocketPath) >= UNIXSOCK_PATH_BUFLEN)
359  {
360  ereport(LOG,
361  (errmsg("Unix-domain socket path \"%s\" is too long (maximum %d bytes)",
362  unixSocketPath,
363  (int) (UNIXSOCK_PATH_BUFLEN - 1))));
364  return STATUS_ERROR;
365  }
366  if (Lock_AF_UNIX(unixSocketDir, unixSocketPath) != STATUS_OK)
367  return STATUS_ERROR;
368  service = unixSocketPath;
369  }
370  else
371  {
372  snprintf(portNumberStr, sizeof(portNumberStr), "%d", portNumber);
373  service = portNumberStr;
374  }
375 
376  ret = pg_getaddrinfo_all(hostName, service, &hint, &addrs);
377  if (ret || !addrs)
378  {
379  if (hostName)
380  ereport(LOG,
381  (errmsg("could not translate host name \"%s\", service \"%s\" to address: %s",
382  hostName, service, gai_strerror(ret))));
383  else
384  ereport(LOG,
385  (errmsg("could not translate service \"%s\" to address: %s",
386  service, gai_strerror(ret))));
387  if (addrs)
388  pg_freeaddrinfo_all(hint.ai_family, addrs);
389  return STATUS_ERROR;
390  }
391 
392  for (addr = addrs; addr; addr = addr->ai_next)
393  {
394  if (family != AF_UNIX && addr->ai_family == AF_UNIX)
395  {
396  /*
397  * Only set up a unix domain socket when they really asked for it.
398  * The service/port is different in that case.
399  */
400  continue;
401  }
402 
403  /* See if there is still room to add 1 more socket. */
404  for (; listen_index < MaxListen; listen_index++)
405  {
406  if (ListenSocket[listen_index] == PGINVALID_SOCKET)
407  break;
408  }
409  if (listen_index >= MaxListen)
410  {
411  ereport(LOG,
412  (errmsg("could not bind to all requested addresses: MAXLISTEN (%d) exceeded",
413  MaxListen)));
414  break;
415  }
416 
417  /* set up address family name for log messages */
418  switch (addr->ai_family)
419  {
420  case AF_INET:
421  familyDesc = _("IPv4");
422  break;
423  case AF_INET6:
424  familyDesc = _("IPv6");
425  break;
426  case AF_UNIX:
427  familyDesc = _("Unix");
428  break;
429  default:
430  snprintf(familyDescBuf, sizeof(familyDescBuf),
431  _("unrecognized address family %d"),
432  addr->ai_family);
433  familyDesc = familyDescBuf;
434  break;
435  }
436 
437  /* set up text form of address for log messages */
438  if (addr->ai_family == AF_UNIX)
439  addrDesc = unixSocketPath;
440  else
441  {
442  pg_getnameinfo_all((const struct sockaddr_storage *) addr->ai_addr,
443  addr->ai_addrlen,
444  addrBuf, sizeof(addrBuf),
445  NULL, 0,
446  NI_NUMERICHOST);
447  addrDesc = addrBuf;
448  }
449 
450  if ((fd = socket(addr->ai_family, SOCK_STREAM, 0)) == PGINVALID_SOCKET)
451  {
452  ereport(LOG,
454  /* translator: first %s is IPv4, IPv6, or Unix */
455  errmsg("could not create %s socket for address \"%s\": %m",
456  familyDesc, addrDesc)));
457  continue;
458  }
459 
460 #ifndef WIN32
461 
462  /*
463  * Without the SO_REUSEADDR flag, a new postmaster can't be started
464  * right away after a stop or crash, giving "address already in use"
465  * error on TCP ports.
466  *
467  * On win32, however, this behavior only happens if the
468  * SO_EXCLUSIVEADDRUSE is set. With SO_REUSEADDR, win32 allows
469  * multiple servers to listen on the same address, resulting in
470  * unpredictable behavior. With no flags at all, win32 behaves as Unix
471  * with SO_REUSEADDR.
472  */
473  if (addr->ai_family != AF_UNIX)
474  {
475  if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
476  (char *) &one, sizeof(one))) == -1)
477  {
478  ereport(LOG,
480  /* translator: third %s is IPv4, IPv6, or Unix */
481  errmsg("%s(%s) failed for %s address \"%s\": %m",
482  "setsockopt", "SO_REUSEADDR",
483  familyDesc, addrDesc)));
484  closesocket(fd);
485  continue;
486  }
487  }
488 #endif
489 
490 #ifdef IPV6_V6ONLY
491  if (addr->ai_family == AF_INET6)
492  {
493  if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
494  (char *) &one, sizeof(one)) == -1)
495  {
496  ereport(LOG,
498  /* translator: third %s is IPv4, IPv6, or Unix */
499  errmsg("%s(%s) failed for %s address \"%s\": %m",
500  "setsockopt", "IPV6_V6ONLY",
501  familyDesc, addrDesc)));
502  closesocket(fd);
503  continue;
504  }
505  }
506 #endif
507 
508  /*
509  * Note: This might fail on some OS's, like Linux older than
510  * 2.4.21-pre3, that don't have the IPV6_V6ONLY socket option, and map
511  * ipv4 addresses to ipv6. It will show ::ffff:ipv4 for all ipv4
512  * connections.
513  */
514  err = bind(fd, addr->ai_addr, addr->ai_addrlen);
515  if (err < 0)
516  {
517  int saved_errno = errno;
518 
519  ereport(LOG,
521  /* translator: first %s is IPv4, IPv6, or Unix */
522  errmsg("could not bind %s address \"%s\": %m",
523  familyDesc, addrDesc),
524  saved_errno == EADDRINUSE ?
525  (addr->ai_family == AF_UNIX ?
526  errhint("Is another postmaster already running on port %d?",
527  (int) portNumber) :
528  errhint("Is another postmaster already running on port %d?"
529  " If not, wait a few seconds and retry.",
530  (int) portNumber)) : 0));
531  closesocket(fd);
532  continue;
533  }
534 
535  if (addr->ai_family == AF_UNIX)
536  {
537  if (Setup_AF_UNIX(service) != STATUS_OK)
538  {
539  closesocket(fd);
540  break;
541  }
542  }
543 
544  /*
545  * Select appropriate accept-queue length limit. It seems reasonable
546  * to use a value similar to the maximum number of child processes
547  * that the postmaster will permit.
548  */
549  maxconn = MaxConnections * 2;
550 
551  err = listen(fd, maxconn);
552  if (err < 0)
553  {
554  ereport(LOG,
556  /* translator: first %s is IPv4, IPv6, or Unix */
557  errmsg("could not listen on %s address \"%s\": %m",
558  familyDesc, addrDesc)));
559  closesocket(fd);
560  continue;
561  }
562 
563  if (addr->ai_family == AF_UNIX)
564  ereport(LOG,
565  (errmsg("listening on Unix socket \"%s\"",
566  addrDesc)));
567  else
568  ereport(LOG,
569  /* translator: first %s is IPv4 or IPv6 */
570  (errmsg("listening on %s address \"%s\", port %d",
571  familyDesc, addrDesc, (int) portNumber)));
572 
573  ListenSocket[listen_index] = fd;
574  added++;
575  }
576 
577  pg_freeaddrinfo_all(hint.ai_family, addrs);
578 
579  if (!added)
580  return STATUS_ERROR;
581 
582  return STATUS_OK;
583 }
#define MemSet(start, val, len)
Definition: c.h:1004
int errhint(const char *fmt,...)
Definition: elog.c:1316
#define _(x)
Definition: elog.c:91
void err(int eval, const char *fmt,...)
Definition: err.c:43
int MaxConnections
Definition: globals.c:137
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
Definition: ip.c:82
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
Definition: ip.c:114
int pg_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
Definition: ip.c:53
#define MAXPGPATH
int pgsocket
Definition: port.h:29
static pgsocket ListenSocket[MAXLISTEN]
Definition: postmaster.c:229
static int Lock_AF_UNIX(const char *unixSocketDir, const char *unixSocketPath)
Definition: pqcomm.c:590
static int Setup_AF_UNIX(const char *sock_path)
Definition: pqcomm.c:625
#define UNIXSOCK_PATH(path, port, sockdir)
Definition: pqcomm.h:32
#define UNIXSOCK_PATH_BUFLEN
Definition: pqcomm.h:48
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define bind(s, addr, addrlen)
Definition: win32_port.h:495
#define EADDRINUSE
Definition: win32_port.h:402
#define socket(af, type, protocol)
Definition: win32_port.h:494
#define listen(s, backlog)
Definition: win32_port.h:496

References _, bind, closesocket, EADDRINUSE, ereport, err(), errcode_for_socket_access(), errhint(), errmsg(), fd(), listen, ListenSocket, Lock_AF_UNIX(), LOG, MaxConnections, MAXPGPATH, MemSet, pg_freeaddrinfo_all(), pg_getaddrinfo_all(), pg_getnameinfo_all(), PGINVALID_SOCKET, Setup_AF_UNIX(), snprintf, socket, STATUS_ERROR, STATUS_OK, UNIXSOCK_PATH, and UNIXSOCK_PATH_BUFLEN.

Referenced by PostmasterMain().

◆ TouchSocketFiles()

void TouchSocketFiles ( void  )

Definition at line 847 of file pqcomm.c.

848 {
849  ListCell *l;
850 
851  /* Loop through all created sockets... */
852  foreach(l, sock_paths)
853  {
854  char *sock_path = (char *) lfirst(l);
855 
856  /* Ignore errors; there's no point in complaining */
857  (void) utime(sock_path, NULL);
858  }
859 }

References lfirst, and sock_paths.

Referenced by ServerLoop().

Variable Documentation

◆ FeBeWaitSet

◆ PqCommBusy

bool PqCommBusy
static

◆ PqCommMethods

const PQcommMethods* PqCommMethods = &PqCommSocketMethods

Definition at line 162 of file pqcomm.c.

Referenced by pq_redirect_to_shm_mq(), and pq_set_parallel_leader().

◆ PqCommReadingMsg

◆ PqCommSocketMethods

const PQcommMethods PqCommSocketMethods
static
Initial value:
= {
}
static int socket_flush_if_writable(void)
Definition: pqcomm.c:1408
static int socket_flush(void)
Definition: pqcomm.c:1313
static void socket_comm_reset(void)
Definition: pqcomm.c:235
static bool socket_is_send_pending(void)
Definition: pqcomm.c:1434
static int socket_putmessage(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1464
static void socket_putmessage_noblock(char msgtype, const char *s, size_t len)
Definition: pqcomm.c:1497

Definition at line 153 of file pqcomm.c.

◆ PqRecvBuffer

char PqRecvBuffer[PQ_RECV_BUFFER_SIZE]
static

Definition at line 127 of file pqcomm.c.

Referenced by pq_getbyte(), pq_getbyte_if_available(), pq_getbytes(), pq_peekbyte(), and pq_recvbuf().

◆ PqRecvLength

int PqRecvLength
static

◆ PqRecvPointer

int PqRecvPointer
static

◆ PqSendBuffer

char* PqSendBuffer
static

Definition at line 122 of file pqcomm.c.

Referenced by internal_flush(), internal_putbytes(), pq_init(), and socket_putmessage_noblock().

◆ PqSendBufferSize

int PqSendBufferSize
static

Definition at line 123 of file pqcomm.c.

Referenced by internal_putbytes(), pq_init(), and socket_putmessage_noblock().

◆ PqSendPointer

◆ PqSendStart

int PqSendStart
static

◆ sock_paths

List* sock_paths = NIL
static

Definition at line 110 of file pqcomm.c.

Referenced by Lock_AF_UNIX(), RemoveSocketFiles(), and TouchSocketFiles().

◆ Unix_socket_group

char* Unix_socket_group

Definition at line 107 of file pqcomm.c.

Referenced by Setup_AF_UNIX().

◆ Unix_socket_permissions

int Unix_socket_permissions

Definition at line 106 of file pqcomm.c.

Referenced by Setup_AF_UNIX(), and show_unix_socket_permissions().