summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2013-07-30 23:28:02 +0200
committerJose <jose@zeroc.com>2013-07-30 23:28:02 +0200
commit24e634c970ceec6a1ef5d8f7e5013d1e42a61fb6 (patch)
tree910419a01ecbc6940fb117a0fed80befe8883cb8 /cpp/src
parentFixed ICE-5364 - test/Ice/binding failure with IPv6 on Ubuntu (diff)
downloadice-24e634c970ceec6a1ef5d8f7e5013d1e42a61fb6.tar.bz2
ice-24e634c970ceec6a1ef5d8f7e5013d1e42a61fb6.tar.xz
ice-24e634c970ceec6a1ef5d8f7e5013d1e42a61fb6.zip
ICE-5330 - reset "/dev/urandom" state at fork.
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceUtil/Random.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/cpp/src/IceUtil/Random.cpp b/cpp/src/IceUtil/Random.cpp
index 5da54df01e7..8bd61f41270 100644
--- a/cpp/src/IceUtil/Random.cpp
+++ b/cpp/src/IceUtil/Random.cpp
@@ -47,6 +47,18 @@ Mutex* staticMutex = 0;
HCRYPTPROV context = 0;
#else
int fd = -1;
+//
+// Callback to use with pthread_atfork to reset the "/dev/urandom"
+// fd state. We don't need to close the fd here as that is done
+// during static destruction.
+//
+void childAtFork()
+{
+ if(fd != -1)
+ {
+ fd = -1;
+ }
+}
#endif
class Init
@@ -56,6 +68,13 @@ public:
Init()
{
staticMutex = new IceUtil::Mutex;
+#ifndef _WIN32
+ //
+ // Register a callback to reset the "/dev/urandom" fd
+ // state after fork.
+ //
+ pthread_atfork(0, 0, &childAtFork);
+#endif
}
~Init()