mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-02 14:01:18 +02:00
Add real random() call to postmaster for use in cancel.
This commit is contained in:
parent
b952a8491e
commit
556e603b25
@ -10,7 +10,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.80 1998/06/04 17:26:41 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.81 1998/06/08 04:27:59 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
*
|
*
|
||||||
@ -198,6 +198,12 @@ static sigset_t oldsigmask,
|
|||||||
static int orgsigmask = sigblock(0);
|
static int orgsigmask = sigblock(0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static unsigned int random_seed = 0;
|
||||||
|
|
||||||
|
extern char *optarg;
|
||||||
|
extern int optind,
|
||||||
|
opterr;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* postmaster.c - function prototypes
|
* postmaster.c - function prototypes
|
||||||
@ -216,6 +222,7 @@ static int ServerLoop(void);
|
|||||||
static int BackendStartup(Port *port);
|
static int BackendStartup(Port *port);
|
||||||
static void readStartupPacket(char *arg, PacketLen len, char *pkt);
|
static void readStartupPacket(char *arg, PacketLen len, char *pkt);
|
||||||
static int initMasks(fd_set *rmask, fd_set *wmask);
|
static int initMasks(fd_set *rmask, fd_set *wmask);
|
||||||
|
static long PostmasterRandom(void);
|
||||||
static void RandomSalt(char *salt);
|
static void RandomSalt(char *salt);
|
||||||
|
|
||||||
#ifdef CYR_RECODE
|
#ifdef CYR_RECODE
|
||||||
@ -223,11 +230,6 @@ void GetCharSetByHost(char *, int, char *);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char *optarg;
|
|
||||||
extern int optind,
|
|
||||||
opterr;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
checkDataDir(const char *DataDir, bool *DataDirOK)
|
checkDataDir(const char *DataDir, bool *DataDirOK)
|
||||||
@ -563,6 +565,10 @@ ServerLoop(void)
|
|||||||
writemask;
|
writemask;
|
||||||
int nSockets;
|
int nSockets;
|
||||||
Dlelem *curr;
|
Dlelem *curr;
|
||||||
|
struct timeval now, later;
|
||||||
|
struct timezone tz;
|
||||||
|
|
||||||
|
gettimeofday(&now, &tz);
|
||||||
|
|
||||||
nSockets = initMasks(&readmask, &writemask);
|
nSockets = initMasks(&readmask, &writemask);
|
||||||
|
|
||||||
@ -596,6 +602,19 @@ ServerLoop(void)
|
|||||||
return (STATUS_ERROR);
|
return (STATUS_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (random_seed == 0)
|
||||||
|
{
|
||||||
|
gettimeofday(&later, &tz);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We are not sure how much precision is in tv_usec, so we
|
||||||
|
* swap the nibbles of 'later' and XOR them with 'now'
|
||||||
|
*/
|
||||||
|
random_seed = now.tv_usec ^
|
||||||
|
((later.tv_usec << 16) |
|
||||||
|
((unsigned int)(later.tv_usec & 0xffff0000) >> 16));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* [TRH] To avoid race conditions, block SIGCHLD signals while we
|
* [TRH] To avoid race conditions, block SIGCHLD signals while we
|
||||||
* are handling the request. (both reaper() and ConnCreate()
|
* are handling the request. (both reaper() and ConnCreate()
|
||||||
@ -1345,19 +1364,28 @@ CharRemap(long int ch)
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
RandomSalt(char *salt)
|
RandomSalt(char *salt)
|
||||||
|
{
|
||||||
|
long rand = PostmasterRandom();
|
||||||
|
|
||||||
|
*salt = CharRemap(rand % 62);
|
||||||
|
*(salt + 1) = CharRemap(rand / 62);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PostmasterRandom
|
||||||
|
*/
|
||||||
|
static long
|
||||||
|
PostmasterRandom(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
time_t now;
|
Assert(random_seed != 0 && !IsUnderPostmaster);
|
||||||
|
srandom(random_seed);
|
||||||
now = time(NULL);
|
|
||||||
srandom((unsigned int) now);
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
*salt = CharRemap(random());
|
return ramdom() ^ random_seed;
|
||||||
*(salt + 1) = CharRemap(random());
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user