Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler: use flb_random_bytes() instead of /dev/urandom #2679

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/flb_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <fluent-bit/flb_pipe.h>
#include <fluent-bit/flb_engine.h>
#include <fluent-bit/flb_engine_dispatch.h>
#include <fluent-bit/flb_random.h>

#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -65,27 +66,15 @@ static inline int consume_byte(flb_pipefd_t fd)
static int random_uniform(int min, int max)
{
int val;
int fd;
int range;
int copies;
int limit;
int ra;
int ret;

fd = open("/dev/urandom", O_RDONLY);
if (fd == -1) {
srand(time(NULL));
}
else {
ret = read(fd, &val, sizeof(val));
if (ret > 0) {
srand(val);
}
else {
srand(time(NULL));
}
close(fd);
if (flb_random_bytes((unsigned char *) &val, sizeof(int))) {
val = time(NULL);
}
srand(val);

range = max - min + 1;
copies = (RAND_MAX / range);
Expand Down