diff options
Diffstat (limited to 'src/lib/entropy/unix_procs/unix_procs.cpp')
-rw-r--r-- | src/lib/entropy/unix_procs/unix_procs.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
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 { |