@@ -75,6 +75,119 @@ static Latch LocalLatchData;
75
75
bool IgnoreSystemIndexes = false;
76
76
77
77
78
+ /* ----------------------------------------------------------------
79
+ * common process startup code
80
+ * ----------------------------------------------------------------
81
+ */
82
+
83
+ /*
84
+ * Initialize the basic environment for a postmaster child
85
+ *
86
+ * Should be called as early as possible after the child's startup.
87
+ */
88
+ void
89
+ InitPostmasterChild (void )
90
+ {
91
+ IsUnderPostmaster = true; /* we are a postmaster subprocess now */
92
+
93
+ InitProcessGlobals ();
94
+
95
+ /*
96
+ * make sure stderr is in binary mode before anything can possibly be
97
+ * written to it, in case it's actually the syslogger pipe, so the pipe
98
+ * chunking protocol isn't disturbed. Non-logpipe data gets translated on
99
+ * redirection (e.g. via pg_ctl -l) anyway.
100
+ */
101
+ #ifdef WIN32
102
+ _setmode (fileno (stderr ), _O_BINARY );
103
+ #endif
104
+
105
+ /* We don't want the postmaster's proc_exit() handlers */
106
+ on_exit_reset ();
107
+
108
+ /* Initialize process-local latch support */
109
+ InitializeLatchSupport ();
110
+ MyLatch = & LocalLatchData ;
111
+ InitLatch (MyLatch );
112
+
113
+ /*
114
+ * If possible, make this process a group leader, so that the postmaster
115
+ * can signal any child processes too. Not all processes will have
116
+ * children, but for consistency we make all postmaster child processes do
117
+ * this.
118
+ */
119
+ #ifdef HAVE_SETSID
120
+ if (setsid () < 0 )
121
+ elog (FATAL , "setsid() failed: %m" );
122
+ #endif
123
+
124
+ /* Request a signal if the postmaster dies, if possible. */
125
+ PostmasterDeathSignalInit ();
126
+ }
127
+
128
+ /*
129
+ * Initialize the basic environment for a standalone process.
130
+ *
131
+ * argv0 has to be suitable to find the program's executable.
132
+ */
133
+ void
134
+ InitStandaloneProcess (const char * argv0 )
135
+ {
136
+ Assert (!IsPostmasterEnvironment );
137
+
138
+ InitProcessGlobals ();
139
+
140
+ /* Initialize process-local latch support */
141
+ InitializeLatchSupport ();
142
+ MyLatch = & LocalLatchData ;
143
+ InitLatch (MyLatch );
144
+
145
+ /* Compute paths, no postmaster to inherit from */
146
+ if (my_exec_path [0 ] == '\0' )
147
+ {
148
+ if (find_my_exec (argv0 , my_exec_path ) < 0 )
149
+ elog (FATAL , "%s: could not locate my own executable path" ,
150
+ argv0 );
151
+ }
152
+
153
+ if (pkglib_path [0 ] == '\0' )
154
+ get_pkglib_path (my_exec_path , pkglib_path );
155
+ }
156
+
157
+ void
158
+ SwitchToSharedLatch (void )
159
+ {
160
+ Assert (MyLatch == & LocalLatchData );
161
+ Assert (MyProc != NULL );
162
+
163
+ MyLatch = & MyProc -> procLatch ;
164
+
165
+ if (FeBeWaitSet )
166
+ ModifyWaitEvent (FeBeWaitSet , 1 , WL_LATCH_SET , MyLatch );
167
+
168
+ /*
169
+ * Set the shared latch as the local one might have been set. This
170
+ * shouldn't normally be necessary as code is supposed to check the
171
+ * condition before waiting for the latch, but a bit care can't hurt.
172
+ */
173
+ SetLatch (MyLatch );
174
+ }
175
+
176
+ void
177
+ SwitchBackToLocalLatch (void )
178
+ {
179
+ Assert (MyLatch != & LocalLatchData );
180
+ Assert (MyProc != NULL && MyLatch == & MyProc -> procLatch );
181
+
182
+ MyLatch = & LocalLatchData ;
183
+
184
+ if (FeBeWaitSet )
185
+ ModifyWaitEvent (FeBeWaitSet , 1 , WL_LATCH_SET , MyLatch );
186
+
187
+ SetLatch (MyLatch );
188
+ }
189
+
190
+
78
191
/* ----------------------------------------------------------------
79
192
* database path / name support stuff
80
193
* ----------------------------------------------------------------
@@ -262,113 +375,6 @@ static int SecurityRestrictionContext = 0;
262
375
/* We also remember if a SET ROLE is currently active */
263
376
static bool SetRoleIsActive = false;
264
377
265
- /*
266
- * Initialize the basic environment for a postmaster child
267
- *
268
- * Should be called as early as possible after the child's startup.
269
- */
270
- void
271
- InitPostmasterChild (void )
272
- {
273
- IsUnderPostmaster = true; /* we are a postmaster subprocess now */
274
-
275
- InitProcessGlobals ();
276
-
277
- /*
278
- * make sure stderr is in binary mode before anything can possibly be
279
- * written to it, in case it's actually the syslogger pipe, so the pipe
280
- * chunking protocol isn't disturbed. Non-logpipe data gets translated on
281
- * redirection (e.g. via pg_ctl -l) anyway.
282
- */
283
- #ifdef WIN32
284
- _setmode (fileno (stderr ), _O_BINARY );
285
- #endif
286
-
287
- /* We don't want the postmaster's proc_exit() handlers */
288
- on_exit_reset ();
289
-
290
- /* Initialize process-local latch support */
291
- InitializeLatchSupport ();
292
- MyLatch = & LocalLatchData ;
293
- InitLatch (MyLatch );
294
-
295
- /*
296
- * If possible, make this process a group leader, so that the postmaster
297
- * can signal any child processes too. Not all processes will have
298
- * children, but for consistency we make all postmaster child processes do
299
- * this.
300
- */
301
- #ifdef HAVE_SETSID
302
- if (setsid () < 0 )
303
- elog (FATAL , "setsid() failed: %m" );
304
- #endif
305
-
306
- /* Request a signal if the postmaster dies, if possible. */
307
- PostmasterDeathSignalInit ();
308
- }
309
-
310
- /*
311
- * Initialize the basic environment for a standalone process.
312
- *
313
- * argv0 has to be suitable to find the program's executable.
314
- */
315
- void
316
- InitStandaloneProcess (const char * argv0 )
317
- {
318
- Assert (!IsPostmasterEnvironment );
319
-
320
- InitProcessGlobals ();
321
-
322
- /* Initialize process-local latch support */
323
- InitializeLatchSupport ();
324
- MyLatch = & LocalLatchData ;
325
- InitLatch (MyLatch );
326
-
327
- /* Compute paths, no postmaster to inherit from */
328
- if (my_exec_path [0 ] == '\0' )
329
- {
330
- if (find_my_exec (argv0 , my_exec_path ) < 0 )
331
- elog (FATAL , "%s: could not locate my own executable path" ,
332
- argv0 );
333
- }
334
-
335
- if (pkglib_path [0 ] == '\0' )
336
- get_pkglib_path (my_exec_path , pkglib_path );
337
- }
338
-
339
- void
340
- SwitchToSharedLatch (void )
341
- {
342
- Assert (MyLatch == & LocalLatchData );
343
- Assert (MyProc != NULL );
344
-
345
- MyLatch = & MyProc -> procLatch ;
346
-
347
- if (FeBeWaitSet )
348
- ModifyWaitEvent (FeBeWaitSet , 1 , WL_LATCH_SET , MyLatch );
349
-
350
- /*
351
- * Set the shared latch as the local one might have been set. This
352
- * shouldn't normally be necessary as code is supposed to check the
353
- * condition before waiting for the latch, but a bit care can't hurt.
354
- */
355
- SetLatch (MyLatch );
356
- }
357
-
358
- void
359
- SwitchBackToLocalLatch (void )
360
- {
361
- Assert (MyLatch != & LocalLatchData );
362
- Assert (MyProc != NULL && MyLatch == & MyProc -> procLatch );
363
-
364
- MyLatch = & LocalLatchData ;
365
-
366
- if (FeBeWaitSet )
367
- ModifyWaitEvent (FeBeWaitSet , 1 , WL_LATCH_SET , MyLatch );
368
-
369
- SetLatch (MyLatch );
370
- }
371
-
372
378
/*
373
379
* GetUserId - get the current effective user ID.
374
380
*
0 commit comments