Skip to content

Commit

Permalink
Merge pull request #29 from pandax381/pr_pre_exit
Browse files Browse the repository at this point in the history
Engine: implement cb_exit callback for plugins
  • Loading branch information
edsiper committed Sep 2, 2015
2 parents f16b017 + af0e21c commit 7719138
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
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

0 comments on commit 7719138

Please sign in to comment.