diff options
author | lloyd <[email protected]> | 2014-11-03 22:16:51 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-11-03 22:16:51 +0000 |
commit | bcd83686c3daed38974d1f9b533c07d35c5a7476 (patch) | |
tree | 3203d6f30423ebf3b7b5b3d4aa2b9ecc9ce5ba5e /src/lib/entropy/unix_procs | |
parent | d623823e7e0d2754343ab498f48976e91180d24f (diff) |
Various small fixes and cleanups, new is_prime util
Diffstat (limited to 'src/lib/entropy/unix_procs')
-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 { |