PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
 

Functions

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

Variables

static child_process_kind child_process_kinds []
 

Function Documentation

◆ postmaster_child_launch()

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

Definition at line 227 of file launch_backend.c.

230{
231 pid_t pid;
232
234
235#ifdef EXEC_BACKEND
236 pid = internal_forkexec(child_process_kinds[child_type].name, child_slot,
237 startup_data, startup_data_len, client_sock);
238 /* the child process will arrive in SubPostmasterMain */
239#else /* !EXEC_BACKEND */
240 pid = fork_process();
241 if (pid == 0) /* child */
242 {
243 /* Close the postmaster's sockets */
244 ClosePostmasterPorts(child_type == B_LOGGER);
245
246 /* Detangle from postmaster */
248
249 /* Detach shared memory if not needed. */
250 if (!child_process_kinds[child_type].shmem_attach)
251 {
254 }
255
256 /*
257 * Enter the Main function with TopMemoryContext. The startup data is
258 * allocated in PostmasterContext, so we cannot release it here yet.
259 * The Main function will do it after it's done handling the startup
260 * data.
261 */
263
264 MyPMChildSlot = child_slot;
265 if (client_sock)
266 {
268 memcpy(MyClientSocket, client_sock, sizeof(ClientSocket));
269 }
270
271 /*
272 * Run the appropriate Main function
273 */
274 child_process_kinds[child_type].main_fn(startup_data, startup_data_len);
275 pg_unreachable(); /* main_fn never returns */
276 }
277#endif /* EXEC_BACKEND */
278 return pid;
279}
#define Assert(condition)
Definition: c.h:812
#define pg_unreachable()
Definition: c.h:315
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:49
int MyPMChildSlot
Definition: globals.c:53
bool IsUnderPostmaster
Definition: globals.c:119
bool IsPostmasterEnvironment
Definition: globals.c:118
static child_process_kind child_process_kinds[]
MemoryContext TopMemoryContext
Definition: mcxt.c:149
void * palloc(Size size)
Definition: mcxt.c:1317
@ B_LOGGER
Definition: miscadmin.h:372
void InitPostmasterChild(void)
Definition: miscinit.c:96
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:1827
void(* main_fn)(char *startup_data, size_t startup_data_len) pg_attribute_noreturn()
void PGSharedMemoryDetach(void)
Definition: sysv_shmem.c:970
const char * name

References Assert, B_LOGGER, child_process_kinds, ClosePostmasterPorts(), dsm_detach_all(), fork_process(), InitPostmasterChild(), IsPostmasterEnvironment, IsUnderPostmaster, child_process_kind::main_fn, MemoryContextSwitchTo(), MyClientSocket, MyPMChildSlot, name, palloc(), pg_unreachable, PGSharedMemoryDetach(), and TopMemoryContext.

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

◆ PostmasterChildName()

const char * PostmasterChildName ( BackendType  child_type)

Definition at line 209 of file launch_backend.c.

210{
211 return child_process_kinds[child_type].name;
212}

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:
= {
[B_INVALID] = {"invalid", NULL, false},
[B_BACKEND] = {"backend", BackendMain, true},
[B_DEAD_END_BACKEND] = {"dead-end backend", BackendMain, true},
[B_AUTOVAC_LAUNCHER] = {"autovacuum launcher", AutoVacLauncherMain, true},
[B_AUTOVAC_WORKER] = {"autovacuum worker", AutoVacWorkerMain, true},
[B_BG_WORKER] = {"bgworker", BackgroundWorkerMain, true},
[B_WAL_SENDER] = {"wal sender", NULL, true},
[B_SLOTSYNC_WORKER] = {"slot sync worker", ReplSlotSyncWorkerMain, true},
[B_STANDALONE_BACKEND] = {"standalone backend", NULL, false},
[B_ARCHIVER] = {"archiver", PgArchiverMain, true},
[B_BG_WRITER] = {"bgwriter", BackgroundWriterMain, true},
[B_CHECKPOINTER] = {"checkpointer", CheckpointerMain, true},
[B_STARTUP] = {"startup", StartupProcessMain, true},
[B_WAL_RECEIVER] = {"wal_receiver", WalReceiverMain, true},
[B_WAL_SUMMARIZER] = {"wal_summarizer", WalSummarizerMain, true},
[B_WAL_WRITER] = {"wal_writer", WalWriterMain, true},
[B_LOGGER] = {"syslogger", SysLoggerMain, false},
}
void AutoVacWorkerMain(char *startup_data, size_t startup_data_len)
Definition: autovacuum.c:1373
void AutoVacLauncherMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn()
void StartupProcessMain(char *startup_data, size_t startup_data_len)
Definition: startup.c:216
void BackendMain(char *startup_data, size_t startup_data_len)
void BackgroundWorkerMain(char *startup_data, size_t startup_data_len)
Definition: bgworker.c:717
void BackgroundWriterMain(char *startup_data, size_t startup_data_len)
Definition: bgwriter.c:87
void CheckpointerMain(char *startup_data, size_t startup_data_len)
Definition: checkpointer.c:173
@ B_WAL_SUMMARIZER
Definition: miscadmin.h:365
@ B_WAL_WRITER
Definition: miscadmin.h:366
@ B_WAL_RECEIVER
Definition: miscadmin.h:364
@ B_CHECKPOINTER
Definition: miscadmin.h:362
@ B_WAL_SENDER
Definition: miscadmin.h:346
@ B_STARTUP
Definition: miscadmin.h:363
@ B_BG_WORKER
Definition: miscadmin.h:345
@ B_INVALID
Definition: miscadmin.h:338
@ B_STANDALONE_BACKEND
Definition: miscadmin.h:349
@ B_BG_WRITER
Definition: miscadmin.h:361
@ B_BACKEND
Definition: miscadmin.h:341
@ B_ARCHIVER
Definition: miscadmin.h:360
@ B_AUTOVAC_LAUNCHER
Definition: miscadmin.h:343
@ B_SLOTSYNC_WORKER
Definition: miscadmin.h:347
@ B_DEAD_END_BACKEND
Definition: miscadmin.h:342
@ B_AUTOVAC_WORKER
Definition: miscadmin.h:344
void PgArchiverMain(char *startup_data, size_t startup_data_len)
Definition: pgarch.c:215
void ReplSlotSyncWorkerMain(char *startup_data, size_t startup_data_len)
Definition: slotsync.c:1329
void SysLoggerMain(char *startup_data, size_t startup_data_len)
Definition: syslogger.c:165
void WalReceiverMain(char *startup_data, size_t startup_data_len)
Definition: walreceiver.c:183
void WalSummarizerMain(char *startup_data, size_t startup_data_len)
void WalWriterMain(char *startup_data, size_t startup_data_len)
Definition: walwriter.c:87

Definition at line 178 of file launch_backend.c.

Referenced by postmaster_child_launch(), and PostmasterChildName().