aboutsummaryrefslogtreecommitdiff
path: root/src/backend/postmaster/postmaster.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/postmaster/postmaster.c')
-rw-r--r--src/backend/postmaster/postmaster.c60
1 files changed, 10 insertions, 50 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 8570e75d8a6..fe6316ecbe9 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -3811,19 +3811,8 @@ BackendStartup(Port *port)
{
free(bn);
- /*
- * Let's clean up ourselves as the postmaster child, and close the
- * postmaster's listen sockets. (In EXEC_BACKEND case this is all
- * done in SubPostmasterMain.)
- */
- IsUnderPostmaster = true; /* we are a postmaster subprocess now */
-
- MyProcPid = getpid(); /* reset MyProcPid */
-
- MyStartTime = time(NULL);
-
- /* We don't want the postmaster's proc_exit() handlers */
- on_exit_reset();
+ /* Detangle from postmaster */
+ InitPostmasterChild();
/* Close the postmaster's sockets */
ClosePostmasterPorts(false);
@@ -3954,16 +3943,6 @@ BackendInitialize(Port *port)
whereToSendOutput = DestRemote; /* now safe to ereport to client */
/*
- * If possible, make this process a group leader, so that the postmaster
- * can signal any child processes too. (We do this now on the off chance
- * that something might spawn a child process during authentication.)
- */
-#ifdef HAVE_SETSID
- if (setsid() < 0)
- elog(FATAL, "setsid() failed: %m");
-#endif
-
- /*
* We arrange for a simple exit(1) if we receive SIGTERM or SIGQUIT or
* timeout while trying to collect the startup packet. Otherwise the
* postmaster cannot shutdown the database FAST or IMMED cleanly if a
@@ -4515,30 +4494,13 @@ SubPostmasterMain(int argc, char *argv[])
{
Port port;
- /* Do this sooner rather than later... */
- IsUnderPostmaster = true; /* we are a postmaster subprocess now */
-
- MyProcPid = getpid(); /* reset MyProcPid */
-
- MyStartTime = time(NULL);
-
- /*
- * make sure stderr is in binary mode before anything can possibly be
- * written to it, in case it's actually the syslogger pipe, so the pipe
- * chunking protocol isn't disturbed. Non-logpipe data gets translated on
- * redirection (e.g. via pg_ctl -l) anyway.
- */
-#ifdef WIN32
- _setmode(fileno(stderr), _O_BINARY);
-#endif
-
- /* Lose the postmaster's on-exit routines (really a no-op) */
- on_exit_reset();
-
/* In EXEC_BACKEND case we will not have inherited these settings */
IsPostmasterEnvironment = true;
whereToSendOutput = DestNone;
+ /* Setup as postmaster child */
+ InitPostmasterChild();
+
/* Setup essential subsystems (to ensure elog() behaves sanely) */
InitializeGUCOptions();
@@ -4718,6 +4680,8 @@ SubPostmasterMain(int argc, char *argv[])
/* do this as early as possible; in particular, before InitProcess() */
IsBackgroundWorker = true;
+ InitPostmasterChild();
+
/* Close the postmaster's sockets */
ClosePostmasterPorts(false);
@@ -5138,14 +5102,11 @@ StartChildProcess(AuxProcType type)
if (pid == 0) /* child */
{
- IsUnderPostmaster = true; /* we are a postmaster subprocess now */
+ InitPostmasterChild();
/* Close the postmaster's sockets */
ClosePostmasterPorts(false);
- /* Lose the postmaster's on-exit routines and port connections */
- on_exit_reset();
-
/* Release postmaster's working memory context */
MemoryContextSwitchTo(TopMemoryContext);
MemoryContextDelete(PostmasterContext);
@@ -5424,12 +5385,11 @@ do_start_bgworker(RegisteredBgWorker *rw)
#ifndef EXEC_BACKEND
case 0:
/* in postmaster child ... */
+ InitPostmasterChild();
+
/* Close the postmaster's sockets */
ClosePostmasterPorts(false);
- /* Lose the postmaster's on-exit routines */
- on_exit_reset();
-
/* Do NOT release postmaster's working memory context */
MyBgworkerEntry = &rw->rw_worker;