|
@@ -725,6 +725,11 @@ PARSER_RC metalog_pluginsd_host(char **words, void *user, PLUGINSD_ACTION *plug
|
|
|
return PARSER_RC_OK;
|
|
|
}
|
|
|
|
|
|
+static void pluginsd_process_thread_cleanup(void *ptr) {
|
|
|
+ PARSER *parser = (PARSER *)ptr;
|
|
|
+ parser_destroy(parser);
|
|
|
+}
|
|
|
+
|
|
|
// New plugins.d parser
|
|
|
|
|
|
inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int trust_durations)
|
|
@@ -743,19 +748,18 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
|
|
|
}
|
|
|
clearerr(fp);
|
|
|
|
|
|
- PARSER_USER_OBJECT *user = callocz(1, sizeof(*user));
|
|
|
- ((PARSER_USER_OBJECT *) user)->enabled = cd->enabled;
|
|
|
- ((PARSER_USER_OBJECT *) user)->host = host;
|
|
|
- ((PARSER_USER_OBJECT *) user)->cd = cd;
|
|
|
- ((PARSER_USER_OBJECT *) user)->trust_durations = trust_durations;
|
|
|
+ PARSER_USER_OBJECT user = {
|
|
|
+ .enabled = cd->enabled,
|
|
|
+ .host = host,
|
|
|
+ .cd = cd,
|
|
|
+ .trust_durations = trust_durations
|
|
|
+ };
|
|
|
|
|
|
- PARSER *parser = parser_init(host, user, fp, PARSER_INPUT_SPLIT);
|
|
|
+ PARSER *parser = parser_init(host, &user, fp, PARSER_INPUT_SPLIT);
|
|
|
|
|
|
- if (unlikely(!parser)) {
|
|
|
- error("Failed to initialize parser");
|
|
|
- cd->serial_failures++;
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ // this keeps the parser with its current value
|
|
|
+ // so, parser needs to be allocated before pushing it
|
|
|
+ netdata_thread_cleanup_push(pluginsd_process_thread_cleanup, parser);
|
|
|
|
|
|
parser->plugins_action->begin_action = &pluginsd_begin_action;
|
|
|
parser->plugins_action->flush_action = &pluginsd_flush_action;
|
|
@@ -770,25 +774,24 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
|
|
|
parser->plugins_action->clabel_commit_action = &pluginsd_clabel_commit_action;
|
|
|
parser->plugins_action->clabel_action = &pluginsd_clabel_action;
|
|
|
|
|
|
- user->parser = parser;
|
|
|
+ user.parser = parser;
|
|
|
|
|
|
while (likely(!parser_next(parser))) {
|
|
|
if (unlikely(netdata_exit || parser_action(parser, NULL)))
|
|
|
break;
|
|
|
}
|
|
|
- info("PARSER ended");
|
|
|
-
|
|
|
- parser_destroy(parser);
|
|
|
|
|
|
- cd->enabled = ((PARSER_USER_OBJECT *) user)->enabled;
|
|
|
- size_t count = ((PARSER_USER_OBJECT *) user)->count;
|
|
|
+ // free parser with the pop function
|
|
|
+ netdata_thread_cleanup_pop(1);
|
|
|
|
|
|
- freez(user);
|
|
|
+ cd->enabled = user.enabled;
|
|
|
+ size_t count = user.count;
|
|
|
|
|
|
if (likely(count)) {
|
|
|
cd->successful_collections += count;
|
|
|
cd->serial_failures = 0;
|
|
|
- } else
|
|
|
+ }
|
|
|
+ else
|
|
|
cd->serial_failures++;
|
|
|
|
|
|
return count;
|