diff options
Diffstat (limited to 'src/backend/postmaster')
-rw-r--r-- | src/backend/postmaster/autovacuum.c | 49 | ||||
-rw-r--r-- | src/backend/postmaster/bgworker.c | 18 | ||||
-rw-r--r-- | src/backend/postmaster/bgwriter.c | 12 | ||||
-rw-r--r-- | src/backend/postmaster/checkpointer.c | 11 | ||||
-rw-r--r-- | src/backend/postmaster/pgarch.c | 20 | ||||
-rw-r--r-- | src/backend/postmaster/pgstat.c | 22 | ||||
-rw-r--r-- | src/backend/postmaster/postmaster.c | 60 | ||||
-rw-r--r-- | src/backend/postmaster/startup.c | 9 | ||||
-rw-r--r-- | src/backend/postmaster/syslogger.c | 22 | ||||
-rw-r--r-- | src/backend/postmaster/walwriter.c | 13 |
10 files changed, 21 insertions, 215 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 062b1209051..a26eee25d46 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -64,7 +64,6 @@ #include <signal.h> #include <sys/types.h> #include <sys/time.h> -#include <time.h> #include <unistd.h> #include "access/heapam.h" @@ -383,12 +382,11 @@ StartAutoVacLauncher(void) #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(); - AutoVacLauncherMain(0, NULL); break; #endif @@ -408,16 +406,8 @@ AutoVacLauncherMain(int argc, char *argv[]) { sigjmp_buf local_sigjmp_buf; - /* we are a postmaster subprocess now */ - IsUnderPostmaster = true; am_autovacuum_launcher = true; - /* reset MyProcPid */ - MyProcPid = getpid(); - - /* record Start Time for logging */ - MyStartTime = time(NULL); - /* Identify myself via ps */ init_ps_display("autovacuum launcher process", "", "", ""); @@ -430,17 +420,6 @@ AutoVacLauncherMain(int argc, char *argv[]) SetProcessingMode(InitProcessing); /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. (autovacuum probably never has any - * child processes, but for consistency we make all postmaster child - * processes do this.) - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - - /* * Set up signal handlers. We operate on databases much like a regular * backend, so we use the same signal handling. See equivalent code in * tcop/postgres.c. @@ -1455,12 +1434,11 @@ StartAutoVacWorker(void) #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(); - AutoVacWorkerMain(0, NULL); break; #endif @@ -1481,33 +1459,14 @@ AutoVacWorkerMain(int argc, char *argv[]) sigjmp_buf local_sigjmp_buf; Oid dbid; - /* we are a postmaster subprocess now */ - IsUnderPostmaster = true; am_autovacuum_worker = true; - /* reset MyProcPid */ - MyProcPid = getpid(); - - /* record Start Time for logging */ - MyStartTime = time(NULL); - /* Identify myself via ps */ init_ps_display("autovacuum worker process", "", "", ""); SetProcessingMode(InitProcessing); /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. (autovacuum probably never has any - * child processes, but for consistency we make all postmaster child - * processes do this.) - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - - /* * Set up signal handlers. We operate on databases much like a regular * backend, so we use the same signal handling. See equivalent code in * tcop/postgres.c. diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index 8a7637baec9..6673f5ba622 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -13,7 +13,6 @@ #include "postgres.h" #include <unistd.h> -#include <time.h> #include "miscadmin.h" #include "libpq/pqsignal.h" @@ -556,16 +555,8 @@ StartBackgroundWorker(void) if (worker == NULL) elog(FATAL, "unable to find bgworker entry"); - /* we are a postmaster subprocess now */ - IsUnderPostmaster = true; IsBackgroundWorker = true; - /* reset MyProcPid */ - MyProcPid = getpid(); - - /* record Start Time for logging */ - MyStartTime = time(NULL); - /* Identify myself via ps */ snprintf(buf, MAXPGPATH, "bgworker: %s", worker->bgw_name); init_ps_display(buf, "", "", ""); @@ -591,15 +582,6 @@ StartBackgroundWorker(void) pg_usleep(PostAuthDelay * 1000000L); /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - - /* * Set up signal handlers. */ if (worker->bgw_flags & BGWORKER_BACKEND_DATABASE_CONNECTION) diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index 872c23110ae..f138eb7473b 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -36,7 +36,6 @@ #include <signal.h> #include <sys/time.h> -#include <time.h> #include <unistd.h> #include "access/xlog.h" @@ -114,17 +113,6 @@ BackgroundWriterMain(void) bool prev_hibernate; /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. (bgwriter probably never has any - * child processes, but for consistency we make all postmaster child - * processes do this.) - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - - /* * Properly accept or ignore signals the postmaster might send us. * * bgwriter doesn't participate in ProcSignal signalling, but a SIGUSR1 diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 4d1ba40ec88..3c9c216c6f1 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -197,17 +197,6 @@ CheckpointerMain(void) CheckpointerShmem->checkpointer_pid = MyProcPid; /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. (checkpointer probably never has - * any child processes, but for consistency we make all postmaster child - * processes do this.) - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - - /* * Properly accept or ignore signals the postmaster might send us * * Note: we deliberately ignore SIGTERM, because during a standard Unix diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index 75e7e1b2903..78dec3a4c6f 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -157,12 +157,11 @@ pgarch_start(void) #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(); - /* Drop our connection to postmaster's shared memory, as well */ dsm_detach_all(); PGSharedMemoryDetach(); @@ -221,21 +220,6 @@ pgarch_forkexec(void) NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) { - IsUnderPostmaster = true; /* we are a postmaster subprocess now */ - - MyProcPid = getpid(); /* reset MyProcPid */ - - MyStartTime = time(NULL); /* record Start Time for logging */ - - /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - InitializeLatchSupport(); /* needed for latch waits */ InitLatch(&mainloop_latch); /* initialize latch used in main loop */ diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index ea3bd4b3e88..fa87660baee 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -695,12 +695,11 @@ pgstat_start(void) #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(); - /* Drop our connection to postmaster's shared memory, as well */ dsm_detach_all(); PGSharedMemoryDetach(); @@ -3152,23 +3151,6 @@ PgstatCollectorMain(int argc, char *argv[]) PgStat_Msg msg; int wr; - IsUnderPostmaster = true; /* we are a postmaster subprocess now */ - - MyProcPid = getpid(); /* reset MyProcPid */ - - MyStartTime = time(NULL); /* record Start Time for logging */ - - /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. (pgstat probably never has any - * child processes, but for consistency we make all postmaster child - * processes do this.) - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - InitializeLatchSupport(); /* needed for latch waits */ /* Initialize private latch for use by signal handlers */ 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; diff --git a/src/backend/postmaster/startup.c b/src/backend/postmaster/startup.c index 72501e07f31..581837a1567 100644 --- a/src/backend/postmaster/startup.c +++ b/src/backend/postmaster/startup.c @@ -178,15 +178,6 @@ void StartupProcessMain(void) { /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - - /* * Properly accept or ignore signals the postmaster might send us. */ pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */ diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index c1b64ac7513..d127fb57711 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -164,11 +164,6 @@ SysLoggerMain(int argc, char *argv[]) int currentLogRotationAge; pg_time_t now; - IsUnderPostmaster = true; /* we are a postmaster subprocess now */ - - MyProcPid = getpid(); /* reset MyProcPid */ - - MyStartTime = time(NULL); /* set our start time in case we call elog */ now = MyStartTime; #ifdef EXEC_BACKEND @@ -236,18 +231,8 @@ SysLoggerMain(int argc, char *argv[]) syslogPipe[1] = 0; #endif - /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. (syslogger probably never has any - * child processes, but for consistency we make all postmaster child - * processes do this.) - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif + InitializeLatchSupport(); /* needed for latch waits */ - InitializeLatchSupport(); /* needed for latch waits */ /* Initialize private latch for use by signal handlers */ InitLatch(&sysLoggerLatch); @@ -609,12 +594,11 @@ SysLogger_Start(void) #ifndef EXEC_BACKEND case 0: /* in postmaster child ... */ + InitPostmasterChild(); + /* Close the postmaster's sockets */ ClosePostmasterPorts(true); - /* Lose the postmaster's on-exit routines */ - on_exit_reset(); - /* Drop our connection to postmaster's shared memory, as well */ dsm_detach_all(); PGSharedMemoryDetach(); diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c index 2101b45c1a3..044c30665e7 100644 --- a/src/backend/postmaster/walwriter.c +++ b/src/backend/postmaster/walwriter.c @@ -42,8 +42,6 @@ #include "postgres.h" #include <signal.h> -#include <sys/time.h> -#include <time.h> #include <unistd.h> #include "access/xlog.h" @@ -102,17 +100,6 @@ WalWriterMain(void) bool hibernating; /* - * If possible, make this process a group leader, so that the postmaster - * can signal any child processes too. (walwriter probably never has any - * child processes, but for consistency we make all postmaster child - * processes do this.) - */ -#ifdef HAVE_SETSID - if (setsid() < 0) - elog(FATAL, "setsid() failed: %m"); -#endif - - /* * Properly accept or ignore signals the postmaster might send us * * We have no particular use for SIGINT at the moment, but seems |