Skip to content

Commit

Permalink
plugin_proxy: flb_plugin_proxy includes flb_plugin_proxy_def
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 committed Jul 29, 2021
1 parent 7f0f057 commit 1a359fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 1 addition & 4 deletions include/fluent-bit/flb_plugin_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
25 changes: 15 additions & 10 deletions src/flb_plugin_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 1a359fd

Please sign in to comment.