Browse Source

Attempt to fix #43 failure to read from /dev/urandom

master
Artyom Beilis 5 years ago
parent
commit
3e3cf43201
1 changed files with 12 additions and 2 deletions
  1. +12
    -2
      src/urandom.cpp

+ 12
- 2
src/urandom.cpp View File

@@ -80,6 +80,7 @@ namespace cppcms {
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

@@ -108,11 +109,20 @@ namespace cppcms {
int fd = open("/dev/urandom",O_RDONLY);
if(!fd)
throw cppcms_error("Failed to open /dev/urandom");
n = read(fd,ptr,len);
while(len > 0) {
n = read(fd,ptr,len);
if(n < 0 && errno == EINTR)
continue;
if(n <= 0)
break;
ptr = static_cast<char *>(ptr) + n;
len -= n;
}
close(fd);
}
if(n!=int(len))
if(len > 0) {
throw cppcms_error("Failed to read /dev/urandom");
}
}
}



Loading…
Cancel
Save