Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fluent/fluent-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
edsiper committed Sep 30, 2020
2 parents 155fafe + 11d1d79 commit 00e0742
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
25 changes: 3 additions & 22 deletions plugins/in_random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@
#include <fluent-bit/flb_config.h>
#include <fluent-bit/flb_error.h>
#include <fluent-bit/flb_pack.h>
#include <fluent-bit/flb_random.h>
#include <msgpack.h>

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _WIN32
# include <event2/util.h>
#else
# include <fcntl.h>
#endif
#include <fcntl.h>

#define DEFAULT_INTERVAL_SEC 1
#define DEFAULT_INTERVAL_NSEC 0
Expand All @@ -53,8 +50,6 @@ struct flb_in_random_config {
static int in_random_collect(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
{
int fd;
int ret;
uint64_t val;
msgpack_packer mp_pck;
msgpack_sbuffer mp_sbuf;
Expand All @@ -68,23 +63,9 @@ static int in_random_collect(struct flb_input_instance *ins,
return -1;
}

#ifdef _WIN32
evutil_secure_rng_get_bytes(&val, sizeof(val));
#else
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1) {
if (flb_random_bytes((unsigned char *) &val, sizeof(uint64_t))) {
val = time(NULL);
}
else {
ret = read(fd, &val, sizeof(val));
if (ret == -1) {
perror("read");
close(fd);
return -1;
}
close(fd);
}
#endif

/* Initialize local msgpack buffer */
msgpack_sbuffer_init(&mp_sbuf);
Expand Down
17 changes: 2 additions & 15 deletions plugins/out_gelf/gelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <fluent-bit/flb_gzip.h>
#include <fluent-bit/flb_utils.h>
#include <fluent-bit/flb_network.h>
#include <fluent-bit/flb_random.h>
#include <msgpack.h>

#include <stdio.h>
Expand Down Expand Up @@ -321,8 +322,6 @@ static void cb_gelf_flush(const void *data, size_t bytes,
static int cb_gelf_init(struct flb_output_instance *ins, struct flb_config *config,
void *data)
{
int ret;
int fd;
const char *tmp;
struct flb_out_gelf_config *ctx = NULL;

Expand Down Expand Up @@ -408,21 +407,9 @@ static int cb_gelf_init(struct flb_output_instance *ins, struct flb_config *conf
}

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

ctx->fd = -1;
Expand Down

0 comments on commit 00e0742

Please sign in to comment.