aboutsummaryrefslogtreecommitdiffstats
path: root/src/entropy/proc_walk
diff options
context:
space:
mode:
Diffstat (limited to 'src/entropy/proc_walk')
-rw-r--r--src/entropy/proc_walk/es_ftw.cpp32
-rw-r--r--src/entropy/proc_walk/es_ftw.h11
2 files changed, 36 insertions, 7 deletions
diff --git a/src/entropy/proc_walk/es_ftw.cpp b/src/entropy/proc_walk/es_ftw.cpp
index ec11378f8..f90d422a5 100644
--- a/src/entropy/proc_walk/es_ftw.cpp
+++ b/src/entropy/proc_walk/es_ftw.cpp
@@ -22,7 +22,7 @@ namespace Botan {
namespace {
-class Directory_Walker
+class Directory_Walker : public FTW_EntropySource::File_Descriptor_Source
{
public:
Directory_Walker(const std::string& root) { add_directory(root); }
@@ -93,11 +93,20 @@ int Directory_Walker::next_fd()
}
-/*************************************************
-* FTW_EntropySource Constructor *
-*************************************************/
+/**
+* FTW_EntropySource Constructor
+*/
FTW_EntropySource::FTW_EntropySource(const std::string& p) : path(p)
{
+ dir = 0;
+ }
+
+/**
+* FTW_EntropySource Destructor
+*/
+FTW_EntropySource::~FTW_EntropySource()
+ {
+ delete dir;
}
/*************************************************
@@ -121,16 +130,25 @@ void FTW_EntropySource::do_slow_poll()
*************************************************/
void FTW_EntropySource::poll(u32bit max_read)
{
- Directory_Walker dir(path);
+ if(!dir)
+ dir = new Directory_Walker(path);
+
SecureVector<byte> read_buf(1024);
u32bit read_so_far = 0;
while(read_so_far < max_read)
{
- int fd = dir.next_fd();
+ int fd = dir->next_fd();
if(fd == -1)
- break;
+ {
+ delete dir;
+ dir = new Directory_Walker(path);
+ fd = dir->next_fd();
+
+ if(fd == -1) // still fails (directory not mounted, etc) -> exit
+ break;
+ }
ssize_t got = ::read(fd, read_buf.begin(), read_buf.size());
diff --git a/src/entropy/proc_walk/es_ftw.h b/src/entropy/proc_walk/es_ftw.h
index e0d266141..a0d480aae 100644
--- a/src/entropy/proc_walk/es_ftw.h
+++ b/src/entropy/proc_walk/es_ftw.h
@@ -16,7 +16,17 @@ namespace Botan {
class BOTAN_DLL FTW_EntropySource : public Buffered_EntropySource
{
public:
+ std::string name() const { return "Proc Walker"; }
+
FTW_EntropySource(const std::string& root_dir);
+ ~FTW_EntropySource();
+
+ class File_Descriptor_Source
+ {
+ public:
+ virtual int next_fd() = 0;
+ virtual ~File_Descriptor_Source() {}
+ };
private:
void do_fast_poll();
void do_slow_poll();
@@ -24,6 +34,7 @@ class BOTAN_DLL FTW_EntropySource : public Buffered_EntropySource
void poll(u32bit max_read);
const std::string path;
+ File_Descriptor_Source* dir;
};
}