fluent / fluent-bit-plugin

Fluent Bit Dynamic Plugin Development
Apache License 2.0
13 stars 12 forks source link

out_stdout2: fix function args to support fluent-bit v2 #9

Open nokute78 opened 1 year ago

nokute78 commented 1 year ago

Current code uses old function prototypes. It causes following build warning and sigsegv.

This patch is to support fluent-bit v2 prototypes. https://github.com/fluent/fluent-bit/blob/v2.0.6/include/fluent-bit/flb_output.h#L199

Warning:

[ 50%] Building C object out_stdout2/CMakeFiles/flb-out_stdout2.dir/stdout2.c.o
/home/taka/git/fluent-bit-plugin/out_stdout2/stdout2.c:52:21: warning: initialization of ‘void (*)(struct flb_event_chunk *, struct flb_output_flush *, struct flb_input_instance *, void *, struct flb_config *)’ from incompatible pointer type ‘void (*)(const void *, size_t,  const char *, int,  struct flb_input_instance *, void *, struct flb_config *)’ {aka ‘void (*)(const void *, long unsigned int,  const char *, int,  struct flb_input_instance *, void *, struct flb_config *)’} [-Wincompatible-pointer-types]
   52 |     .cb_flush     = cb_stdout_flush,
      |                     ^~~~~~~~~~~~~~~

SIGSEGV:

[2022/12/10 08:06:36] [engine] caught signal (SIGSEGV)
#0  0x561068dc8dc1      in  msgpack_object_bin_print() at lib/msgpack-c/src/objectc.c:134
#1  0x561068dc8fee      in  msgpack_object_print() at lib/msgpack-c/src/objectc.c:192
#2  0x5610682ff8c1      in  flb_pack_print() at src/flb_pack.c:472
#3  0x7ff2d86b0d38      in  ???() at ???:0
#4  0x561068321726      in  output_pre_cb_flush() at include/fluent-bit/flb_output.h:527
#5  0x561068de918a      in  co_init() at lib/monkey/deps/flb_libco/amd64.c:117
#6  0xffffffffffffffff  in  ???() at ???:0
Aborted (core dumped)
nokute78 commented 1 year ago

Patched plugin works.

$ valgrind --leak-check=full ../../bin/fluent-bit -e ./flb-out_stdout2.so -i dummy -o stdout2
==12138== Memcheck, a memory error detector
==12138== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==12138== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==12138== Command: ../../bin/fluent-bit -e ./flb-out_stdout2.so -i dummy -o stdout2
==12138== 
Fluent Bit v2.0.7
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/12/10 08:18:11] [ info] [fluent bit] version=2.0.7, commit=0397d01126, pid=12138
[2022/12/10 08:18:11] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2022/12/10 08:18:11] [ info] [cmetrics] version=0.5.7
[2022/12/10 08:18:11] [ info] [ctraces ] version=0.2.5
[2022/12/10 08:18:11] [ info] [input:dummy:dummy.0] initializing
[2022/12/10 08:18:11] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2022/12/10 08:18:11] [ info] [sp] stream processor started
==12138== Warning: client switching stacks?  SP change: 0x5ff95a8 --> 0x54a2a10
==12138==          to suppress, use: --max-stackframe=11889560 or greater
==12138== Warning: client switching stacks?  SP change: 0x54a2968 --> 0x5ff95a8
==12138==          to suppress, use: --max-stackframe=11889728 or greater
==12138== Warning: client switching stacks?  SP change: 0x5ff97e8 --> 0x54a2968
==12138==          to suppress, use: --max-stackframe=11890304 or greater
==12138==          further instances of this message will not be shown.
[0] [1670627891.982745855, {"message"=>"dummy"}]
[0] [1670627892.975489926, {"message"=>"dummy"}]
^C[2022/12/10 08:18:14] [engine] caught signal (SIGINT)
[2022/12/10 08:18:14] [ warn] [engine] service will shutdown in max 5 seconds
[2022/12/10 08:18:14] [ info] [input] pausing dummy.0
[0] [1670627893.956161450, {"message"=>"dummy"}]
[2022/12/10 08:18:14] [ info] [engine] service has stopped (0 pending tasks)
[2022/12/10 08:18:14] [ info] [input] pausing dummy.0
==12138== 
==12138== HEAP SUMMARY:
==12138==     in use at exit: 0 bytes in 0 blocks
==12138==   total heap usage: 1,444 allocs, 1,444 frees, 1,245,991 bytes allocated
==12138== 
==12138== All heap blocks were freed -- no leaks are possible
==12138== 
==12138== For lists of detected and suppressed errors, rerun with: -s
==12138== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)