diff options
-rw-r--r-- | src/backend/utils/init/miscinit.c | 8 | ||||
-rw-r--r-- | src/bin/initdb/initdb.c | 3 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 6d7eeb870e7..515d07417a6 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -222,6 +222,14 @@ InitStandaloneProcess(const char *argv0) MyStartTime = time(NULL); /* set our start time in case we call elog */ + /* + * Initialize random() for the first time, like PostmasterMain() would. + * In a regular IsUnderPostmaster backend, BackendRun() computes a + * high-entropy seed before any user query. Fewer distinct initial seeds + * can occur here. + */ + srandom((unsigned int) (MyProcPid ^ MyStartTime)); + /* Initialize process-local latch support */ InitializeLatchSupport(); MyLatch = &LocalLatchData; diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 118edf94559..89a6b0da09b 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -1047,6 +1047,9 @@ choose_dsm_implementation(void) #ifdef HAVE_SHM_OPEN int ntries = 10; + /* Initialize random(); this function is its only user in this program. */ + srandom((unsigned int) (getpid() ^ time(NULL))); + while (ntries > 0) { uint32 handle; |