mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
better randoms on OS X
This commit is contained in:
parent
644af22b4d
commit
f7dcfc6a2c
@ -318,7 +318,7 @@ namespace mongo {
|
||||
repairDatabases();
|
||||
|
||||
/* this is for security on certain platforms */
|
||||
srand(curTimeMillis() ^ startupSrandTimer.micros());
|
||||
srand(curTimeMicros() ^ startupSrandTimer.micros());
|
||||
|
||||
listen(listenPort);
|
||||
}
|
||||
@ -334,7 +334,7 @@ using namespace mongo;
|
||||
|
||||
int main(int argc, char* argv[], char *envp[] )
|
||||
{
|
||||
srand(curTimeMillis());
|
||||
srand(curTimeMicros());
|
||||
boost::filesystem::path::default_name_check( boost::filesystem::no_check );
|
||||
|
||||
{
|
||||
|
@ -14,6 +14,10 @@ namespace mongo {
|
||||
#if defined(__linux__)
|
||||
devrandom = new ifstream("/dev/urandom", ios::binary|ios::in);
|
||||
massert( "can't open dev/urandom", devrandom->is_open() );
|
||||
#elif defined(_WIN32)
|
||||
srand(curTimeMicros());
|
||||
#else
|
||||
srandomdev();
|
||||
#endif
|
||||
assert( sizeof(nonce) == 8 );
|
||||
|
||||
@ -26,8 +30,10 @@ namespace mongo {
|
||||
#if defined(__linux__)
|
||||
devrandom->read((char*)&n, sizeof(n));
|
||||
massert("devrandom failed", !devrandom->fail());
|
||||
#else
|
||||
#elif defined(_WIN32)
|
||||
n = ((unsigned long long)rand())<<32 | rand();
|
||||
#else
|
||||
n = random();
|
||||
#endif
|
||||
return n;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user