Fixes?
This commit is contained in:
parent
f96a7201cf
commit
110c1a0013
2 changed files with 8 additions and 4 deletions
|
@ -306,11 +306,14 @@ namespace Util{
|
|||
/// Secure random bytes generator
|
||||
/// Uses /dev/urandom internally
|
||||
void getRandomBytes(void * dest, size_t len){
|
||||
static FILE * randSource = fopen("/dev/urandom", "rb");
|
||||
if (fread((void *)dest, len, 1, randSource) != 1){
|
||||
std::ifstream rndSrc("/dev/urandom", std::ifstream::binary);
|
||||
rndSrc.read((char*)dest, len);
|
||||
size_t cnt = rndSrc.gcount();
|
||||
if (!rndSrc.good()){
|
||||
WARN_MSG("Reading random data failed - generating using rand() as backup");
|
||||
for (size_t i = 0; i < len; ++i){((char*)dest)[i] = rand() % 255;}
|
||||
for (size_t i = cnt; i < len; ++i){((char*)dest)[i] = rand() % 255;}
|
||||
}
|
||||
rndSrc.close();
|
||||
}
|
||||
|
||||
/// 64-bits version of ftell
|
||||
|
|
|
@ -385,7 +385,7 @@ void Controller::SharedMemStats(void *config){
|
|||
while (((Util::Config *)config)->is_active){
|
||||
{
|
||||
std::ifstream cpustat("/proc/stat");
|
||||
if (cpustat){
|
||||
if (cpustat.good()){
|
||||
char line[300];
|
||||
while (cpustat.getline(line, 300)){
|
||||
static uint64_t cl_total = 0, cl_idle = 0;
|
||||
|
@ -403,6 +403,7 @@ void Controller::SharedMemStats(void *config){
|
|||
}
|
||||
}
|
||||
}
|
||||
cpustat.close();
|
||||
}
|
||||
{
|
||||
tthread::lock_guard<tthread::mutex> guard(Controller::configMutex);
|
||||
|
|
Loading…
Add table
Reference in a new issue