Skip to content

Commit 503ac69

Browse files
authored
scheduler: use flb_random_bytes() instead of /dev/urandom (#2679)
Windows does not support /dev/urandom. For this reason, it ended up using a weak entropy source for task scheduling. Avoid this issue by using flb_random_bytes() instead. Signed-off-by: Fujimoto Seiji <fujimoto@ceptord.net>
1 parent dc234b1 commit 503ac69

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/flb_scheduler.c

+4-15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <fluent-bit/flb_pipe.h>
2727
#include <fluent-bit/flb_engine.h>
2828
#include <fluent-bit/flb_engine_dispatch.h>
29+
#include <fluent-bit/flb_random.h>
2930

3031
#include <sys/types.h>
3132
#include <sys/stat.h>
@@ -65,27 +66,15 @@ static inline int consume_byte(flb_pipefd_t fd)
6566
static int random_uniform(int min, int max)
6667
{
6768
int val;
68-
int fd;
6969
int range;
7070
int copies;
7171
int limit;
7272
int ra;
73-
int ret;
7473

75-
fd = open("/dev/urandom", O_RDONLY);
76-
if (fd == -1) {
77-
srand(time(NULL));
78-
}
79-
else {
80-
ret = read(fd, &val, sizeof(val));
81-
if (ret > 0) {
82-
srand(val);
83-
}
84-
else {
85-
srand(time(NULL));
86-
}
87-
close(fd);
74+
if (flb_random_bytes((unsigned char *) &val, sizeof(int))) {
75+
val = time(NULL);
8876
}
77+
srand(val);
8978

9079
range = max - min + 1;
9180
copies = (RAND_MAX / range);

0 commit comments

Comments
 (0)