diff --git a/include/node.h b/include/node.h index 185b51e9b..d86695d34 100644 --- a/include/node.h +++ b/include/node.h @@ -185,13 +185,13 @@ struct node * * @see node_type::init */ -int node_init(int argc, char *argv[], config_setting_t *cfg); +int node_init(struct node_type *vt, int argc, char *argv[], config_setting_t *cfg); /** De-initialize node type subsystems. * * @see node_type::deinit */ -int node_deinit(); +int node_deinit(struct node_type *vt); /** Create a node by allocating dynamic memory. * diff --git a/lib/node.c b/lib/node.c index ee26780bc..2855941c7 100644 --- a/lib/node.c +++ b/lib/node.c @@ -30,33 +30,28 @@ int node_write(struct node *n, struct msg *p, int ps, int f, int c) return n->_vt->write ? n->_vt->write(n, p, ps, f, c) : -1; } -int node_init(int argc, char *argv[], config_setting_t *cfg) +int node_init(struct node_type *vt, int argc, char *argv[], config_setting_t *cfg) { - list_foreach(const struct node_type *vt, &node_types) { - if (list_length(&vt->instances) > 0) { - info("Initializing " YEL("%s") " node type", vt->name); + if (list_length(&vt->instances) > 0) { + info("Initializing " YEL("%s") " node type", vt->name); - if (vt->init) { INDENT - vt->init(argc, argv, cfg); - } + if (vt->init) { INDENT + vt->init(argc, argv, cfg); } - else - warn("No node is using the " YEL("%s") " node type. Skipping...", vt->name); } + else + warn("No node is using the " YEL("%s") " node type. Skipping...", vt->name); return 0; } -int node_deinit() +int node_deinit(struct node_type *vt) { - /* De-initialize node types */ - list_foreach(const struct node_type *vt, &node_types) { - if (list_length(&vt->instances) > 0) { - info("De-initializing " YEL("%s") " node type", vt->name); + if (list_length(&vt->instances) > 0) { + info("De-initializing " YEL("%s") " node type", vt->name); - if (vt->deinit) { INDENT - vt->deinit(); - } + if (vt->deinit) { INDENT + vt->deinit(); } } diff --git a/src/pipe.c b/src/pipe.c index c57b669b9..62e89abfb 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -41,7 +41,7 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx) pthread_join(send_thread, NULL); node_stop(node); - node_deinit(); + node_deinit(node->_vt); free(recv_pool); free(send_pool); @@ -158,7 +158,7 @@ int main(int argc, char *argv[]) if (!node) error("Node '%s' does not exist!", argv[2]); - node_init(argc-optind, argv+optind, config_root_setting(&config)); + node_init(node->_vt, argc-optind, argv+optind, config_root_setting(&config)); recv_pool = alloc(sizeof(struct msg) * node->combine); send_pool = alloc(sizeof(struct msg) * node->combine); diff --git a/src/server.c b/src/server.c index ee4b654a2..e8421dbb2 100644 --- a/src/server.c +++ b/src/server.c @@ -42,8 +42,8 @@ static void quit() } info("De-initializing node types"); - { INDENT - node_deinit(); + list_foreach(struct node_type *vt, &node_types) { INDENT + node_deinit(vt); } /* Freeing dynamically allocated memory */ @@ -161,8 +161,8 @@ int main(int argc, char *argv[]) } info("Initialize node types"); - { INDENT - node_init(argc, argv, config_root_setting(&config)); + list_foreach(struct node_type *vt, &node_types) { INDENT + node_init(vt, argc, argv, config_root_setting(&config)); } info("Starting nodes"); diff --git a/src/test.c b/src/test.c index ebae5e062..174ed1bc4 100644 --- a/src/test.c +++ b/src/test.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) if (!node) error("There's no node with the name '%s'", argv[3]); - node_init(argc-3, argv+3, config_root_setting(&config)); + node_init(node->_vt, argc-3, argv+3, config_root_setting(&config)); node_start(node); /* Parse Arguments */ @@ -138,7 +138,7 @@ check: error("Unknown test: '%s'", argv[2]); node_stop(node); - node_deinit(); + node_deinit(node->_vt); config_destroy(&config); return 0;