diff --git a/include/villas/hist.h b/include/villas/hist.h index c68a066c5..f56476abc 100644 --- a/include/villas/hist.h +++ b/include/villas/hist.h @@ -10,11 +10,9 @@ #include #include -#include "config.h" +#include -#ifdef WITH_JANSSON - #include -#endif +#include "config.h" #define HIST_HEIGHT (LOG_WIDTH - 55) #define HIST_SEQ 17 diff --git a/include/villas/log.h b/include/villas/log.h index 4b8afb4fd..59432d127 100644 --- a/include/villas/log.h +++ b/include/villas/log.h @@ -72,7 +72,8 @@ struct log { int level; /** Debug facilities used by the debug() macro. */ - int facilities; + long facilities; + }; /** Initialize log object */ diff --git a/include/villas/path.h b/include/villas/path.h index 5c090fea8..1efebe1a5 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -54,19 +54,19 @@ struct path struct path_source *source; /**< Pointer to the incoming node */ struct list destinations; /**< List of all outgoing nodes (struct path_destination). */ - struct list hooks; /**< List of function pointers to hooks */ + struct list hooks; /**< List of function pointers to hooks. */ - int enabled; /**< Is this path enabled */ - int reverse; /**< This path as a matching reverse path */ + int enabled; /**< Is this path enabled. */ + int reverse; /**< This path as a matching reverse path. */ - pthread_t tid; /**< The thread id for this path */ + pthread_t tid; /**< The thread id for this path. */ char *_name; /**< Singleton: A string which is used to print this path to screen. */ struct stats *stats; /**< Statistic counters. This is a pointer to the statistic hooks private data. */ struct super_node *super_node; /**< The super node this path belongs to. */ - config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this path */ + config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this path. */ }; /** Initialize internal data structures. */ diff --git a/include/villas/plugin.h b/include/villas/plugin.h index 67a2fb833..f719e7f48 100644 --- a/include/villas/plugin.h +++ b/include/villas/plugin.h @@ -62,7 +62,7 @@ struct plugin { #define plugin_name(vt) plugin(vt)->name #define plugin_description(vt) plugin(vt)->description -int plugin_init(struct plugin *p, char *name, char *path); +int plugin_init(struct plugin *p); int plugin_destroy(struct plugin *p); diff --git a/lib/node.c b/lib/node.c index 407e39456..df37b6e9b 100644 --- a/lib/node.c +++ b/lib/node.c @@ -81,10 +81,11 @@ int node_start(struct node *n) info("Starting node %s", node_name_long(n)); { INDENT ret = n->_vt->start ? n->_vt->start(n) : -1; + if (ret) + return ret; } - - if (ret == 0) - n->state = STATE_STARTED; + + n->state = STATE_STARTED; n->sequence = 0; diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 76460f362..1b0bcbd4a 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -46,9 +46,6 @@ int socket_init(int argc, char *argv[], config_setting_t *cfg) /* Gather list of used network interfaces */ list_foreach(struct node *n, &p.node.instances) { - if (n->state != STATE_INITIALIZED) - continue; - struct socket *s = n->_vd; struct rtnl_link *link; diff --git a/lib/path.c b/lib/path.c index f9cb2b317..58af4a5b5 100644 --- a/lib/path.c +++ b/lib/path.c @@ -221,12 +221,12 @@ int path_parse(struct path *p, config_setting_t *cfg, struct list *nodes) if (n->_vt->write == NULL) cerror(cfg_out, "Output node '%s' is not supported as a destination.", node_name(n)); - struct path_destination *pd = alloc(sizeof(struct path_destination)); + struct path_destination pd; - pd->node = n; - pd->queuelen = queuelen; + pd.node = n; + pd.queuelen = queuelen; - list_push(&p->destinations, pd); + list_push(&p->destinations, memdup(&pd, sizeof(pd))); } list_destroy(&destinations, NULL, false); @@ -236,7 +236,9 @@ int path_parse(struct path *p, config_setting_t *cfg, struct list *nodes) int path_check(struct path *p) { - list_foreach (struct node *n, &p->destinations) { + assert(p->state != STATE_DESTROYED); + + list_foreach(struct node *n, &p->destinations) { if (!n->_vt->write) error("Destiation node '%s' is not supported as a sink for path '%s'", node_name(n), path_name(p)); } @@ -296,13 +298,13 @@ int path_start(struct path *p) assert(p->state == STATE_CHECKED); - info("Starting path: %s (#hooks=%zu)", - path_name(p), list_length(&p->hooks)); + info("Starting path: %s (#hooks=%zu)", path_name(p), list_length(&p->hooks)); ret = hook_run(p, NULL, 0, HOOK_PATH_START); if (ret) return ret; - + + /* Start one thread per path for sending to destinations */ ret = pthread_create(&p->tid, NULL, &path_run, p); if (ret) return ret; diff --git a/lib/plugin.c b/lib/plugin.c index c5c86e251..e0b462ba8 100644 --- a/lib/plugin.c +++ b/lib/plugin.c @@ -11,16 +11,26 @@ /** Global list of all known plugins */ struct list plugins = LIST_INIT(); -int plugin_init(struct plugin *p, char *name, char *path) +int plugin_init(struct plugin *p) { - p->name = strdup(name); - p->path = strdup(path); + assert(p->state == STATE_DESTROYED); p->state = STATE_INITIALIZED; return 0; } +int plugin_parse(struct plugin *p, config_setting_t *cfg) +{ + const char *path; + + path = config_setting_get_string(cfg); + if (!path) + cerror(cfg, "Setting 'plugin' must be a string."); + + return 0; +} + int plugin_load(struct plugin *p) { p->handle = dlopen(p->path, RTLD_NOW); @@ -57,17 +67,6 @@ int plugin_destroy(struct plugin *p) return 0; } -int plugin_parse(struct plugin *p, config_setting_t *cfg) -{ - const char *path; - - path = config_setting_get_string(cfg); - if (!path) - cerror(cfg, "Setting 'plugin' must be a string."); - - return 0; -} - struct plugin * plugin_lookup(enum plugin_type type, const char *name) { list_foreach(struct plugin *l, &plugins) { diff --git a/lib/super_node.c b/lib/super_node.c index 1203e1489..ba1aabe64 100644 --- a/lib/super_node.c +++ b/lib/super_node.c @@ -182,7 +182,11 @@ int super_node_parse(struct super_node *sn, config_setting_t *cfg) for (int i = 0; i < config_setting_length(cfg_plugins); i++) { struct config_setting_t *cfg_plugin = config_setting_get_elem(cfg_plugins, i); - struct plugin plugin; + struct plugin plugin = { .state = STATE_DESTROYED }; + + ret = plugin_init(&plugin); + if (ret) + cerror(cfg_plugin, "Failed to initialize plugin"); ret = plugin_parse(&plugin, cfg_plugin); if (ret) @@ -207,23 +211,24 @@ int super_node_parse(struct super_node *sn, config_setting_t *cfg) /* Required settings */ if (!config_setting_lookup_string(cfg_node, "type", &type)) cerror(cfg_node, "Missing node type"); - - + p = plugin_lookup(PLUGIN_TYPE_NODE, type); if (!p) cerror(cfg_node, "Invalid node type: %s", type); - - struct node n = { .state = STATE_DESTROYED }; + + struct node *n = alloc(sizeof(struct node)); - ret = node_init(&n, &p->node); + n->state = STATE_DESTROYED; + + ret = node_init(n, &p->node); if (ret) cerror(cfg_node, "Failed to initialize node"); - ret = node_parse(&n, cfg_node); + ret = node_parse(n, cfg_node); if (ret) cerror(cfg_node, "Failed to parse node"); - list_push(&sn->nodes, memdup(&n, sizeof(n))); + list_push(&sn->nodes, n); } } diff --git a/lib/web.c b/lib/web.c index 3c1ea68d1..484bd736d 100644 --- a/lib/web.c +++ b/lib/web.c @@ -124,8 +124,6 @@ static void logger(int level, const char *msg) { int web_init(struct web *w, struct api *a) { - info("Initialize web sub-system"); - lws_set_log_level((1 << LLL_COUNT) - 1, logger); w->api = a;