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

Commit556e603

Browse files
committed
Add real random() call to postmaster for use in cancel.
1 parentb952a84 commit556e603

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.80 1998/06/04 17:26:41 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.81 1998/06/08 04:27:59 momjian Exp $
1414
*
1515
* NOTES
1616
*
@@ -198,6 +198,12 @@ staticsigset_toldsigmask,
198198
staticintorgsigmask=sigblock(0);
199199
#endif
200200

201+
staticunsignedintrandom_seed=0;
202+
203+
externchar*optarg;
204+
externintoptind,
205+
opterr;
206+
201207

202208
/*
203209
* postmaster.c - function prototypes
@@ -216,18 +222,14 @@ static int ServerLoop(void);
216222
staticintBackendStartup(Port*port);
217223
staticvoidreadStartupPacket(char*arg,PacketLenlen,char*pkt);
218224
staticintinitMasks(fd_set*rmask,fd_set*wmask);
225+
staticlongPostmasterRandom(void);
219226
staticvoidRandomSalt(char*salt);
220227

221228
#ifdefCYR_RECODE
222-
voidGetCharSetByHost(char*,int,char*);
229+
voidGetCharSetByHost(char*,int,char*);
223230

224231
#endif
225232

226-
externchar*optarg;
227-
externintoptind,
228-
opterr;
229-
230-
231233

232234
staticvoid
233235
checkDataDir(constchar*DataDir,bool*DataDirOK)
@@ -563,6 +565,10 @@ ServerLoop(void)
563565
writemask;
564566
intnSockets;
565567
Dlelem*curr;
568+
structtimevalnow,later;
569+
structtimezonetz;
570+
571+
gettimeofday(&now,&tz);
566572

567573
nSockets=initMasks(&readmask,&writemask);
568574

@@ -596,6 +602,19 @@ ServerLoop(void)
596602
return (STATUS_ERROR);
597603
}
598604

605+
if (random_seed==0)
606+
{
607+
gettimeofday(&later,&tz);
608+
609+
/*
610+
*We are not sure how much precision is in tv_usec, so we
611+
*swap the nibbles of 'later' and XOR them with 'now'
612+
*/
613+
random_seed=now.tv_usec ^
614+
((later.tv_usec <<16) |
615+
((unsignedint)(later.tv_usec&0xffff0000) >>16));
616+
}
617+
599618
/*
600619
* [TRH] To avoid race conditions, block SIGCHLD signals while we
601620
* are handling the request. (both reaper() and ConnCreate()
@@ -1345,19 +1364,28 @@ CharRemap(long int ch)
13451364
*/
13461365
staticvoid
13471366
RandomSalt(char*salt)
1367+
{
1368+
longrand=PostmasterRandom();
1369+
1370+
*salt=CharRemap(rand %62);
1371+
*(salt+1)=CharRemap(rand /62);
1372+
}
1373+
1374+
/*
1375+
* PostmasterRandom
1376+
*/
1377+
staticlong
1378+
PostmasterRandom(void)
13481379
{
13491380

13501381
staticboolinitialized= false;
13511382

13521383
if (!initialized)
13531384
{
1354-
time_tnow;
1355-
1356-
now=time(NULL);
1357-
srandom((unsignedint)now);
1385+
Assert(random_seed!=0&& !IsUnderPostmaster);
1386+
srandom(random_seed);
13581387
initialized= true;
13591388
}
13601389

1361-
*salt=CharRemap(random());
1362-
*(salt+1)=CharRemap(random());
1390+
returnramdom() ^random_seed;
13631391
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp