summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/linearstore/journal/JournalFile.cpp
diff options
context:
space:
mode:
authorKim van der Riet <kpvdr@apache.org>2014-01-16 20:46:24 +0000
committerKim van der Riet <kpvdr@apache.org>2014-01-16 20:46:24 +0000
commite4e01cd48489a57a1c7e4dd4b5223d24067d4086 (patch)
tree1b3492f3fbe1d995db516bf4b9fc4e846598c32d /cpp/src/qpid/linearstore/journal/JournalFile.cpp
parent910556efefca56752ac0ba692d0a2ecc6847158d (diff)
downloadqpid-python-e4e01cd48489a57a1c7e4dd4b5223d24067d4086.tar.gz
QPID-5487: [linearstore] Replace use of /dev/urandom with c random generator calls
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1558913 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/linearstore/journal/JournalFile.cpp')
-rw-r--r--cpp/src/qpid/linearstore/journal/JournalFile.cpp14
1 files changed, 2 insertions, 12 deletions
diff --git a/cpp/src/qpid/linearstore/journal/JournalFile.cpp b/cpp/src/qpid/linearstore/journal/JournalFile.cpp
index 129a9145d0..1b2025bd5a 100644
--- a/cpp/src/qpid/linearstore/journal/JournalFile.cpp
+++ b/cpp/src/qpid/linearstore/journal/JournalFile.cpp
@@ -279,18 +279,8 @@ const std::string JournalFile::getFileName() const {
//static
uint64_t JournalFile::getRandom64() {
- int randomData = ::open("/dev/urandom", O_RDONLY);
- if (randomData < 0) {
- throw jexception(); // TODO: Complete exception details
- }
- uint64_t randomNumber;
- ::size_t size = sizeof(randomNumber);
- ::ssize_t result = ::read(randomData, (char*)&randomNumber, size);
- if (result < 0 || result != ssize_t(size)) {
- throw jexception(); // TODO: Complete exception details
- }
- ::close(randomData);
- return randomNumber;
+ // TODO: ::rand() is not thread safe, either lock or use rand_r(seed) with a thread-local seed.
+ return ((uint64_t)::rand() << QLS_RAND_SHIFT1) | ((uint64_t)::rand() << QLS_RAND_SHIFT2) | (::rand() & QLS_RAND_MASK);
}
bool JournalFile::isOpen() const {