Skip to content

Commit

Permalink
Core: prepare a channel when using in library mode
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Aug 26, 2015
1 parent 0cacedb commit 45169e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/fluent-bit/flb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ struct flb_config {
int flush_fd; /* Timer FD associated to flush */
int verbose; /* Verbose mode (default OFF) */
time_t init_time; /* Time when Fluent Bit started */

/* Used in library mode */
pthread_t worker; /* worker tid */
int channel[2]; /* pipe to communicate caller with worker */

struct mk_rconf *file;

Expand Down
16 changes: 10 additions & 6 deletions src/flb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

#include <signal.h>
#include <unistd.h>

#include <fluent-bit/flb_engine.h>
#include <fluent-bit/flb_input.h>
#include <fluent-bit/flb_output.h>
Expand All @@ -38,6 +40,12 @@ int flb_lib_init(struct flb_config *config, char *output)
return -1;
}

ret = pipe(config->channel);
if (ret == -1) {
perror("pipe");
return -1;
}

ret = flb_output_set(config, output);
if (ret == -1) {
return -1;
Expand All @@ -48,12 +56,7 @@ int flb_lib_init(struct flb_config *config, char *output)

int flb_lib_push(struct flb_config *config, void *data, size_t len)
{
struct flb_input_plugin *p;

p = &in_lib_plugin;
p->cb_ingest(p->in_context, data, len);

return 0;
return write(config->channel[1], data, len);
}

static void flb_lib_worker(void *data)
Expand All @@ -72,6 +75,7 @@ int flb_lib_start(struct flb_config *config)
}

config->worker = tid;
sleep(0.5);
return 0;
}

Expand Down

0 comments on commit 45169e5

Please sign in to comment.