make-random-seed-more-random-1.patch
text/x-diff
Filename: make-random-seed-more-random-1.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/backend/postmaster/postmaster.c | 0 | 0 |
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index eedc617..2d5a0ac 100644
*** a/src/backend/postmaster/postmaster.c
--- b/src/backend/postmaster/postmaster.c
*************** ClosePostmasterPorts(bool am_syslogger)
*** 2520,2530 ****
/*
* 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);
--- 2520,2532 ----
/*
* InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds
*
! * Called early in the postmaster and every backend.
*/
void
InitProcessGlobals(void)
{
+ unsigned int rseed;
+
MyProcPid = getpid();
MyStartTimestamp = GetCurrentTimestamp();
MyStartTime = timestamptz_to_time_t(MyStartTimestamp);
*************** InitProcessGlobals(void)
*** 2539,2553 ****
#endif
/*
! * Set a different seed for random() in every backend. Since PIDs and
! * timestamps tend to change more frequently in their least significant
! * bits, shift the timestamp left to allow a larger total number of seeds
! * in a given time period. Since that would leave only 20 bits of the
! * timestamp that cycle every ~1 second, also mix in some higher bits.
*/
! srandom(((uint64) MyProcPid) ^
((uint64) MyStartTimestamp << 12) ^
! ((uint64) MyStartTimestamp >> 20));
}
--- 2541,2570 ----
#endif
/*
! * Set a different seed for random() in every process. We want something
! * unpredictable, so if possible, use high-quality random bits for the
! * seed. Otherwise, fall back to a seed based on timestamp and PID.
! *
! * Note we can't use pg_backend_random here, since this is used in the
! * postmaster, and even in a backend we might not be attached to shared
! * memory yet.
*/
! #ifdef HAVE_STRONG_RANDOM
! if (!pg_strong_random(&rseed, sizeof(rseed)))
! #endif
! {
! /*
! * Since PIDs and timestamps tend to change more frequently in their
! * least significant bits, shift the timestamp left to allow a larger
! * total number of seeds in a given time period. Since that would
! * leave only 20 bits of the timestamp that cycle every ~1 second,
! * also mix in some higher bits.
! */
! rseed = ((uint64) MyProcPid) ^
((uint64) MyStartTimestamp << 12) ^
! ((uint64) MyStartTimestamp >> 20);
! }
! srandom(rseed);
}