summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-02-22 11:01:18 -0500
committerEliot Horowitz <eliot@10gen.com>2011-02-22 11:29:49 -0500
commit109c7101f5e36b9c0c4e2d13e5692beda504f22a (patch)
tree3600f71270cfa04a3ef2df17c702b0b94a21da7f
parentb138f371920a426137d0f964be6761d6523dba8b (diff)
downloadmongo-109c7101f5e36b9c0c4e2d13e5692beda504f22a.tar.gz
correct nonce on os x
-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)