diff --git a/lib/hook.c b/lib/hook.c index dcc93a21b..008534e21 100644 --- a/lib/hook.c +++ b/lib/hook.c @@ -147,7 +147,6 @@ int hook_cmp_priority(const void *a, const void *b) int hook_parse_list(struct list *list, config_setting_t *cfg, struct path *o) { - struct hook h; struct plugin *p; int ret, priority = 10; @@ -167,6 +166,8 @@ int hook_parse_list(struct list *list, config_setting_t *cfg, struct path *o) if (!config_setting_is_group(cfg_hook)) cerror(cfg_hook, "The 'hooks' setting must be an array of strings."); + struct hook h = { .state = STATE_DESTROYED }; + ret = hook_init(&h, &p->hook, o); if (ret) continue; diff --git a/lib/hooks/drop.c b/lib/hooks/drop.c index d5b551430..f40052793 100644 --- a/lib/hooks/drop.c +++ b/lib/hooks/drop.c @@ -23,7 +23,7 @@ static int drop_read(struct hook *h, struct sample *smps[], size_t *cnt) if (h->prev) { dist = h->last->sequence - (int32_t) h->prev->sequence; if (dist <= 0) { - warn("Dropped sample: dist = %d, i = %d", dist, i); + warn("Dropped sample: sequence=%u, dist=%d, i=%d", h->last->sequence, dist, i); if (h->path && h->path->stats) stats_update(h->path->stats->delta, STATS_REORDERED, dist); } diff --git a/lib/node.c b/lib/node.c index 24218e344..c73b18506 100644 --- a/lib/node.c +++ b/lib/node.c @@ -86,7 +86,7 @@ int node_start(struct node *n) info("Starting node %s", node_name_long(n)); { INDENT - ret = n->_vt->start ? n->_vt->start(n) : -1; + ret = n->_vt->start ? n->_vt->start(n) : 0; if (ret) return ret; } @@ -107,7 +107,7 @@ int node_stop(struct node *n) info("Stopping node %s", node_name(n)); { INDENT - ret = n->_vt->stop ? n->_vt->stop(n) : -1; + ret = n->_vt->stop ? n->_vt->stop(n) : 0; } if (ret == 0) diff --git a/lib/node_type.c b/lib/node_type.c index b5a47401a..7dea2af57 100644 --- a/lib/node_type.c +++ b/lib/node_type.c @@ -17,7 +17,7 @@ int node_type_start(struct node_type *vt, struct super_node *sn) { int ret; - if (vt->state != STATE_STARTED) + if (vt->state != STATE_DESTROYED) return 0; info("Initializing " YEL("%s") " node type which is used by %zu nodes", plugin_name(vt), list_length(&vt->instances)); @@ -40,7 +40,7 @@ int node_type_stop(struct node_type *vt) info("De-initializing " YEL("%s") " node type", plugin_name(vt)); { INDENT - ret = vt->deinit ? vt->deinit() : -1; + ret = vt->deinit ? vt->deinit() : 0; } if (ret == 0) diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 2b2c374a8..7ed72305c 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -34,7 +34,7 @@ static struct plugin p; /* Private static storage */ -struct list interfaces; +struct list interfaces = { .state = STATE_DESTROYED }; int socket_init(struct super_node *sn) { @@ -71,7 +71,7 @@ int socket_init(struct super_node *sn) } /* If not found, create a new interface */ - struct interface j; + struct interface j = { .sockets.state = STATE_DESTROYED }; ret = if_init(&j, link); if (ret) @@ -94,7 +94,7 @@ found: list_push(&i->sockets, s); int socket_deinit() { - for (size_t j = 0; list_length(&interfaces); j++) { + for (size_t j = 0; j < list_length(&interfaces); j++) { struct interface *i = list_at(&interfaces, j); if_stop(i); diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index ce25b2c87..aa471c4fe 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -22,7 +22,7 @@ #include "nodes/websocket.h" /* Private static storage */ -struct list connections; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */ +static struct list connections = { .state = STATE_DESTROYED }; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */ /* Forward declarations */ static struct plugin p; diff --git a/lib/path.c b/lib/path.c index e6807eb0c..b6711c964 100644 --- a/lib/path.c +++ b/lib/path.c @@ -54,8 +54,9 @@ static void path_read(struct path *p) enqueue = hook_read_list(&p->hooks, smps, recv); if (enqueue != recv) { info("Hooks skipped %u out of %u samples for path %s", recv - enqueue, recv, path_name(p)); - - stats_update(p->stats->delta, STATS_SKIPPED, recv - enqueue); + + if (p->stats) + stats_update(p->stats->delta, STATS_SKIPPED, recv - enqueue); } for (size_t i = 0; i < list_length(&p->destinations); i++) { @@ -336,6 +337,9 @@ int path_start(struct path *p) int path_stop(struct path *p) { int ret; + + if (p->state != STATE_STARTED) + return 0; info("Stopping path: %s", path_name(p)); diff --git a/lib/super_node.c b/lib/super_node.c index 828289236..55959842f 100644 --- a/lib/super_node.c +++ b/lib/super_node.c @@ -331,7 +331,7 @@ int super_node_start(struct super_node *sn) for (size_t i = 0; i < list_length(&sn->nodes); i++) { INDENT struct node *n = list_at(&sn->nodes, i); - node_type_start(n->_vt, sn->cli.argc, sn->cli.argv, config_root_setting(&sn->cfg)); + node_type_start(n->_vt, sn); } info("Starting nodes"); @@ -364,28 +364,35 @@ int super_node_start(struct super_node *sn) int super_node_stop(struct super_node *sn) { - if (sn->state != STATE_STARTED) - return 0; + int ret; info("Stopping paths"); for (size_t i = 0; i < list_length(&sn->paths); i++) { INDENT struct path *p = list_at(&sn->paths, i); - path_stop(p); + ret = path_stop(p); + if (ret) + error("Failed to stop path: %s", path_name(p)); } info("Stopping nodes"); for (size_t i = 0; i < list_length(&sn->nodes); i++) { INDENT struct node *n = list_at(&sn->nodes, i); - node_stop(n); + ret = node_stop(n); + if (ret) + error("Failed to stop node: %s", node_name(n)); } info("Stopping node types"); for (size_t i = 0; i < list_length(&plugins); i++) { INDENT struct plugin *p = list_at(&plugins, i); - if (p->type == PLUGIN_TYPE_NODE) - node_type_stop(&p->node); + + if (p->type == PLUGIN_TYPE_NODE) { + ret = node_type_stop(&p->node); + if (ret) + error("Failed to stop node-type: %s", plugin_name(p)); + } } web_stop(&sn->web);