PostgreSQL Source Code git master
Loading...
Searching...
No Matches
launch_backend.c File Reference
Include dependency graph for launch_backend.c:

Go to the source code of this file.

Data Structures

struct  child_process_kind
 

Macros

#define PG_PROCTYPE(bktype, description, main_func, shmem_attach)    [bktype] = {description, main_func, shmem_attach},
 

Functions

const charPostmasterChildName (BackendType child_type)
 
pid_t postmaster_child_launch (BackendType child_type, int child_slot, void *startup_data, size_t startup_data_len, ClientSocket *client_sock)
 

Variables

static child_process_kind child_process_kinds []
 

Macro Definition Documentation

◆ PG_PROCTYPE

#define PG_PROCTYPE (   bktype,
  description,
  main_func,
  shmem_attach 
)     [bktype] = {description, main_func, shmem_attach},

Function Documentation

◆ postmaster_child_launch()

pid_t postmaster_child_launch ( BackendType  child_type,
int  child_slot,
void startup_data,
size_t  startup_data_len,
ClientSocket client_sock 
)

Definition at line 207 of file launch_backend.c.

210{
211 pid_t pid;
212
214
215 /* Capture time Postmaster initiates process creation for logging */
218
219#ifdef EXEC_BACKEND
220 pid = internal_forkexec(child_type, child_slot,
222 /* the child process will arrive in SubPostmasterMain */
223#else /* !EXEC_BACKEND */
224 pid = fork_process();
225 if (pid == 0) /* child */
226 {
227 /* Capture and transfer timings that may be needed for logging */
229 {
231 ((BackendStartupData *) startup_data)->socket_created;
233 ((BackendStartupData *) startup_data)->fork_started;
235 }
236
237 /* Close the postmaster's sockets */
239
240 /* Detangle from postmaster */
242
243 /* Detach shared memory if not needed. */
244 if (!child_process_kinds[child_type].shmem_attach)
245 {
248 }
249
250 /*
251 * Enter the Main function with TopMemoryContext. The startup data is
252 * allocated in PostmasterContext, so we cannot release it here yet.
253 * The Main function will do it after it's done handling the startup
254 * data.
255 */
257
258 MyPMChildSlot = child_slot;
259 if (client_sock)
260 {
263 }
264
265 /*
266 * Run the appropriate Main function
267 */
269 pg_unreachable(); /* main_fn never returns */
270 }
271#endif /* EXEC_BACKEND */
272 return pid;
273}
TimestampTz GetCurrentTimestamp(void)
Definition timestamp.c:1645
ConnectionTiming conn_timing
#define Assert(condition)
Definition c.h:873
#define pg_unreachable()
Definition c.h:341
void dsm_detach_all(void)
Definition dsm.c:775
#define palloc_object(type)
Definition fe_memutils.h:74
pid_t fork_process(void)
struct ClientSocket * MyClientSocket
Definition globals.c:50
int MyPMChildSlot
Definition globals.c:54
bool IsUnderPostmaster
Definition globals.c:120
bool IsPostmasterEnvironment
Definition globals.c:119
static child_process_kind child_process_kinds[]
MemoryContext TopMemoryContext
Definition mcxt.c:166
#define IsExternalConnectionBackend(backend_type)
Definition miscadmin.h:405
@ B_LOGGER
Definition miscadmin.h:374
void InitPostmasterChild(void)
Definition miscinit.c:96
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
void ClosePostmasterPorts(bool am_syslogger)
static int fb(int x)
TimestampTz socket_create
TimestampTz fork_start
void(* main_fn)(const void *startup_data, size_t startup_data_len)
void PGSharedMemoryDetach(void)
Definition sysv_shmem.c:972

References Assert, B_LOGGER, child_process_kinds, ClosePostmasterPorts(), conn_timing, dsm_detach_all(), fb(), ConnectionTiming::fork_end, fork_process(), ConnectionTiming::fork_start, GetCurrentTimestamp(), InitPostmasterChild(), IsExternalConnectionBackend, IsPostmasterEnvironment, IsUnderPostmaster, child_process_kind::main_fn, MemoryContextSwitchTo(), MyClientSocket, MyPMChildSlot, palloc_object, pg_unreachable, PGSharedMemoryDetach(), ConnectionTiming::socket_create, and TopMemoryContext.

Referenced by BackendStartup(), StartBackgroundWorker(), StartChildProcess(), and SysLogger_Start().

◆ PostmasterChildName()

const char * PostmasterChildName ( BackendType  child_type)

Definition at line 189 of file launch_backend.c.

190{
192}

References child_process_kinds, fb(), and child_process_kind::name.

Referenced by AssignPostmasterChildSlot(), and StartChildProcess().

Variable Documentation

◆ child_process_kinds

child_process_kind child_process_kinds[]
static
Initial value:
= {
#define PG_PROCTYPE(bktype, description, main_func, shmem_attach)
}

Definition at line 181 of file launch_backend.c.

181 {
182#define PG_PROCTYPE(bktype, description, main_func, shmem_attach) \
183 [bktype] = {description, main_func, shmem_attach},
185#undef PG_PROCTYPE
186};

Referenced by postmaster_child_launch(), and PostmasterChildName().