projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'collectd-5.8'
[collectd.git]
/
src
/
utils_ovs.c
diff --git
a/src/utils_ovs.c
b/src/utils_ovs.c
index
e9e841e
..
2df9f2b
100644
(file)
--- a/
src/utils_ovs.c
+++ b/
src/utils_ovs.c
@@
-263,12
+263,11
@@
static void ovs_db_callback_remove(ovs_db_t *pdb, ovs_callback_t *del_cb) {
/* Remove all callbacks form OVS DB object */
static void ovs_db_callback_remove_all(ovs_db_t *pdb) {
pthread_mutex_lock(&pdb->mutex);
/* Remove all callbacks form OVS DB object */
static void ovs_db_callback_remove_all(ovs_db_t *pdb) {
pthread_mutex_lock(&pdb->mutex);
- for (ovs_callback_t *del_cb = pdb->remote_cb; pdb->remote_cb;
- del_cb = pdb->remote_cb) {
+ while (pdb->remote_cb != NULL) {
+ ovs_callback_t *del_cb = pdb->remote_cb;
pdb->remote_cb = del_cb->next;
pdb->remote_cb = del_cb->next;
- free(del_cb);
+
s
free(del_cb);
}
}
- pdb->remote_cb = NULL;
pthread_mutex_unlock(&pdb->mutex);
}
pthread_mutex_unlock(&pdb->mutex);
}
@@
-751,17
+750,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 */
ovs_db_event_post(pdb, OVS_DB_EVENT_CONN_ESTABLISHED);
} else {
/* send notification to event thread */
ovs_db_event_post(pdb, OVS_DB_EVENT_CONN_ESTABLISHED);
@@
-796,12
+792,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
+821,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;
@@
-935,6
+928,7
@@
static int ovs_db_event_thread_init(ovs_db_t *pdb) {
}
/* Destroy EVENT thread */
}
/* Destroy EVENT thread */
+/* XXX: Must hold pdb->mutex when calling! */
static int ovs_db_event_thread_destroy(ovs_db_t *pdb) {
if (pthread_equal(pdb->event_thread.tid, (pthread_t){0})) {
/* already destroyed */
static int ovs_db_event_thread_destroy(ovs_db_t *pdb) {
if (pthread_equal(pdb->event_thread.tid, (pthread_t){0})) {
/* already destroyed */
@@
-974,6
+968,7
@@
static int ovs_db_poll_thread_init(ovs_db_t *pdb) {
}
/* Destroy POLL thread */
}
/* Destroy POLL thread */
+/* XXX: Must hold pdb->mutex when calling! */
static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
if (pthread_equal(pdb->poll_thread.tid, (pthread_t){0})) {
/* already destroyed */
static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
if (pthread_equal(pdb->poll_thread.tid, (pthread_t){0})) {
/* already destroyed */
@@
-1002,9
+997,10
@@
ovs_db_t *ovs_db_init(const char *node, const char *service,
return NULL;
/* allocate db data & fill it */
return NULL;
/* allocate db data & fill it */
- ovs_db_t *pdb =
pdb =
calloc(1, sizeof(*pdb));
+ ovs_db_t *pdb = calloc(1, sizeof(*pdb));
if (pdb == NULL)
return NULL;
if (pdb == NULL)
return NULL;
+ pdb->sock = -1;
/* store the OVS DB address */
sstrncpy(pdb->node, node, sizeof(pdb->node));
/* store the OVS DB address */
sstrncpy(pdb->node, node, sizeof(pdb->node));
@@
-1046,7
+1042,6
@@
ovs_db_t *ovs_db_init(const char *node, const char *service,
}
/* init polling thread */
}
/* init polling thread */
- pdb->sock = -1;
if (ovs_db_poll_thread_init(pdb) < 0) {
ovs_db_destroy(pdb);
return NULL;
if (ovs_db_poll_thread_init(pdb) < 0) {
ovs_db_destroy(pdb);
return NULL;
@@
-1261,13
+1256,13
@@
int ovs_db_destroy(ovs_db_t *pdb) {
/* stop poll thread */
if (ovs_db_event_thread_destroy(pdb) < 0) {
OVS_ERROR("destroy poll thread failed");
/* stop poll thread */
if (ovs_db_event_thread_destroy(pdb) < 0) {
OVS_ERROR("destroy poll thread failed");
- ovs_db_ret =
(-1)
;
+ ovs_db_ret =
-1
;
}
/* stop event thread */
if (ovs_db_poll_thread_destroy(pdb) < 0) {
OVS_ERROR("stop event thread failed");
}
/* stop event thread */
if (ovs_db_poll_thread_destroy(pdb) < 0) {
OVS_ERROR("stop event thread failed");
- ovs_db_ret =
(-1)
;
+ ovs_db_ret =
-1
;
}
pthread_mutex_unlock(&pdb->mutex);
}
pthread_mutex_unlock(&pdb->mutex);