summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/UUID.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2003-05-22 23:49:14 +0000
committerBenoit Foucher <benoit@zeroc.com>2003-05-22 23:49:14 +0000
commitd9f50ea9c98230ddd24149cdd1c0172573e0c832 (patch)
tree445b33f19e9ded380bdc7aece91cc140321629f0 /cpp/src/IceUtil/UUID.cpp
parentFixed a bug that caused a crash if an empty sequence of classes was (diff)
downloadice-d9f50ea9c98230ddd24149cdd1c0172573e0c832.tar.bz2
ice-d9f50ea9c98230ddd24149cdd1c0172573e0c832.tar.xz
ice-d9f50ea9c98230ddd24149cdd1c0172573e0c832.zip
Fix for UUID test failure
Diffstat (limited to 'cpp/src/IceUtil/UUID.cpp')
-rw-r--r--cpp/src/IceUtil/UUID.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/cpp/src/IceUtil/UUID.cpp b/cpp/src/IceUtil/UUID.cpp
index 910158b112a..e60c9b45b6a 100644
--- a/cpp/src/IceUtil/UUID.cpp
+++ b/cpp/src/IceUtil/UUID.cpp
@@ -134,9 +134,33 @@ IceUtil::generateUUID()
assert(sizeof(UUID) == 16);
- size_t bytesRead = read(fd, &uuid, sizeof(UUID));
+ char* buffer = reinterpret_cast<char*>(&uuid);
+ int reads = 0;
+ size_t index = 0;
+
+ // Limit the number of attempts to 20 reads to avoid
+ // a potential "for ever" loop
+ //
+ while(reads <= 20 && index != sizeof(UUID))
+ {
+ ssize_t bytesRead = read(fd, buffer + index, sizeof(UUID) - index);
+
+ if(bytesRead == -1 && errno != EINTR)
+ {
+ int err = errno;
+ cerr << "Reading /dev/urandom returned " << strerror(err) << endl;
+ assert(0);
+ close(fd);
+ throw UUIDGenerationException(__FILE__, __LINE__);
+ }
+ else
+ {
+ index += bytesRead;
+ reads++;
+ }
+ }
- if (bytesRead != sizeof(UUID))
+ if (index != sizeof(UUID))
{
assert(0);
close(fd);