aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/entropy
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/entropy')
-rw-r--r--src/lib/entropy/egd/es_egd.cpp4
-rw-r--r--src/lib/entropy/proc_walk/proc_walk.cpp2
-rw-r--r--src/lib/entropy/unix_procs/unix_procs.cpp25
3 files changed, 19 insertions, 12 deletions
diff --git a/src/lib/entropy/egd/es_egd.cpp b/src/lib/entropy/egd/es_egd.cpp
index c04acb4f3..e61d4ef82 100644
--- a/src/lib/entropy/egd/es_egd.cpp
+++ b/src/lib/entropy/egd/es_egd.cpp
@@ -43,7 +43,7 @@ int EGD_EntropySource::EGD_Socket::open_socket(const std::string& path)
std::memset(&addr, 0, sizeof(addr));
addr.sun_family = PF_LOCAL;
- if(sizeof(addr.sun_path) < path.length() + 1)
+ if(path.length() >= sizeof(addr.sun_path))
throw std::invalid_argument("EGD socket path is too long");
std::strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path));
@@ -109,7 +109,7 @@ size_t EGD_EntropySource::EGD_Socket::read(byte outbuf[], size_t length)
void EGD_EntropySource::EGD_Socket::close()
{
- if(m_fd > 0)
+ if(m_fd >= 0)
{
::close(m_fd);
m_fd = -1;
diff --git a/src/lib/entropy/proc_walk/proc_walk.cpp b/src/lib/entropy/proc_walk/proc_walk.cpp
index 5a72f46e5..f459a7e32 100644
--- a/src/lib/entropy/proc_walk/proc_walk.cpp
+++ b/src/lib/entropy/proc_walk/proc_walk.cpp
@@ -106,7 +106,7 @@ int Directory_Walker::next_fd()
{
int fd = ::open(full_path.c_str(), O_RDONLY | O_NOCTTY);
- if(fd > 0)
+ if(fd >= 0)
return fd;
}
}
diff --git a/src/lib/entropy/unix_procs/unix_procs.cpp b/src/lib/entropy/unix_procs/unix_procs.cpp
index c36941f43..7925741bb 100644
--- a/src/lib/entropy/unix_procs/unix_procs.cpp
+++ b/src/lib/entropy/unix_procs/unix_procs.cpp
@@ -11,6 +11,7 @@
#include <botan/internal/unix_procs.h>
#include <botan/parsing.h>
#include <algorithm>
+#include <atomic>
#include <sys/time.h>
#include <sys/stat.h>
@@ -67,19 +68,25 @@ Unix_EntropySource::Unix_EntropySource(const std::vector<std::string>& trusted_p
void UnixProcessInfo_EntropySource::poll(Entropy_Accumulator& accum)
{
- accum.add(::getpid(), 0.0);
- accum.add(::getppid(), 0.0);
- accum.add(::getuid(), 0.0);
- accum.add(::getgid(), 0.0);
- accum.add(::getsid(0), 0.0);
- accum.add(::getpgrp(), 0.0);
+ static std::atomic<int> last_pid;
+
+ int pid = ::getpid();
+
+ accum.add(pid, 0.0);
+
+ if(pid != last_pid)
+ {
+ last_pid = pid;
+ accum.add(::getppid(), 0.0);
+ accum.add(::getuid(), 0.0);
+ accum.add(::getgid(), 0.0);
+ accum.add(::getsid(0), 0.0);
+ accum.add(::getpgrp(), 0.0);
+ }
struct ::rusage usage;
::getrusage(RUSAGE_SELF, &usage);
accum.add(usage, 0.0);
-
- ::getrusage(RUSAGE_CHILDREN, &usage);
- accum.add(usage, 0.0);
}
namespace {