summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/nonce.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/db/nonce.cpp b/db/nonce.cpp
index 5698f73af61..6f35c7996fd 100644
--- a/db/nonce.cpp
+++ b/db/nonce.cpp
@@ -35,7 +35,7 @@ namespace mongo {
if( _initialized ) return;
_initialized = true;
-#if defined(__linux__) || defined(__sunos__)
+#if defined(__linux__) || defined(__sunos__) || defined(__APPLE__)
_devrandom = new ifstream("/dev/urandom", ios::binary|ios::in);
massert( 10353 , "can't open dev/urandom", _devrandom->is_open() );
#elif defined(_WIN32)
@@ -53,13 +53,16 @@ namespace mongo {
nonce Security::getNonce() {
static mongo::mutex m("getNonce");
scoped_lock lk(m);
+
+ if ( ! _initialized )
+ init();
/* question/todo: /dev/random works on OS X. is it better
to use that than random() / srandom()?
*/
nonce n;
-#if defined(__linux__) || defined(__sunos__)
+#if defined(__linux__) || defined(__sunos__) || defined(__APPLE__)
_devrandom->read((char*)&n, sizeof(n));
massert( 10355 , "devrandom failed", !_devrandom->fail());
#elif defined(_WIN32)