summaryrefslogtreecommitdiffstats
path: root/ctrl/facemgr/src
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-11-05 12:28:49 +0000
committerGerrit Code Review <gerrit@fd.io>2019-11-05 12:28:49 +0000
commit8adda70cd102a3ea5d91a72aecfde7107dd0c807 (patch)
tree7fcf5a6644d51ce1ab459fe2bd2888aea39c7b51 /ctrl/facemgr/src
parent9793bd7849975399ca103480ab946669888080a8 (diff)
parent29bb779084d76fb31e1b5dfbf54995918d02fc0e (diff)
Merge "[HICN-372] Code clean up"
Diffstat (limited to 'ctrl/facemgr/src')
-rw-r--r--ctrl/facemgr/src/api.c13
-rw-r--r--ctrl/facemgr/src/interface.c20
-rw-r--r--ctrl/facemgr/src/interface.h2
-rw-r--r--ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c1
-rw-r--r--ctrl/facemgr/src/interfaces/updown/updown.c12
-rw-r--r--ctrl/facemgr/src/main.c1
-rw-r--r--ctrl/facemgr/src/util/map.h4
7 files changed, 32 insertions, 21 deletions
diff --git a/ctrl/facemgr/src/api.c b/ctrl/facemgr/src/api.c
index 19f211dbf..f0ae15b62 100644
--- a/ctrl/facemgr/src/api.c
+++ b/ctrl/facemgr/src/api.c
@@ -1622,28 +1622,29 @@ facemgr_bootstrap(facemgr_t * facemgr)
/* FIXME facemgr_delete_interface */
#ifdef WITH_EXAMPLE_UPDOWN
- interface_free(facemgr->updown);
+ facemgr_delete_interface(facemgr, facemgr->updown);
ERR_UPDOWN_CREATE:
#endif
#ifdef WITH_EXAMPLE_DUMMY
- interface_free(facemgr->dummy);
+ facemgr_delete_interface(facemgr, facemgr->dummy);
ERR_DUMMY_CREATE:
#endif
#ifdef __ANDROID__
- interface_free(facemgr->au);
+ facemgr_delete_interface(facemgr, facemgr->au);
ERR_AU_CREATE:
#endif /* __ANDROID__ */
#ifdef __linux__
- interface_free(facemgr->nl);
+ facemgr_delete_interface(facemgr, facemgr->nl);
ERR_NL_CREATE:
#endif /* __linux__ */
#ifdef __APPLE__
- interface_free(facemgr->nf);
+ facemgr_delete_interface(facemgr, facemgr->nf);
ERR_NF_CREATE:
#endif /* __APPLE__ */
- interface_free(facemgr->hl);
+ facemgr_delete_interface(facemgr, facemgr->hl);
ERR_HL_CREATE:
ERR_REGISTER:
+ interface_unregister_all();
return -1;
}
diff --git a/ctrl/facemgr/src/interface.c b/ctrl/facemgr/src/interface.c
index 72a78ef56..d592bf04c 100644
--- a/ctrl/facemgr/src/interface.c
+++ b/ctrl/facemgr/src/interface.c
@@ -53,19 +53,21 @@ interface_unregister_all()
int n = interface_ops_map_get_key_array(interface_ops_map, &ops_name_array);
if (n < 0) {
ERROR("[interface_unregister_all] Could not get interface ops array");
- ret = -1;
- } else {
- for (unsigned i = 0; i < n; i++) {
- const char * ops_name = ops_name_array[i];
- if (interface_ops_map_remove(interface_ops_map, ops_name, NULL) < 0) {
- ERROR("[interface_unregister_all] Could not remove %s from interface ops map", ops_name);
- ret = -1;
- }
+ return -1;
+ }
+
+ for (unsigned i = 0; i < n; i++) {
+ const char * ops_name = ops_name_array[i];
+ if (interface_ops_map_remove(interface_ops_map, ops_name, NULL) < 0) {
+ ERROR("[interface_unregister_all] Could not remove %s from interface ops map", ops_name);
+ ret = -1;
}
- free(ops_name_array);
}
+ free(ops_name_array);
+
interface_ops_map_free(interface_ops_map);
interface_ops_map = NULL;
+
return ret;
}
diff --git a/ctrl/facemgr/src/interface.h b/ctrl/facemgr/src/interface.h
index 0ebe8c7c8..627a3645e 100644
--- a/ctrl/facemgr/src/interface.h
+++ b/ctrl/facemgr/src/interface.h
@@ -77,6 +77,8 @@ typedef struct interface_s {
*/
int interface_register(const interface_ops_t * ops);
+int interface_unregister_all();
+
/**
* \brief Unregister all interface types
*/
diff --git a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c
index e8f168706..82d4a7e6e 100644
--- a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c
+++ b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c
@@ -242,7 +242,6 @@ int hl_on_event(interface_t * interface, const facelet_t * facelet)
if (!data->s) {
/* We are not connected to the forwarder */
goto ERR;
-
}
switch(facelet_get_event(facelet)) {
diff --git a/ctrl/facemgr/src/interfaces/updown/updown.c b/ctrl/facemgr/src/interfaces/updown/updown.c
index 6a7ab83f4..b804cdac1 100644
--- a/ctrl/facemgr/src/interfaces/updown/updown.c
+++ b/ctrl/facemgr/src/interfaces/updown/updown.c
@@ -53,7 +53,7 @@ int updown_initialize(interface_t * interface, void * cfg)
data->fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (data->fd == -1) {
perror("socket error");
- return -1;
+ goto ERR_SOCKET;
}
memset(&addr, 0, sizeof(addr));
@@ -67,7 +67,7 @@ int updown_initialize(interface_t * interface, void * cfg)
if (connect(data->fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
perror("connect error");
- return -1;
+ goto ERR_CONNECT;
}
if (interface_register_fd(interface, data->fd, NULL) < 0) {
@@ -77,6 +77,11 @@ int updown_initialize(interface_t * interface, void * cfg)
return 0;
+ERR_FD:
+ERR_CONNECT:
+ close(data->fd);
+ERR_SOCKET:
+ free(data);
ERR_MALLOC:
return -1;
}
@@ -87,11 +92,12 @@ int updown_finalize(interface_t * interface)
if (data->fd > 0)
close(data->fd);
+ free(data);
return 0;
}
-int updown_callback(interface_t * interface)
+int updown_callback(interface_t * interface, int fd, void * unused)
{
updown_data_t * data = (updown_data_t*)interface->data;
char buf[100];
diff --git a/ctrl/facemgr/src/main.c b/ctrl/facemgr/src/main.c
index 9eba2aa0c..b7bd6c6cd 100644
--- a/ctrl/facemgr/src/main.c
+++ b/ctrl/facemgr/src/main.c
@@ -246,6 +246,7 @@ MAIN_LOOP:
ERR_BOOTSTRAP:
facemgr_free(facemgr);
+ loop_free(loop);
ERR_FACEMGR_CONFIG:
ERR_FACEMGR:
ERR_PARSE:
diff --git a/ctrl/facemgr/src/util/map.h b/ctrl/facemgr/src/util/map.h
index 19a308d86..adab8d758 100644
--- a/ctrl/facemgr/src/util/map.h
+++ b/ctrl/facemgr/src/util/map.h
@@ -219,7 +219,7 @@ NAME ## _get_key_array(NAME ## _t * map, KEY_T **array) {
for (int i = 0; i < n; i++) \
(*array)[i] = pair_array[i]->key; \
free(pair_array); \
- return 0; \
+ return n; \
} \
\
int \
@@ -238,7 +238,7 @@ NAME ## _get_value_array(NAME ## _t * map, VAL_T **array) {
for (int i = 0; i < n; i++) \
(*array)[i] = pair_array[i]->value; \
free(pair_array); \
- return 0; \
+ return n; \
}
#endif /* UTIL_MAP_H */