diff options
-rw-r--r-- | src/lib/entropy/dev_random/dev_random.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/lib/entropy/dev_random/dev_random.cpp b/src/lib/entropy/dev_random/dev_random.cpp index b51f19ecb..f37831d2e 100644 --- a/src/lib/entropy/dev_random/dev_random.cpp +++ b/src/lib/entropy/dev_random/dev_random.cpp @@ -38,18 +38,7 @@ Device_EntropySource::Device_EntropySource(const std::vector<std::string>& fsnam { int fd = ::open(fsname.c_str(), flags); - if(fd > 0) - { - if(fd > FD_SETSIZE) - { - ::close(fd); - throw Exception("Open of OS RNG succeeded but fd is too large for fd_set"); - } - - m_dev_fds.push_back(fd); - m_max_fd = std::max(m_max_fd, fd); - } - else + if(fd < 0) { /* ENOENT or EACCES is normal as some of the named devices may not exist @@ -57,10 +46,19 @@ Device_EntropySource::Device_EntropySource(const std::vector<std::string>& fsnam either a bug in the application or file descriptor exhaustion. */ if(errno != ENOENT && errno != EACCES) - { throw Exception("Opening OS RNG device failed with errno " + std::to_string(errno)); + } + else + { + if(fd > FD_SETSIZE) + { + ::close(fd); + throw Exception("Open of OS RNG succeeded but fd is too large for fd_set"); } + + m_dev_fds.push_back(fd); + m_max_fd = std::max(m_max_fd, fd); } } } |