From 24e634c970ceec6a1ef5d8f7e5013d1e42a61fb6 Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 30 Jul 2013 23:28:02 +0200 Subject: ICE-5330 - reset "/dev/urandom" state at fork. --- cpp/src/IceUtil/Random.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'cpp/src/IceUtil/Random.cpp') 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() -- cgit v1.2.3