PostgreSQL Source Code git master
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 char * PostmasterChildName (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 */
216 if (IsExternalConnectionBackend(child_type))
217 ((BackendStartupData *) startup_data)->fork_started = GetCurrentTimestamp();
218
219#ifdef EXEC_BACKEND
220 pid = internal_forkexec(child_process_kinds[child_type].name, child_slot,
221 startup_data, startup_data_len, client_sock);
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 */
228 if (IsExternalConnectionBackend(child_type))
229 {
231 ((BackendStartupData *) startup_data)->socket_created;
233 ((BackendStartupData *) startup_data)->fork_started;
235 }
236
237 /* Close the postmaster's sockets */
238 ClosePostmasterPorts(child_type == B_LOGGER);
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 {
262 memcpy(MyClientSocket, client_sock, sizeof(ClientSocket));
263 }
264
265 /*
266 * Run the appropriate Main function
267 */
268 child_process_kinds[child_type].main_fn(startup_data, startup_data_len);
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 pg_unreachable()
Definition: c.h:336
void dsm_detach_all(void)
Definition: dsm.c:775
pid_t fork_process(void)
Definition: fork_process.c:33
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
Assert(PointerIsAligned(start, uint64))
static child_process_kind child_process_kinds[]
MemoryContext TopMemoryContext
Definition: mcxt.c:166
void * palloc(Size size)
Definition: mcxt.c:1365
#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)
Definition: postmaster.c:1866
TimestampTz socket_create
TimestampTz fork_start
TimestampTz fork_end
void(* main_fn)(const void *startup_data, size_t startup_data_len)
void PGSharedMemoryDetach(void)
Definition: sysv_shmem.c:970
const char * name

References Assert(), B_LOGGER, child_process_kinds, ClosePostmasterPorts(), conn_timing, dsm_detach_all(), ConnectionTiming::fork_end, fork_process(), ConnectionTiming::fork_start, GetCurrentTimestamp(), InitPostmasterChild(), IsExternalConnectionBackend, IsPostmasterEnvironment, IsUnderPostmaster, child_process_kind::main_fn, MemoryContextSwitchTo(), MyClientSocket, MyPMChildSlot, name, palloc(), 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{
191 return child_process_kinds[child_type].name;
192}

References child_process_kinds, 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.

Referenced by postmaster_child_launch(), and PostmasterChildName().