MCPcopy Create free account
hub / github.com/apache/cloudberry / BackendInitialize

Function BackendInitialize

src/backend/postmaster/postmaster.c:4885–5074  ·  view source on GitHub ↗

* BackendInitialize -- initialize an interactive (postmaster-child) * backend process, and collect the client's startup packet. * * returns: nothing. Will not return at all if there's any failure. * * Note: this code does not depend on having any access to shared memory. * Indeed, our approach to SIGTERM/timeout handling *requires* that * shared memory not have been touched yet; see com

Source from the content-addressed store, hash-verified

4883 * but have not yet set up most of our local pointers to shmem structures.
4884 */
4885static void
4886BackendInitialize(Port *port)
4887{
4888 int status;
4889 int ret;
4890 char remote_host[NI_MAXHOST];
4891 char remote_port[NI_MAXSERV];
4892 StringInfoData ps_data;
4893
4894 /* Save port etc. for ps status */
4895 MyProcPort = port;
4896
4897 /* Tell fd.c about the long-lived FD associated with the port */
4898 ReserveExternalFD();
4899
4900 /*
4901 * PreAuthDelay is a debugging aid for investigating problems in the
4902 * authentication cycle: it can be set in postgresql.conf to allow time to
4903 * attach to the newly-forked backend with a debugger. (See also
4904 * PostAuthDelay, which we allow clients to pass through PGOPTIONS, but it
4905 * is not honored until after authentication.)
4906 */
4907 if (PreAuthDelay > 0)
4908 pg_usleep(PreAuthDelay * 1000000L);
4909
4910 /* This flag will remain set until InitPostgres finishes authentication */
4911 ClientAuthInProgress = true; /* limit visibility of log messages */
4912
4913 /* set these to empty in case they are needed before we set them up */
4914 port->remote_host = "";
4915 port->remote_port = "";
4916
4917 /*
4918 * Initialize libpq and enable reporting of ereport errors to the client.
4919 * Must do this now because authentication uses libpq to send messages.
4920 */
4921 pq_init(); /* initialize libpq to talk to client */
4922 whereToSendOutput = DestRemote; /* now safe to ereport to client */
4923
4924 /*
4925 * We arrange to do _exit(1) if we receive SIGTERM or timeout while trying
4926 * to collect the startup packet; while SIGQUIT results in _exit(2).
4927 * Otherwise the postmaster cannot shutdown the database FAST or IMMED
4928 * cleanly if a buggy client fails to send the packet promptly.
4929 *
4930 * Exiting with _exit(1) is only possible because we have not yet touched
4931 * shared memory; therefore no outside-the-process state needs to get
4932 * cleaned up.
4933 */
4934 pqsignal(SIGTERM, process_startup_packet_die);
4935 /* SIGQUIT handler was already set up by InitPostmasterChild */
4936 InitializeTimeouts(); /* establishes SIGALRM handler */
4937 PG_SETMASK(&StartupBlockSig);
4938
4939 /*
4940 * Get the remote host name and port for logging and status display.
4941 */
4942 remote_host[0] = '\0';

Callers 2

BackendStartupFunction · 0.85
SubPostmasterMainFunction · 0.85

Calls 15

ReserveExternalFDFunction · 0.85
pq_initFunction · 0.85
InitializeTimeoutsFunction · 0.85
pg_getnameinfo_allFunction · 0.85
gai_strerrorFunction · 0.85
RegisterTimeoutFunction · 0.85
enable_timeout_afterFunction · 0.85
ProcessStartupPacketFunction · 0.85
disable_timeoutFunction · 0.85
proc_exitFunction · 0.85
initStringInfoFunction · 0.85

Tested by

no test coverage detected