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

Engine: implement cb_exit callback for plugins #29

Merged
merged 2 commits into from
Sep 2, 2015
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions include/fluent-bit/flb_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ struct flb_input_plugin {
*/
int (*cb_ingest) (void *in_context, void *, size_t);

/* Exit */
int (*cb_exit) (void *, struct flb_config *);

/* Input handler configuration */
void *in_context;

Expand Down Expand Up @@ -113,5 +116,6 @@ int flb_input_set_collector_event(char *name,
struct flb_config *config);
void flb_input_initialize_all(struct flb_config *config);
void flb_input_pre_run_all(struct flb_config *config);
void flb_input_exit_all(struct flb_config *config);

#endif
4 changes: 4 additions & 0 deletions include/fluent-bit/flb_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ struct flb_output_plugin {
/* Flush callback */
int (*cb_flush) (void *, size_t, void *, struct flb_config *);

/* Exit */
int (*cb_exit) (void *, struct flb_config *);

/* Output handler configuration */
void *out_context;

Expand All @@ -80,6 +83,7 @@ struct flb_output_plugin {

int flb_output_set(struct flb_config *config, char *output);
void flb_output_pre_run(struct flb_config *config);
void flb_output_exit(struct flb_config *config);
int flb_output_set_context(char *name, void *out_context, struct flb_config *config);
int flb_output_init(struct flb_config *config);

Expand Down
4 changes: 4 additions & 0 deletions src/flb_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ int flb_engine_start(struct flb_config *config)
if (event->type == FLB_ENGINE_EV_CORE) {
ret = flb_engine_handle_event(event->fd, event->mask, config);
if (ret == -1) {
/* Inputs exit */
flb_input_exit_all(config);
/* Outputs exit */
flb_output_exit(config);
return 0;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/flb_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ void flb_input_pre_run_all(struct flb_config *config)
}
}

/* Invoke all exit input callbacks */
void flb_input_exit_all(struct flb_config *config)
{
struct mk_list *head;
struct flb_input_plugin *in;

mk_list_foreach(head, &config->inputs) {
in = mk_list_entry(head, struct flb_input_plugin, _head);
if (in->active == FLB_TRUE) {
if (in->cb_exit) {
in->cb_exit(in->in_context, config);
}
}
}
}

/* Check that at least one Input is enabled */
int flb_input_check(struct flb_config *config)
{
Expand Down
21 changes: 21 additions & 0 deletions src/flb_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ void flb_output_pre_run(struct flb_config *config)
}
}

/* Invoke exit call for the output plugin */
void flb_output_exit(struct flb_config *config)
{
struct mk_list *head;
struct flb_output_plugin *out;

mk_list_foreach(head, &config->outputs) {
out = mk_list_entry(head, struct flb_output_plugin, _head);
if (out->active == FLB_TRUE) {
/* Check a exit callback */
if (out->cb_exit) {
out->cb_exit(out->out_context, config);
}

if (out->upstream) {
/* TODO: close/destroy out->upstream */
}
}
}
}

/*
* It validate an output type given the string, it return the
* proper type and if valid, populate the global config.
Expand Down