projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
41d355d
)
snake case for iface list + payload simplification
author
Andrew Bays
<abays@redhat.com>
Thu, 1 Feb 2018 20:13:15 +0000
(15:13 -0500)
committer
Andrew Bays
<andrew.bays@gmail.com>
Thu, 5 Sep 2019 13:21:22 +0000
(09:21 -0400)
src/connectivity.c
patch
|
blob
|
history
diff --git
a/src/connectivity.c
b/src/connectivity.c
index
cb0ed98
..
8cacf3b
100644
(file)
--- a/
src/connectivity.c
+++ b/
src/connectivity.c
@@
-93,7
+93,7
@@
/*
* Private data types
*/
/*
* Private data types
*/
-struct interfacelist_s {
+struct interface
_
list_s {
char *interface;
uint32_t status;
char *interface;
uint32_t status;
@@
-101,14
+101,14
@@
struct interfacelist_s {
uint32_t sent;
long long unsigned int timestamp;
uint32_t sent;
long long unsigned int timestamp;
- struct interfacelist_s *next;
+ struct interface
_
list_s *next;
};
};
-typedef struct interface
list_s interface
list_t;
+typedef struct interface
_list_s interface_
list_t;
/*
* Private variables
*/
/*
* Private variables
*/
-static interface
list_t *interface
list_head = NULL;
+static interface
_list_t *interface_
list_head = NULL;
static int connectivity_thread_loop = 0;
static int connectivity_thread_error = 0;
static int connectivity_thread_loop = 0;
static int connectivity_thread_error = 0;
@@
-129,6
+129,7
@@
static int gen_message_payload(int state, int old_state, const char *interface,
long long unsigned int timestamp, char **buf) {
const unsigned char *buf2;
yajl_gen g;
long long unsigned int timestamp, char **buf) {
const unsigned char *buf2;
yajl_gen g;
+ char json_str[DATA_MAX_NAME_LEN];
#if !defined(HAVE_YAJL_V2)
yajl_gen_config conf = {};
#if !defined(HAVE_YAJL_V2)
yajl_gen_config conf = {};
@@
-169,17
+170,13
@@
static int gen_message_payload(int state, int old_state, const char *interface,
event_id = event_id + 1;
int event_id_len = sizeof(char) * sizeof(int) * 4 + 1;
event_id = event_id + 1;
int event_id_len = sizeof(char) * sizeof(int) * 4 + 1;
-
char *event_id_str = malloc(event_id_len
);
- snprintf(
event_id
_str, event_id_len, "%d", event_id);
+
memset(json_str, '\0', DATA_MAX_NAME_LEN
);
+ snprintf(
json
_str, event_id_len, "%d", event_id);
- if (yajl_gen_number(g, event_id_str, strlen(event_id_str)) !=
- yajl_gen_status_ok) {
- sfree(event_id_str);
+ if (yajl_gen_number(g, json_str, strlen(json_str)) != yajl_gen_status_ok) {
goto err;
}
goto err;
}
- sfree(event_id_str);
-
// eventName
if (yajl_gen_string(g, (u_char *)CONNECTIVITY_EVENT_NAME_FIELD,
strlen(CONNECTIVITY_EVENT_NAME_FIELD)) !=
// eventName
if (yajl_gen_string(g, (u_char *)CONNECTIVITY_EVENT_NAME_FIELD,
strlen(CONNECTIVITY_EVENT_NAME_FIELD)) !=
@@
-191,20
+188,16
@@
static int gen_message_payload(int state, int old_state, const char *interface,
event_name_len = event_name_len + (state == 0 ? 4 : 2); // "down" or "up"
event_name_len =
event_name_len + 12; // "interface", 2 spaces and null-terminator
event_name_len = event_name_len + (state == 0 ? 4 : 2); // "down" or "up"
event_name_len =
event_name_len + 12; // "interface", 2 spaces and null-terminator
- char *event_name_str = malloc(event_name_len);
- memset(event_name_str, '\0', event_name_len);
- snprintf(event_name_str, event_name_len, "interface %s %s", interface,
+ memset(json_str, '\0', DATA_MAX_NAME_LEN);
+ snprintf(json_str, event_name_len, "interface %s %s", interface,
(state == 0 ? CONNECTIVITY_EVENT_NAME_DOWN_VALUE
: CONNECTIVITY_EVENT_NAME_UP_VALUE));
(state == 0 ? CONNECTIVITY_EVENT_NAME_DOWN_VALUE
: CONNECTIVITY_EVENT_NAME_UP_VALUE));
- if (yajl_gen_string(g, (u_char *)
event_name_str, strlen(event_name
_str)) !=
+ if (yajl_gen_string(g, (u_char *)
json_str, strlen(json
_str)) !=
yajl_gen_status_ok) {
yajl_gen_status_ok) {
- sfree(event_name_str);
goto err;
}
goto err;
}
- sfree(event_name_str);
-
// lastEpochMicrosec
if (yajl_gen_string(g, (u_char *)CONNECTIVITY_LAST_EPOCH_MICROSEC_FIELD,
strlen(CONNECTIVITY_LAST_EPOCH_MICROSEC_FIELD)) !=
// lastEpochMicrosec
if (yajl_gen_string(g, (u_char *)CONNECTIVITY_LAST_EPOCH_MICROSEC_FIELD,
strlen(CONNECTIVITY_LAST_EPOCH_MICROSEC_FIELD)) !=
@@
-213,18
+206,14
@@
static int gen_message_payload(int state, int old_state, const char *interface,
int last_epoch_microsec_len =
sizeof(char) * sizeof(long long unsigned int) * 4 + 1;
int last_epoch_microsec_len =
sizeof(char) * sizeof(long long unsigned int) * 4 + 1;
-
char *last_epoch_microsec_str = malloc(last_epoch_microsec_len
);
- snprintf(
last_epoch_microsec
_str, last_epoch_microsec_len, "%llu",
+
memset(json_str, '\0', DATA_MAX_NAME_LEN
);
+ snprintf(
json
_str, last_epoch_microsec_len, "%llu",
(long long unsigned int)CDTIME_T_TO_US(cdtime()));
(long long unsigned int)CDTIME_T_TO_US(cdtime()));
- if (yajl_gen_number(g, last_epoch_microsec_str,
- strlen(last_epoch_microsec_str)) != yajl_gen_status_ok) {
- sfree(last_epoch_microsec_str);
+ if (yajl_gen_number(g, json_str, strlen(json_str)) != yajl_gen_status_ok) {
goto err;
}
goto err;
}
- sfree(last_epoch_microsec_str);
-
// priority
if (yajl_gen_string(g, (u_char *)CONNECTIVITY_PRIORITY_FIELD,
strlen(CONNECTIVITY_PRIORITY_FIELD)) !=
// priority
if (yajl_gen_string(g, (u_char *)CONNECTIVITY_PRIORITY_FIELD,
strlen(CONNECTIVITY_PRIORITY_FIELD)) !=
@@
-276,18
+265,14
@@
static int gen_message_payload(int state, int old_state, const char *interface,
int start_epoch_microsec_len =
sizeof(char) * sizeof(long long unsigned int) * 4 + 1;
int start_epoch_microsec_len =
sizeof(char) * sizeof(long long unsigned int) * 4 + 1;
-
char *start_epoch_microsec_str = malloc(start_epoch_microsec_len
);
- snprintf(
start_epoch_microsec
_str, start_epoch_microsec_len, "%llu",
+
memset(json_str, '\0', DATA_MAX_NAME_LEN
);
+ snprintf(
json
_str, start_epoch_microsec_len, "%llu",
(long long unsigned int)timestamp);
(long long unsigned int)timestamp);
- if (yajl_gen_number(g, start_epoch_microsec_str,
- strlen(start_epoch_microsec_str)) != yajl_gen_status_ok) {
- sfree(start_epoch_microsec_str);
+ if (yajl_gen_number(g, json_str, strlen(json_str)) != yajl_gen_status_ok) {
goto err;
}
goto err;
}
- sfree(start_epoch_microsec_str);
-
// version
if (yajl_gen_string(g, (u_char *)CONNECTIVITY_VERSION_FIELD,
strlen(CONNECTIVITY_VERSION_FIELD)) != yajl_gen_status_ok)
// version
if (yajl_gen_string(g, (u_char *)CONNECTIVITY_VERSION_FIELD,
strlen(CONNECTIVITY_VERSION_FIELD)) != yajl_gen_status_ok)
@@
-396,7
+381,7
@@
static int connectivity_link_state(struct nlmsghdr *msg) {
pthread_mutex_lock(&connectivity_lock);
pthread_mutex_lock(&connectivity_lock);
- interfacelist_t *il;
+ interface
_
list_t *il;
/* Scan attribute list for device name. */
mnl_attr_for_each(attr, msg, sizeof(*ifi)) {
/* Scan attribute list for device name. */
mnl_attr_for_each(attr, msg, sizeof(*ifi)) {
@@
-413,7
+398,7
@@
static int connectivity_link_state(struct nlmsghdr *msg) {
dev = mnl_attr_get_str(attr);
dev = mnl_attr_get_str(attr);
- for (il = interfacelist_head; il != NULL; il = il->next)
+ for (il = interface
_
list_head; il != NULL; il = il->next)
if (strcmp(dev, il->interface) == 0)
break;
if (strcmp(dev, il->interface) == 0)
break;
@@
-660,7
+645,7
@@
static int stop_thread(int shutdown) /* {{{ */
static int connectivity_init(void) /* {{{ */
{
static int connectivity_init(void) /* {{{ */
{
- if (interfacelist_head == NULL) {
+ if (interface
_
list_head == NULL) {
NOTICE("connectivity plugin: No interfaces have been configured.");
return (-1);
}
NOTICE("connectivity plugin: No interfaces have been configured.");
return (-1);
}
@@
-671,7
+656,7
@@
static int connectivity_init(void) /* {{{ */
static int connectivity_config(const char *key, const char *value) /* {{{ */
{
if (strcasecmp(key, "Interface") == 0) {
static int connectivity_config(const char *key, const char *value) /* {{{ */
{
if (strcasecmp(key, "Interface") == 0) {
- interfacelist_t *il;
+ interface
_
list_t *il;
char *interface;
il = malloc(sizeof(*il));
char *interface;
il = malloc(sizeof(*il));
@@
-696,8
+681,8
@@
static int connectivity_config(const char *key, const char *value) /* {{{ */
il->prev_status = LINK_STATE_UNKNOWN;
il->timestamp = (long long unsigned int)CDTIME_T_TO_US(cdtime());
il->sent = 0;
il->prev_status = LINK_STATE_UNKNOWN;
il->timestamp = (long long unsigned int)CDTIME_T_TO_US(cdtime());
il->sent = 0;
- il->next = interfacelist_head;
- interfacelist_head = il;
+ il->next = interface
_
list_head;
+ interface
_
list_head = il;
} else {
return (-1);
} else {
return (-1);
@@
-763,7
+748,8
@@
static int connectivity_read(void) /* {{{ */
stop_thread(0);
stop_thread(0);
- for (interfacelist_t *il = interfacelist_head; il != NULL; il = il->next) {
+ for (interface_list_t *il = interface_list_head; il != NULL;
+ il = il->next) {
il->status = LINK_STATE_UNKNOWN;
il->prev_status = LINK_STATE_UNKNOWN;
il->sent = 0;
il->status = LINK_STATE_UNKNOWN;
il->prev_status = LINK_STATE_UNKNOWN;
il->sent = 0;
@@
-774,7
+760,7
@@
static int connectivity_read(void) /* {{{ */
return (-1);
} /* if (connectivity_thread_error != 0) */
return (-1);
} /* if (connectivity_thread_error != 0) */
- for (interface
list_t *il = interface
list_head; il != NULL;
+ for (interface
_list_t *il = interface_
list_head; il != NULL;
il = il->next) /* {{{ */
{
uint32_t status;
il = il->next) /* {{{ */
{
uint32_t status;
@@
-794,22
+780,22
@@
static int connectivity_read(void) /* {{{ */
}
pthread_mutex_unlock(&connectivity_lock);
}
pthread_mutex_unlock(&connectivity_lock);
- } /* }}} for (il = interfacelist_head; il != NULL; il = il->next) */
+ } /* }}} for (il = interface
_
list_head; il != NULL; il = il->next) */
return (0);
} /* }}} int connectivity_read */
static int connectivity_shutdown(void) /* {{{ */
{
return (0);
} /* }}} int connectivity_read */
static int connectivity_shutdown(void) /* {{{ */
{
- interfacelist_t *il;
+ interface
_
list_t *il;
DEBUG("connectivity plugin: Shutting down thread.");
if (stop_thread(1) < 0)
return (-1);
DEBUG("connectivity plugin: Shutting down thread.");
if (stop_thread(1) < 0)
return (-1);
- il = interfacelist_head;
+ il = interface
_
list_head;
while (il != NULL) {
while (il != NULL) {
- interfacelist_t *il_next;
+ interface
_
list_t *il_next;
il_next = il->next;
il_next = il->next;