From 1a359fda5dcd3ffdf7bbf3a639700cd014bd57b8 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Thu, 29 Jul 2021 22:01:51 +0900 Subject: [PATCH] plugin_proxy: flb_plugin_proxy includes flb_plugin_proxy_def Signed-off-by: Takahiro Yamashita --- include/fluent-bit/flb_plugin_proxy.h | 5 +---- src/flb_plugin_proxy.c | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/fluent-bit/flb_plugin_proxy.h b/include/fluent-bit/flb_plugin_proxy.h index 14e974ca741..90657c4d0f9 100644 --- a/include/fluent-bit/flb_plugin_proxy.h +++ b/include/fluent-bit/flb_plugin_proxy.h @@ -44,10 +44,7 @@ struct flb_plugin_proxy_def { /* Proxy context */ struct flb_plugin_proxy { /* Fields populated once remote flb_cb_register() is called */ - int type; /* defined by FLB_PROXY_[INPUT|OUTPUT]_PLUGIN */ - int proxy; /* proxy type */ - char *name; /* plugin short name */ - char *description; /* plugin description */ + struct flb_plugin_proxy_def *def; /* Internal */ struct flb_api *api; /* API context to export functions */ diff --git a/src/flb_plugin_proxy.c b/src/flb_plugin_proxy.c index 9935ad7b5ca..dc5674b30ad 100644 --- a/src/flb_plugin_proxy.c +++ b/src/flb_plugin_proxy.c @@ -50,7 +50,7 @@ static void flb_proxy_cb_flush(const void *data, size_t bytes, (void) config; #ifdef FLB_HAVE_PROXY_GO - if (ctx->proxy->proxy == FLB_PROXY_GOLANG) { + if (ctx->proxy->def->proxy == FLB_PROXY_GOLANG) { flb_trace("[GO] entering go_flush()"); ret = proxy_go_flush(ctx, data, bytes, tag, tag_len); } @@ -136,7 +136,7 @@ int flb_plugin_proxy_register(struct flb_plugin_proxy *proxy, { int ret; int (*cb_register)(struct flb_plugin_proxy_def *); - struct flb_plugin_proxy_def *def; + struct flb_plugin_proxy_def *def = proxy->def; /* Lookup the registration callback */ cb_register = flb_plugin_proxy_symbol(proxy, "FLBPluginRegister"); @@ -149,10 +149,6 @@ int flb_plugin_proxy_register(struct flb_plugin_proxy *proxy, * - plugin name * - plugin description */ - def = flb_malloc(sizeof(struct flb_plugin_proxy_def)); - if (!def) { - return -1; - } /* Do the registration */ ret = cb_register(def); @@ -177,7 +173,6 @@ int flb_plugin_proxy_register(struct flb_plugin_proxy *proxy, * real link to the 'output' interface */ if (def->type == FLB_PROXY_OUTPUT_PLUGIN) { - proxy->proxy = def->proxy; flb_proxy_register_output(proxy, def, config); } } @@ -195,14 +190,14 @@ int flb_plugin_proxy_init(struct flb_plugin_proxy *proxy, proxy->instance = o_ins; /* Based on 'proxy', use the proper handler */ - if (proxy->proxy == FLB_PROXY_GOLANG) { + if (proxy->def->proxy == FLB_PROXY_GOLANG) { #ifdef FLB_HAVE_PROXY_GO ret = proxy_go_init(proxy); #endif } else { fprintf(stderr, "[proxy] unrecognized proxy handler %i\n", - proxy->proxy); + proxy->def->proxy); } return ret; @@ -238,8 +233,17 @@ struct flb_plugin_proxy *flb_plugin_proxy_create(const char *dso_path, int type, return NULL; } + proxy->def = flb_malloc(sizeof(struct flb_plugin_proxy_def)); + if (!proxy->def) { + flb_errno(); + dlclose(handle); + flb_api_destroy(proxy->api); + flb_free(proxy); + return NULL; + } + /* Set fields and add it to the list */ - proxy->type = type; + proxy->def->type = type; proxy->dso_handler = handle; proxy->data = NULL; mk_list_add(&proxy->_head, &config->proxies); @@ -253,6 +257,7 @@ struct flb_plugin_proxy *flb_plugin_proxy_create(const char *dso_path, int type, void flb_plugin_proxy_destroy(struct flb_plugin_proxy *proxy) { /* cleanup */ + flb_free(proxy->def); flb_api_destroy(proxy->api); dlclose(proxy->dso_handler); mk_list_del(&proxy->_head);