projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tcpconns: remove redundant include
[collectd.git]
/
src
/
utils_ovs.c
diff --git
a/src/utils_ovs.c
b/src/utils_ovs.c
index
4f48755
..
57629a0
100644
(file)
--- a/
src/utils_ovs.c
+++ b/
src/utils_ovs.c
@@
-209,7
+209,7
@@
static void ovs_db_event_post(ovs_db_t *pdb, int event) {
/* Check if POLL thread is still running. Returns
* 1 if running otherwise 0 is returned */
/* Check if POLL thread is still running. Returns
* 1 if running otherwise 0 is returned */
-static
_B
ool ovs_db_poll_is_running(ovs_db_t *pdb) {
+static
b
ool ovs_db_poll_is_running(ovs_db_t *pdb) {
int state = 0;
pthread_mutex_lock(&pdb->poll_thread.mutex);
state = pdb->poll_thread.state;
int state = 0;
pthread_mutex_lock(&pdb->poll_thread.mutex);
state = pdb->poll_thread.state;
@@
-560,7
+560,7
@@
static int ovs_db_json_data_process(ovs_db_t *pdb, const char *data,
return -1;
sstrncpy(sjson, data, len + 1);
return -1;
sstrncpy(sjson, data, len + 1);
- OVS_DEBUG("[len=%
zu
] %s", len, sjson);
+ OVS_DEBUG("[len=%
" PRIsz "
] %s", len, sjson);
/* parse json data */
jnode = yajl_tree_parse(sjson, yajl_errbuf, sizeof(yajl_errbuf));
/* parse json data */
jnode = yajl_tree_parse(sjson, yajl_errbuf, sizeof(yajl_errbuf));
@@
-751,17
+751,14
@@
static void ovs_db_reconnect(ovs_db_t *pdb) {
}
/* try to connect to the server */
for (struct addrinfo *rp = result; rp != NULL; rp = rp->ai_next) {
}
/* try to connect to the server */
for (struct addrinfo *rp = result; rp != NULL; rp = rp->ai_next) {
- char errbuff[OVS_ERROR_BUFF_SIZE];
int sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sock < 0) {
int sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sock < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_DEBUG("socket(): %s", errbuff);
+ OVS_DEBUG("socket(): %s", STRERRNO);
continue;
}
if (connect(sock, rp->ai_addr, rp->ai_addrlen) < 0) {
close(sock);
continue;
}
if (connect(sock, rp->ai_addr, rp->ai_addrlen) < 0) {
close(sock);
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_DEBUG("connect(): %s [family=%d]", errbuff, rp->ai_family);
+ OVS_DEBUG("connect(): %s [family=%d]", STRERRNO, rp->ai_family);
} else {
/* send notification to event thread */
pdb->sock = sock;
} else {
/* send notification to event thread */
pdb->sock = sock;
@@
-796,12
+793,10
@@
static void *ovs_poll_worker(void *arg) {
/* poll data */
while (ovs_db_poll_is_running(pdb)) {
/* poll data */
while (ovs_db_poll_is_running(pdb)) {
- char errbuff[OVS_ERROR_BUFF_SIZE];
poll_fd.fd = pdb->sock;
int poll_ret = poll(&poll_fd, 1, /* ms */ OVS_DB_POLL_TIMEOUT * 1000);
if (poll_ret < 0) {
poll_fd.fd = pdb->sock;
int poll_ret = poll(&poll_fd, 1, /* ms */ OVS_DB_POLL_TIMEOUT * 1000);
if (poll_ret < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_ERROR("poll(): %s", errbuff);
+ OVS_ERROR("poll(): %s", STRERRNO);
break;
} else if (poll_ret == 0) {
OVS_DEBUG("poll(): timeout");
break;
} else if (poll_ret == 0) {
OVS_DEBUG("poll(): timeout");
@@
-827,8
+822,7
@@
static void *ovs_poll_worker(void *arg) {
char buff[OVS_DB_POLL_READ_BLOCK_SIZE];
ssize_t nbytes = recv(poll_fd.fd, buff, sizeof(buff), 0);
if (nbytes < 0) {
char buff[OVS_DB_POLL_READ_BLOCK_SIZE];
ssize_t nbytes = recv(poll_fd.fd, buff, sizeof(buff), 0);
if (nbytes < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_ERROR("recv(): %s", errbuff);
+ OVS_ERROR("recv(): %s", STRERRNO);
/* read error? Try to reconnect */
close(poll_fd.fd);
continue;
/* read error? Try to reconnect */
close(poll_fd.fd);
continue;
@@
-1007,6
+1001,8
@@
static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
ovs_db_t *ovs_db_init(const char *node, const char *service,
const char *unix_path, ovs_db_callback_t *cb) {
ovs_db_t *ovs_db_init(const char *node, const char *service,
const char *unix_path, ovs_db_callback_t *cb) {
+ int ret;
+
/* sanity check */
if (node == NULL || service == NULL || unix_path == NULL)
return NULL;
/* sanity check */
if (node == NULL || service == NULL || unix_path == NULL)
return NULL;
@@
-1052,16
+1048,25
@@
ovs_db_t *ovs_db_init(const char *node, const char *service,
/* init event thread */
if (ovs_db_event_thread_init(pdb) < 0) {
/* init event thread */
if (ovs_db_event_thread_init(pdb) < 0) {
- ovs_db_destroy(pdb);
- return NULL;
+ ret = ovs_db_destroy(pdb);
+ if (ret > 0)
+ goto failure;
}
/* init polling thread */
if (ovs_db_poll_thread_init(pdb) < 0) {
}
/* init polling thread */
if (ovs_db_poll_thread_init(pdb) < 0) {
- ovs_db_destroy(pdb);
- return NULL;
+ ret = ovs_db_destroy(pdb);
+ if (ret > 0) {
+ ovs_db_event_thread_data_destroy(pdb);
+ goto failure;
+ }
}
return pdb;
}
return pdb;
+
+failure:
+ pthread_mutex_destroy(&pdb->mutex);
+ sfree(pdb);
+ return NULL;
}
int ovs_db_send_request(ovs_db_t *pdb, const char *method, const char *params,
}
int ovs_db_send_request(ovs_db_t *pdb, const char *method, const char *params,
@@
-1271,7
+1276,7
@@
int ovs_db_destroy(ovs_db_t *pdb) {
/* try to lock the structure before releasing */
if ((ret = pthread_mutex_lock(&pdb->mutex))) {
OVS_ERROR("pthread_mutex_lock() DB mutex lock failed (%d)", ret);
/* try to lock the structure before releasing */
if ((ret = pthread_mutex_lock(&pdb->mutex))) {
OVS_ERROR("pthread_mutex_lock() DB mutex lock failed (%d)", ret);
- return
-1
;
+ return
ret
;
}
/* stop poll thread and destroy thread's private data */
}
/* stop poll thread and destroy thread's private data */
@@
-1370,15
+1375,18
@@
yajl_val ovs_utils_get_map_value(yajl_val jval, const char *key) {
/* check first element of the array */
str_val = YAJL_GET_STRING(array_values[0]);
/* check first element of the array */
str_val = YAJL_GET_STRING(array_values[0]);
- if (strcmp("map", str_val) != 0)
+ if (str
_val == NULL || str
cmp("map", str_val) != 0)
return NULL;
/* try to find map value by map key */
return NULL;
/* try to find map value by map key */
+ if (YAJL_GET_ARRAY(array_values[1]) == NULL)
+ return NULL;
+
map_len = YAJL_GET_ARRAY(array_values[1])->len;
map_values = YAJL_GET_ARRAY(array_values[1])->values;
for (size_t i = 0; i < map_len; i++) {
/* check YAJL array */
map_len = YAJL_GET_ARRAY(array_values[1])->len;
map_values = YAJL_GET_ARRAY(array_values[1])->values;
for (size_t i = 0; i < map_len; i++) {
/* check YAJL array */
- if (!YAJL_IS_ARRAY(map_values[i]))
+ if (!YAJL_IS_ARRAY(map_values[i])
|| YAJL_GET_ARRAY(map_values[i]) == NULL
)
break;
/* check a database pair value (2-element, first one represents a key
break;
/* check a database pair value (2-element, first one represents a key
@@
-1390,7
+1398,7
@@
yajl_val ovs_utils_get_map_value(yajl_val jval, const char *key) {
/* return map value if given key equals map key */
str_val = YAJL_GET_STRING(array_values[0]);
/* return map value if given key equals map key */
str_val = YAJL_GET_STRING(array_values[0]);
- if (strcmp(key, str_val) == 0)
+ if (str
_val != NULL && str
cmp(key, str_val) == 0)
return array_values[1];
}
return NULL;
return array_values[1];
}
return NULL;