Skip to content

Commit b9d5468

Browse files
committed
Merge pull request #20 from hasegaw/pr_defer_inputs_init
flb_input: Defer initialzation of input modules
2 parents 8bd0d4e + df5819b commit b9d5468

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

include/fluent-bit/flb_input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ int flb_input_set_collector_event(char *name,
106106
int (*cb_collect) (struct flb_config *, void *),
107107
int fd,
108108
struct flb_config *config);
109+
void flb_input_initialize_all(struct flb_config *config);
109110
void flb_input_pre_run_all(struct flb_config *config);
110111

111112
#endif

src/flb_engine.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ int flb_engine_start(struct flb_config *config)
162162

163163
flb_info("starting engine");
164164

165+
/* Initialize input plugins */
166+
flb_input_initialize_all(config);
167+
165168
/* Inputs pre-run */
166169
flb_input_pre_run_all(config);
167170

src/flb_input.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,36 @@ static struct flb_input_plugin *plugin_lookup(char *name, struct flb_config *con
4343
/* Enable an input */
4444
int flb_input_enable(char *name, struct flb_config *config)
4545
{
46-
int ret;
4746
struct flb_input_plugin *plugin;
4847

4948
plugin = plugin_lookup(name, config);
5049
if (!plugin) {
5150
return -1;
5251
}
5352

54-
if (!plugin->cb_init) {
55-
flb_utils_error(FLB_ERR_INPUT_UNSUP);
56-
}
5753
plugin->active = FLB_TRUE;
5854

59-
/* Initialize the input */
60-
if (plugin->cb_init) {
61-
ret = plugin->cb_init(config);
62-
if (ret != 0) {
63-
flb_error("Failed ininitalize Input %s",
64-
plugin->name);
55+
return 0;
56+
}
57+
58+
/* Initialize all inputs */
59+
void flb_input_initialize_all(struct flb_config *config)
60+
{
61+
int ret;
62+
struct mk_list *head;
63+
struct flb_input_plugin *in;
64+
65+
mk_list_foreach(head, &config->inputs) {
66+
in = mk_list_entry(head, struct flb_input_plugin, _head);
67+
/* Initialize the input */
68+
if (in->active == FLB_TRUE && in->cb_init) {
69+
ret = in->cb_init(config);
70+
if (ret != 0) {
71+
flb_error("Failed ininitalize input %s",
72+
in->name);
73+
}
6574
}
6675
}
67-
68-
return 0;
6976
}
7077

7178
/* Invoke all pre-run input callbacks */

0 commit comments

Comments
 (0)