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

Function InitPostmasterChild

src/backend/utils/init/miscinit.c:103–167  ·  view source on GitHub ↗

* Initialize the basic environment for a postmaster child * * Should be called as early as possible after the child's startup. */

Source from the content-addressed store, hash-verified

101 * Should be called as early as possible after the child's startup.
102 */
103void
104InitPostmasterChild(void)
105{
106 IsUnderPostmaster = true; /* we are a postmaster subprocess now */
107
108 /*
109 * Set reference point for stack-depth checking. This might seem
110 * redundant in !EXEC_BACKEND builds; but it's not because the postmaster
111 * launches its children from signal handlers, so we might be running on
112 * an alternative stack.
113 */
114 (void) set_stack_base();
115
116 InitProcessGlobals();
117
118 /*
119 * make sure stderr is in binary mode before anything can possibly be
120 * written to it, in case it's actually the syslogger pipe, so the pipe
121 * chunking protocol isn't disturbed. Non-logpipe data gets translated on
122 * redirection (e.g. via pg_ctl -l) anyway.
123 */
124#ifdef WIN32
125 _setmode(fileno(stderr), _O_BINARY);
126#endif
127
128 /* We don't want the postmaster's proc_exit() handlers */
129 on_exit_reset();
130
131 /* In EXEC_BACKEND case we will not have inherited BlockSig etc values */
132#ifdef EXEC_BACKEND
133 pqinitmask();
134#endif
135
136 /* Initialize process-local latch support */
137 InitializeLatchSupport();
138 MyLatch = &LocalLatchData;
139 InitLatch(MyLatch);
140 InitializeLatchWaitSet();
141
142 /*
143 * If possible, make this process a group leader, so that the postmaster
144 * can signal any child processes too. Not all processes will have
145 * children, but for consistency we make all postmaster child processes do
146 * this.
147 */
148#ifdef HAVE_SETSID
149 if (setsid() < 0)
150 elog(FATAL, "setsid() failed: %m");
151#endif
152
153 /*
154 * Every postmaster child process is expected to respond promptly to
155 * SIGQUIT at all times. Therefore we centrally remove SIGQUIT from
156 * BlockSig and install a suitable signal handler. (Client-facing
157 * processes may choose to replace this default choice of handler with
158 * quickdie().) All other blockable signals remain blocked for now.
159 */
160 pqsignal(SIGQUIT, SignalHandlerForCrashExit);

Callers 10

syslogger.cFile · 0.85
StartLoginMonitorWorkerFunction · 0.85
BackendStartupFunction · 0.85
SubPostmasterMainFunction · 0.85
StartChildProcessFunction · 0.85
do_start_bgworkerFunction · 0.85
StartAutoVacLauncherFunction · 0.85
StartAutoVacWorkerFunction · 0.85
pgstat.cFile · 0.85

Calls 9

set_stack_baseFunction · 0.85
InitProcessGlobalsFunction · 0.85
on_exit_resetFunction · 0.85
pqinitmaskFunction · 0.85
InitializeLatchSupportFunction · 0.85
InitLatchFunction · 0.85
InitializeLatchWaitSetFunction · 0.85
pqsignalFunction · 0.50

Tested by

no test coverage detected