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, 29 insertions, 31 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 41de140ae01..688f462e7d0 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -129,6 +129,7 @@
#include "utils/pidfile.h"
#include "utils/ps_status.h"
#include "utils/timeout.h"
+#include "utils/timestamp.h"
#include "utils/varlena.h"
#ifdef EXEC_BACKEND
@@ -581,9 +582,9 @@ PostmasterMain(int argc, char *argv[])
int i;
char *output_config_variable = NULL;
- MyProcPid = PostmasterPid = getpid();
+ InitProcessGlobals();
- MyStartTime = time(NULL);
+ PostmasterPid = MyProcPid;
IsPostmasterEnvironment = true;
@@ -598,16 +599,6 @@ PostmasterMain(int argc, char *argv[])
umask(PG_MODE_MASK_OWNER);
/*
- * Initialize random(3) so we don't get the same values in every run.
- *
- * Note: the seed is pretty predictable from externally-visible facts such
- * as postmaster start time, so avoid using random() for security-critical
- * random values during postmaster startup. At the time of first
- * connection, PostmasterRandom will select a hopefully-more-random seed.
- */
- srandom((unsigned int) (MyProcPid ^ MyStartTime));
-
- /*
* By default, palloc() requests in the postmaster will be allocated in
* the PostmasterContext, which is space that can be recycled by backends.
* Allocated data that needs to be available to backends should be
@@ -2514,6 +2505,32 @@ ClosePostmasterPorts(bool am_syslogger)
/*
+ * InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds
+ *
+ * Called early in every backend.
+ */
+void
+InitProcessGlobals(void)
+{
+ MyProcPid = getpid();
+ MyStartTimestamp = GetCurrentTimestamp();
+ MyStartTime = timestamptz_to_time_t(MyStartTimestamp);
+
+ /*
+ * Don't want backend to be able to see the postmaster random number
+ * generator state. We have to clobber the static random_seed.
+ */
+#ifndef HAVE_STRONG_RANDOM
+ random_seed = 0;
+ random_start_time.tv_usec = 0;
+#endif
+
+ /* Set a different seed for random() in every backend. */
+ srandom((unsigned int) MyProcPid ^ (unsigned int) MyStartTimestamp);
+}
+
+
+/*
* reset_shared -- reset shared memory and semaphores
*/
static void
@@ -4154,10 +4171,6 @@ BackendInitialize(Port *port)
/* This flag will remain set until InitPostgres finishes authentication */
ClientAuthInProgress = true; /* limit visibility of log messages */
- /* save process start time */
- port->SessionStartTime = GetCurrentTimestamp();
- MyStartTime = timestamptz_to_time_t(port->SessionStartTime);
-
/* set these to empty in case they are needed before we set them up */
port->remote_host = "";
port->remote_port = "";
@@ -4315,24 +4328,9 @@ BackendRun(Port *port)
char **av;
int maxac;
int ac;
- long secs;
- int usecs;
int i;
/*
- * Don't want backend to be able to see the postmaster random number
- * generator state. We have to clobber the static random_seed *and* start
- * a new random sequence in the random() library function.
- */
-#ifndef HAVE_STRONG_RANDOM
- random_seed = 0;
- random_start_time.tv_usec = 0;
-#endif
- /* slightly hacky way to convert timestamptz into integers */
- TimestampDifference(0, port->SessionStartTime, &secs, &usecs);
- srandom((unsigned int) (MyProcPid ^ (usecs << 12) ^ secs));
-
- /*
* Now, build the argv vector that will be given to PostgresMain.
*
* The maximum possible number of commandline arguments that could come