Skip to content

Commit

Permalink
input: the initialization callback now accepts an optional 'data' arg…
Browse files Browse the repository at this point in the history
…ument

In some cases when Fluent Bit is run in library mode, the caller may want
to pass some data/reference to the input plugin. This patch allows to store
and pass that reference when the plugin is being initialized.

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Jan 12, 2016
1 parent 2a9544b commit 9a5b137
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
11 changes: 9 additions & 2 deletions include/fluent-bit/flb_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct flb_input_plugin {
char *description;

/* Initalization */
int (*cb_init) (struct flb_config *);
int (*cb_init) (struct flb_config *, void *);

/* Pre run */
int (*cb_pre_run) (void *, struct flb_config *);
Expand Down Expand Up @@ -79,6 +79,13 @@ struct flb_input_plugin {
int stats_fd;
#endif

/*
* Optional data passed to the plugin, this info is useful when
* running Fluent Bit in library mode and the target plugin needs
* some specific data from it caller.
*/
void *data;

/* Link to global list from flb_config->inputs */
struct mk_list _head;
};
Expand All @@ -105,7 +112,7 @@ struct flb_input_collector {
};

int flb_input_register_all(struct flb_config *config);
int flb_input_set(struct flb_config *config, char *name);
int flb_input_set(struct flb_config *config, char *name, void *data);
int flb_input_check(struct flb_config *config);
int flb_input_set_context(char *name, void *in_context, struct flb_config *config);
int flb_input_set_collector_time(char *name,
Expand Down
2 changes: 1 addition & 1 deletion include/fluent-bit/flb_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct flb_lib_ctx {
struct flb_config *config;
};

struct flb_lib_ctx *flb_lib_init(char *input, char *output);
struct flb_lib_ctx *flb_lib_init(char *input, char *output, void *data);
int flb_lib_config_file(struct flb_lib_ctx *ctx, char *path);
int flb_lib_push(struct flb_lib_ctx *ctx, void *data, size_t len);
int flb_lib_start(struct flb_lib_ctx *ctx);
Expand Down
5 changes: 3 additions & 2 deletions src/flb_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static struct flb_input_plugin *plugin_lookup(char *name, struct flb_config *con
}

/* Enable an input */
int flb_input_set(struct flb_config *config, char *name)
int flb_input_set(struct flb_config *config, char *name, void *data)
{
struct flb_input_plugin *plugin;

Expand All @@ -51,6 +51,7 @@ int flb_input_set(struct flb_config *config, char *name)
}

plugin->active = FLB_TRUE;
plugin->data = data;

return 0;
}
Expand All @@ -66,7 +67,7 @@ void flb_input_initialize_all(struct flb_config *config)
in = mk_list_entry(head, struct flb_input_plugin, _head);
/* Initialize the input */
if (in->active == FLB_TRUE && in->cb_init) {
ret = in->cb_init(config);
ret = in->cb_init(config, in->data);
if (ret != 0) {
flb_error("Failed ininitalize input %s",
in->name);
Expand Down
6 changes: 3 additions & 3 deletions src/flb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void flb_lib_context_destroy(struct flb_lib_ctx *ctx)
* plugin for the configuration context in question. This is a mandatory step
* for callers who wants to ingest data directly into the engine.
*/
struct flb_lib_ctx *flb_lib_init(char *input, char *output)
struct flb_lib_ctx *flb_lib_init(char *input, char *output, void *data)
{
int ret;
struct flb_lib_ctx *ctx;
Expand All @@ -85,10 +85,10 @@ struct flb_lib_ctx *flb_lib_init(char *input, char *output)
config = ctx->config;

if (!input) {
ret = flb_input_set(config, "lib");
ret = flb_input_set(config, "lib", data);
}
else {
ret = flb_input_set(config, input);
ret = flb_input_set(config, input, data);
}

if (ret == -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int main(int argc, char **argv)
config->flush = atoi(optarg);
break;
case 'i':
ret = flb_input_set(config, optarg);
ret = flb_input_set(config, optarg, NULL);
if (ret != 0) {
flb_utils_error(FLB_ERR_INPUT_INVALID);
}
Expand Down

0 comments on commit 9a5b137

Please sign in to comment.