Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit89f2b64

Browse files
committed
Initialize random() in bootstrap/stand-alone postgres and in initdb.
This removes a difference between the standard IsUnderPostmasterexecution environment and that of --boot and --single. In a stand-alonebackend, "SELECT random()" always started at the same seed.On a system capable of using posix shared memory, initdb could stillconclude "selecting dynamic shared memory implementation ... sysv".Crashed --boot or --single postgres processes orphaned shared memoryobjects having names that collided with the not-actually-random namesthat initdb probed. The sysv fallback appeared after ten crashes of--boot or --single postgres. Since --boot and --single are rare inproduction use, systems used for PostgreSQL development are theprincipal candidate to notice this symptom.Back-patch to 9.3 (all supported versions). PostgreSQL 9.4 introduceddynamic shared memory, but 9.3 does share the "SELECT random()" problem.Reviewed by Tom Lane and Kyotaro HORIGUCHI.Discussion:https://postgr.es/m/20180915221546.GA3159382@rfd.leadboat.com
1 parentb1356f1 commit89f2b64

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

‎src/backend/utils/init/miscinit.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ InitStandaloneProcess(const char *argv0)
320320

321321
MyStartTime=time(NULL);/* set our start time in case we call elog */
322322

323+
/*
324+
* Initialize random() for the first time, like PostmasterMain() would.
325+
* In a regular IsUnderPostmaster backend, BackendRun() computes a
326+
* high-entropy seed before any user query. Fewer distinct initial seeds
327+
* can occur here.
328+
*/
329+
srandom((unsignedint) (MyProcPid ^MyStartTime));
330+
323331
/* Initialize process-local latch support */
324332
InitializeLatchSupport();
325333
MyLatch=&LocalLatchData;

‎src/bin/initdb/initdb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,9 @@ choose_dsm_implementation(void)
922922
#ifdefHAVE_SHM_OPEN
923923
intntries=10;
924924

925+
/* Initialize random(); this function is its only user in this program. */
926+
srandom((unsignedint) (getpid() ^time(NULL)));
927+
925928
while (ntries>0)
926929
{
927930
uint32handle;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp