-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
flb_input.c
865 lines (737 loc) · 23.5 KB
/
flb_input.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* Fluent Bit
* ==========
* Copyright (C) 2019 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <monkey/mk_core.h>
#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_mem.h>
#include <fluent-bit/flb_str.h>
#include <fluent-bit/flb_env.h>
#include <fluent-bit/flb_pipe.h>
#include <fluent-bit/flb_macros.h>
#include <fluent-bit/flb_input.h>
#include <fluent-bit/flb_error.h>
#include <fluent-bit/flb_utils.h>
#include <fluent-bit/flb_engine.h>
#include <fluent-bit/flb_metrics.h>
#include <fluent-bit/flb_storage.h>
#include <fluent-bit/flb_kv.h>
#define protcmp(a, b) strncasecmp(a, b, strlen(a))
static int check_protocol(const char *prot, const char *output)
{
int len;
len = strlen(prot);
if (len > strlen(output)) {
return 0;
}
if (protcmp(prot, output) != 0) {
return 0;
}
return 1;
}
static inline int instance_id(struct flb_input_plugin *p,
struct flb_config *config) \
{
int c = 0;
struct mk_list *head;
struct flb_input_instance *entry;
mk_list_foreach(head, &config->inputs) {
entry = mk_list_entry(head, struct flb_input_instance, _head);
if (entry->id == c) {
c++;
}
}
return c;
}
/* Generate a new collector ID for the instance in question */
static int collector_id(struct flb_input_instance *in)
{
int id = 0;
struct flb_input_collector *collector;
if (mk_list_is_empty(&in->collectors) == 0) {
return id;
}
collector = mk_list_entry_last(&in->collectors,
struct flb_input_collector,
_head_ins);
return (collector->id + 1);
}
/* Create an input plugin instance */
struct flb_input_instance *flb_input_new(struct flb_config *config,
const char *input, void *data,
int public_only)
{
int id;
int ret;
struct mk_list *head;
struct flb_input_plugin *plugin;
struct flb_input_instance *instance = NULL;
if (!input) {
return NULL;
}
mk_list_foreach(head, &config->in_plugins) {
plugin = mk_list_entry(head, struct flb_input_plugin, _head);
if (!check_protocol(plugin->name, input)) {
plugin = NULL;
continue;
}
/*
* Check if the plugin is private and validate the 'public_only'
* requirement.
*/
if (public_only == FLB_TRUE && plugin->flags & FLB_INPUT_PRIVATE) {
return NULL;
}
/* Create plugin instance */
instance = flb_calloc(1, sizeof(struct flb_input_instance));
if (!instance) {
flb_errno();
return NULL;
}
instance->config = config;
/* Get an ID */
id = instance_id(plugin, config);
/* format name (with instance id) */
snprintf(instance->name, sizeof(instance->name) - 1,
"%s.%i", plugin->name, id);
instance->alias = NULL;
instance->id = id;
instance->flags = plugin->flags;
instance->p = plugin;
instance->tag = NULL;
instance->tag_len = 0;
instance->routable = FLB_TRUE;
instance->context = NULL;
instance->data = data;
instance->threaded = FLB_FALSE;
instance->storage = NULL;
/* net */
instance->host.name = NULL;
instance->host.address = NULL;
instance->host.uri = NULL;
instance->host.ipv6 = FLB_FALSE;
/* Initialize list heads */
mk_list_init(&instance->routes);
mk_list_init(&instance->tasks);
mk_list_init(&instance->chunks);
mk_list_init(&instance->collectors);
mk_list_init(&instance->threads);
/* Initialize properties list */
flb_kv_init(&instance->properties);
/* Plugin use networking */
if (plugin->flags & FLB_INPUT_NET) {
ret = flb_net_host_set(plugin->name, &instance->host, input);
if (ret != 0) {
flb_free(instance);
return NULL;
}
}
/* Plugin requires a Thread context */
if (plugin->flags & FLB_INPUT_THREAD) {
instance->threaded = FLB_TRUE;
}
instance->mp_total_buf_size = 0;
instance->mem_buf_status = FLB_INPUT_RUNNING;
instance->mem_buf_limit = 0;
instance->mem_chunks_size = 0;
mk_list_add(&instance->_head, &config->inputs);
}
return instance;
}
static inline int prop_key_check(const char *key, const char *kv, int k_len)
{
int len;
len = strlen(key);
if (strncasecmp(key, kv, k_len) == 0 && len == k_len) {
return 0;
}
return -1;
}
/* Override a configuration property for the given input_instance plugin */
int flb_input_set_property(struct flb_input_instance *in,
const char *k, const char *v)
{
int len;
ssize_t limit;
flb_sds_t tmp = NULL;
struct flb_kv *kv;
len = strlen(k);
tmp = flb_env_var_translate(in->config->env, v);
if (tmp) {
if (flb_sds_len(tmp) == 0) {
flb_sds_destroy(tmp);
tmp = NULL;
}
}
/* Check if the key is a known/shared property */
if (prop_key_check("tag", k, len) == 0 && tmp) {
in->tag = tmp;
in->tag_len = flb_sds_len(tmp);
}
else if (prop_key_check("routable", k, len) == 0 && tmp) {
in->routable = flb_utils_bool(tmp);
flb_sds_destroy(tmp);
}
else if (prop_key_check("alias", k, len) == 0 && tmp) {
in->alias = tmp;
}
else if (prop_key_check("mem_buf_limit", k, len) == 0 && tmp) {
limit = flb_utils_size_to_bytes(tmp);
flb_sds_destroy(tmp);
if (limit == -1) {
return -1;
}
in->mem_buf_limit = (size_t) limit;
}
else if (prop_key_check("listen", k, len) == 0) {
in->host.listen = tmp;
}
else if (prop_key_check("host", k, len) == 0) {
in->host.name = tmp;
}
else if (prop_key_check("port", k, len) == 0) {
if (tmp) {
in->host.port = atoi(tmp);
flb_sds_destroy(tmp);
}
}
else if (prop_key_check("ipv6", k, len) == 0 && tmp) {
in->host.ipv6 = flb_utils_bool(tmp);
flb_sds_destroy(tmp);
}
else {
/*
* Create the property, we don't pass the value since we will
* map it directly to avoid an extra memory allocation.
*/
kv = flb_kv_item_create(&in->properties, (char *) k, NULL);
if (!kv) {
if (tmp) {
flb_sds_destroy(tmp);
}
return -1;
}
kv->val = tmp;
}
return 0;
}
const char *flb_input_get_property(const char *key, struct flb_input_instance *i)
{
return flb_config_prop_get(key, &i->properties);
}
/* Return an instance name or alias */
const char *flb_input_name(struct flb_input_instance *in)
{
if (in->alias) {
return in->alias;
}
return in->name;
}
void flb_input_instance_free(struct flb_input_instance *in)
{
if (in->alias) {
flb_sds_destroy(in->alias);
}
/* Remove URI context */
if (in->host.uri) {
flb_uri_destroy(in->host.uri);
}
flb_sds_destroy(in->host.name);
flb_sds_destroy(in->host.address);
/* release the tag if any */
flb_sds_destroy(in->tag);
/* Let the engine remove any pending task */
flb_engine_destroy_tasks(&in->tasks);
/* release properties */
flb_kv_release(&in->properties);
/* Remove metrics */
#ifdef FLB_HAVE_METRICS
if (in->metrics) {
flb_metrics_destroy(in->metrics);
}
#endif
if (in->storage) {
flb_storage_input_destroy(in);
}
/* Unlink and release */
mk_list_del(&in->_head);
flb_free(in);
}
int flb_input_instance_init(struct flb_input_instance *in,
struct flb_config *config)
{
int ret;
const char *name;
struct flb_input_plugin *p = in->p;
/* Skip pseudo input plugins */
if (!p) {
return 0;
}
/* Metrics */
#ifdef FLB_HAVE_METRICS
/* Get name or alias for the instance */
name = flb_input_name(in);
/* Create the metrics context */
in->metrics = flb_metrics_create(name);
if (in->metrics) {
flb_metrics_add(FLB_METRIC_N_RECORDS, "records", in->metrics);
flb_metrics_add(FLB_METRIC_N_BYTES, "bytes", in->metrics);
}
#endif
/* Initialize the input */
if (p->cb_init) {
/* Sanity check: all non-dynamic tag input plugins must have a tag */
if (!in->tag) {
flb_input_set_property(in, "tag", in->name);
}
ret = p->cb_init(in, config, in->data);
if (ret != 0) {
flb_error("Failed initialize input %s",
in->name);
flb_input_instance_free(in);
return -1;
}
}
return 0;
}
/* Initialize all inputs */
void flb_input_initialize_all(struct flb_config *config)
{
int ret;
struct mk_list *tmp;
struct mk_list *head;
struct flb_input_instance *in;
struct flb_input_plugin *p;
/* Initialize thread-id table */
memset(&config->in_table_id, '\0', sizeof(config->in_table_id));
/* Iterate all active input instance plugins */
mk_list_foreach_safe(head, tmp, &config->inputs) {
in = mk_list_entry(head, struct flb_input_instance, _head);
p = in->p;
/* Skip pseudo input plugins */
if (!p) {
continue;
}
/* Initialize instance */
ret = flb_input_instance_init(in, config);
if (ret == -1) {
/* do nothing, it's ok if it fails */
}
}
}
/* Invoke all pre-run input callbacks */
void flb_input_pre_run_all(struct flb_config *config)
{
struct mk_list *head;
struct flb_input_instance *in;
struct flb_input_plugin *p;
mk_list_foreach(head, &config->inputs) {
in = mk_list_entry(head, struct flb_input_instance, _head);
p = in->p;
if (!p) {
continue;
}
if (p->cb_pre_run) {
p->cb_pre_run(in, config, in->context);
}
}
}
void flb_input_instance_exit(struct flb_input_instance *in,
struct flb_config *config)
{
struct flb_input_plugin *p;
p = in->p;
if (p->cb_exit && in->context) {
p->cb_exit(in->context, config);
}
}
/* Invoke all exit input callbacks */
void flb_input_exit_all(struct flb_config *config)
{
struct mk_list *tmp;
struct mk_list *head;
struct flb_input_instance *in;
struct flb_input_plugin *p;
/* Iterate instances */
mk_list_foreach_safe_r(head, tmp, &config->inputs) {
in = mk_list_entry(head, struct flb_input_instance, _head);
p = in->p;
if (!p) {
continue;
}
flb_input_instance_exit(in, config);
flb_input_instance_free(in);
}
}
/* Check that at least one Input is enabled */
int flb_input_check(struct flb_config *config)
{
if (mk_list_is_empty(&config->inputs) == 0) {
return -1;
}
return 0;
}
/*
* API for Input plugins
* =====================
* Copyright (C) 2019 The Fluent Bit Authors
* The Input interface provides a certain number of functions that can be
* used by Input plugins to configure it own behavior and request specific
*
* 1. flb_input_set_context()
*
* let an Input plugin set a context data reference that can be used
* later when invoking other callbacks.
*
* 2. flb_input_set_collector_time()
*
* request the Engine to trigger a specific collector callback at a
* certain interval time. Note that this callback will run in the main
* thread so it computing time must be short, otherwise it will block
* the main loop.
*
* The collector can runs in timeouts of the order of seconds.nanoseconds
*
* note: 1 Second = 1000000000 Nanosecond
*
* 3. flb_input_set_collector_event()
*
* for a registered file descriptor, associate the READ events to a
* specified plugin. Every time there is some data to read, the collector
* callback will be triggered. Oriented to a file descriptor that already
* have information that may be read through iotctl(..FIONREAD..);
*
* 4. flb_input_set_collector_server()
*
* it register a collector based on TCP socket events. It register a socket
* who did bind() and listen() and for each event on the socket it triggers
* the registered callbacks.
*/
/* Assign an Configuration context to an Input */
void flb_input_set_context(struct flb_input_instance *in, void *context)
{
in->context = context;
}
int flb_input_channel_init(struct flb_input_instance *in)
{
return flb_pipe_create(in->channel);
}
int flb_input_set_collector_time(struct flb_input_instance *in,
int (*cb_collect) (struct flb_input_instance *,
struct flb_config *, void *),
time_t seconds,
long nanoseconds,
struct flb_config *config)
{
struct flb_input_collector *collector;
collector = flb_malloc(sizeof(struct flb_input_collector));
if (!collector) {
flb_errno();
return -1;
}
collector->id = collector_id(in);
collector->type = FLB_COLLECT_TIME;
collector->cb_collect = cb_collect;
collector->fd_event = -1;
collector->fd_timer = -1;
collector->seconds = seconds;
collector->nanoseconds = nanoseconds;
collector->instance = in;
collector->running = FLB_FALSE;
MK_EVENT_ZERO(&collector->event);
mk_list_add(&collector->_head, &config->collectors);
mk_list_add(&collector->_head_ins, &in->collectors);
return collector->id;
}
int flb_input_set_collector_event(struct flb_input_instance *in,
int (*cb_collect) (struct flb_input_instance *,
struct flb_config *, void *),
flb_pipefd_t fd,
struct flb_config *config)
{
struct flb_input_collector *collector;
collector = flb_malloc(sizeof(struct flb_input_collector));
if (!collector) {
flb_errno();
return -1;
}
collector->id = collector_id(in);
collector->type = FLB_COLLECT_FD_EVENT;
collector->cb_collect = cb_collect;
collector->fd_event = fd;
collector->fd_timer = -1;
collector->seconds = -1;
collector->nanoseconds = -1;
collector->instance = in;
collector->running = FLB_FALSE;
MK_EVENT_ZERO(&collector->event);
mk_list_add(&collector->_head, &config->collectors);
mk_list_add(&collector->_head_ins, &in->collectors);
return collector->id;
}
static int collector_start(struct flb_input_collector *coll,
struct flb_config *config)
{
int fd;
int ret;
struct mk_event *event;
struct mk_event_loop *evl;
if (coll->running == FLB_TRUE) {
return 0;
}
event = &coll->event;
evl = config->evl;
if (coll->type == FLB_COLLECT_TIME) {
event->mask = MK_EVENT_EMPTY;
event->status = MK_EVENT_NONE;
fd = mk_event_timeout_create(evl, coll->seconds,
coll->nanoseconds, event);
if (fd == -1) {
flb_error("[input collector] COLLECT_TIME registration failed");
coll->running = FLB_FALSE;
return -1;
}
coll->fd_timer = fd;
}
else if (coll->type & (FLB_COLLECT_FD_EVENT | FLB_COLLECT_FD_SERVER)) {
event->fd = coll->fd_event;
event->mask = MK_EVENT_EMPTY;
event->status = MK_EVENT_NONE;
ret = mk_event_add(evl,
coll->fd_event,
FLB_ENGINE_EV_CORE,
MK_EVENT_READ, event);
if (ret == -1) {
flb_error("[input collector] COLLECT_EVENT registration failed");
mk_event_closesocket(coll->fd_event);
coll->running = FLB_FALSE;
return -1;
}
}
coll->running = FLB_TRUE;
return 0;
}
int flb_input_collector_start(int coll_id, struct flb_input_instance *in)
{
int ret;
int c = 0;
struct mk_list *head;
struct flb_input_collector *coll;
mk_list_foreach(head, &in->collectors) {
coll = mk_list_entry(head, struct flb_input_collector, _head_ins);
if (coll->id == coll_id) {
ret = collector_start(coll, in->config);
if (ret == -1) {
flb_error("[input] error starting collector #%i: %s",
in->name);
}
return ret;
}
c++;
}
return -1;
}
int flb_input_collectors_start(struct flb_config *config)
{
struct mk_list *head;
struct flb_input_collector *collector;
/* For each Collector, register the event into the main loop */
mk_list_foreach(head, &config->collectors) {
collector = mk_list_entry(head, struct flb_input_collector, _head);
collector_start(collector, config);
}
return 0;
}
static struct flb_input_collector *get_collector(int id,
struct flb_input_instance *in)
{
struct mk_list *head;
struct flb_input_collector *coll;
mk_list_foreach(head, &in->collectors) {
coll = mk_list_entry(head, struct flb_input_collector, _head_ins);
if (coll->id == id) {
return coll;
}
}
return NULL;
}
int flb_input_collector_running(int coll_id, struct flb_input_instance *in)
{
struct flb_input_collector *coll;
coll = get_collector(coll_id, in);
if (!coll) {
return FLB_FALSE;
}
return coll->running;
}
int flb_input_pause_all(struct flb_config *config)
{
int paused = 0;
struct mk_list *head;
struct flb_input_instance *in;
mk_list_foreach(head, &config->inputs) {
in = mk_list_entry(head, struct flb_input_instance, _head);
flb_info("[input] pausing %s", in->name);
if (flb_input_buf_paused(in) == FLB_FALSE) {
if (in->p->cb_pause) {
in->p->cb_pause(in->context, in->config);
}
paused++;
}
in->mem_buf_status = FLB_INPUT_PAUSED;
}
return paused;
}
int flb_input_collector_pause(int coll_id, struct flb_input_instance *in)
{
int ret;
struct flb_config *config;
struct flb_input_collector *coll;
coll = get_collector(coll_id, in);
if (!coll) {
return -1;
}
config = in->config;
if (coll->type == FLB_COLLECT_TIME) {
/*
* For a collector time, it's better to just remove the file
* descriptor associated to the time out, when resumed a new
* one can be created.
*/
mk_event_timeout_destroy(config->evl, &coll->event);
mk_event_closesocket(coll->fd_timer);
coll->fd_timer = -1;
}
else if (coll->type & (FLB_COLLECT_FD_SERVER | FLB_COLLECT_FD_EVENT)) {
ret = mk_event_del(config->evl, &coll->event);
if (ret != 0) {
flb_warn("[input] cannot disable event for %s", in->name);
return -1;
}
}
coll->running = FLB_FALSE;
return 0;
}
int flb_input_collector_resume(int coll_id, struct flb_input_instance *in)
{
int fd;
int ret;
struct flb_input_collector *coll;
struct flb_config *config;
struct mk_event *event;
coll = get_collector(coll_id, in);
if (!coll) {
return -1;
}
if (coll->running == FLB_TRUE) {
flb_error("[input] cannot resume collector %s:%i, already running",
in->name, coll_id);
return -1;
}
config = in->config;
event = &coll->event;
if (coll->type == FLB_COLLECT_TIME) {
event->mask = MK_EVENT_EMPTY;
event->status = MK_EVENT_NONE;
fd = mk_event_timeout_create(config->evl, coll->seconds,
coll->nanoseconds, event);
if (fd == -1) {
flb_error("[input collector] resume COLLECT_TIME failed");
return -1;
}
coll->fd_timer = fd;
}
else if (coll->type & (FLB_COLLECT_FD_SERVER | FLB_COLLECT_FD_EVENT)) {
event->fd = coll->fd_event;
event->mask = MK_EVENT_EMPTY;
event->status = MK_EVENT_NONE;
ret = mk_event_add(config->evl,
coll->fd_event,
FLB_ENGINE_EV_CORE,
MK_EVENT_READ, event);
if (ret == -1) {
flb_error("[input] cannot disable/pause event for %s", in->name);
return -1;
}
}
coll->running = FLB_TRUE;
return 0;
}
int flb_input_set_collector_socket(struct flb_input_instance *in,
int (*cb_new_connection) (struct flb_input_instance *,
struct flb_config *,
void *),
flb_pipefd_t fd,
struct flb_config *config)
{
struct flb_input_collector *collector;
collector = flb_malloc(sizeof(struct flb_input_collector));
if (!collector) {
flb_errno();
return -1;
}
collector->type = FLB_COLLECT_FD_SERVER;
collector->cb_collect = cb_new_connection;
collector->fd_event = fd;
collector->fd_timer = -1;
collector->seconds = -1;
collector->nanoseconds = -1;
collector->instance = in;
collector->running = FLB_FALSE;
MK_EVENT_ZERO(&collector->event);
mk_list_add(&collector->_head, &config->collectors);
mk_list_add(&collector->_head_ins, &in->collectors);
return 0;
}
int flb_input_collector_fd(flb_pipefd_t fd, struct flb_config *config)
{
struct mk_list *head;
struct flb_input_collector *collector = NULL;
struct flb_thread *th;
mk_list_foreach(head, &config->collectors) {
collector = mk_list_entry(head, struct flb_input_collector, _head);
if (collector->fd_event == fd) {
break;
}
else if (collector->fd_timer == fd) {
flb_utils_timer_consume(fd);
break;
}
collector = NULL;
}
/* No matches */
if (!collector) {
return -1;
}
if (collector->running == FLB_FALSE) {
return -1;
}
/* Trigger the collector callback */
if (collector->instance->threaded == FLB_TRUE) {
th = flb_input_thread_collect(collector, config);
if (!th) {
return -1;
}
flb_thread_resume(th);
}
else {
collector->cb_collect(collector->instance, config,
collector->instance->context);
}
return 0;
}