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

Function StartChildProcess

src/backend/postmaster/postmaster.c:6069–6165  ·  view source on GitHub ↗

* StartChildProcess -- start an auxiliary process for the postmaster * * "type" determines what kind of child will be started. All child types * initially go to AuxiliaryProcessMain, which will handle common setup. * * Return value of StartChildProcess is subprocess' PID, or 0 if failed * to start subprocess. */

Source from the content-addressed store, hash-verified

6067 * to start subprocess.
6068 */
6069static pid_t
6070StartChildProcess(AuxProcType type)
6071{
6072 pid_t pid;
6073 char *av[10];
6074 int ac = 0;
6075 char typebuf[32];
6076
6077 /*
6078 * Set up command-line arguments for subprocess
6079 */
6080 av[ac++] = "postgres";
6081
6082#ifdef EXEC_BACKEND
6083 av[ac++] = "--forkboot";
6084 av[ac++] = NULL; /* filled in by postmaster_forkexec */
6085#endif
6086
6087 snprintf(typebuf, sizeof(typebuf), "-x%d", type);
6088 av[ac++] = typebuf;
6089
6090 av[ac] = NULL;
6091 Assert(ac < lengthof(av));
6092
6093#ifdef EXEC_BACKEND
6094 pid = postmaster_forkexec(ac, av);
6095#else /* !EXEC_BACKEND */
6096 pid = fork_process();
6097
6098 if (pid == 0) /* child */
6099 {
6100 InitPostmasterChild();
6101
6102 /* Close the postmaster's sockets */
6103 ClosePostmasterPorts(false);
6104
6105 /* Release postmaster's working memory context */
6106 MemoryContextSwitchTo(TopMemoryContext);
6107 MemoryContextDelete(PostmasterContext);
6108 PostmasterContext = NULL;
6109
6110 AuxiliaryProcessMain(ac, av); /* does not return */
6111 }
6112#endif /* EXEC_BACKEND */
6113
6114 if (pid < 0)
6115 {
6116 /* in parent, fork failed */
6117 int save_errno = errno;
6118
6119 errno = save_errno;
6120 switch (type)
6121 {
6122 case StartupProcess:
6123 ereport(LOG,
6124 (errmsg("could not fork startup process: %m")));
6125 break;
6126 case ArchiverProcess:

Callers

nothing calls this directly

Calls 8

postmaster_forkexecFunction · 0.85
fork_processFunction · 0.85
InitPostmasterChildFunction · 0.85
ClosePostmasterPortsFunction · 0.85
MemoryContextSwitchToFunction · 0.85
AuxiliaryProcessMainFunction · 0.85
ExitPostmasterFunction · 0.85
errmsgFunction · 0.50

Tested by

no test coverage detected