#define _BSD_SOURCE
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include <stdlib.h>
#include <string.h>
#include <strings.h>
-#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
};
/** Valid types for ceph defined in types.db */
-const char * ceph_dset_types [CEPH_DSET_TYPES_NUM] =
+static const char * const ceph_dset_types [CEPH_DSET_TYPES_NUM] =
{"ceph_latency", "ceph_bytes", "ceph_rate"};
/******* ceph_daemon *******/
#define BUFFER_ADD(dest, src) do { \
size_t dest_size = sizeof (dest); \
strncat ((dest), (src), dest_size - strlen (dest)); \
- (dest)[dest_size - 1] = 0; \
+ (dest)[dest_size - 1] = '\0'; \
} while (0)
static int
char buffer[number_len+1];
char key[2 * DATA_MAX_NAME_LEN];
_Bool latency_type = 0;
- size_t i;
int status;
+ key[0] = '\0';
memcpy(buffer, number_val, number_len);
- buffer[sizeof(buffer) - 1] = 0;
+ buffer[sizeof(buffer) - 1] = '\0';
- memset (key, 0, sizeof (key));
- for (i = 0; i < state->depth; i++)
+ for (size_t i = 0; i < state->depth; i++)
{
if (state->stack[i] == NULL)
continue;
static void ceph_daemons_print(void)
{
- int i;
- for(i = 0; i < g_num_daemons; ++i)
+ for(int i = 0; i < g_num_daemons; ++i)
{
ceph_daemon_print(g_daemons[i]);
}
static void ceph_daemon_free(struct ceph_daemon *d)
{
- int i = 0;
- for(; i < d->last_idx; i++)
+ for(int i = 0; i < d->last_idx; i++)
{
sfree(d->last_poll_data[i]);
}
sfree(d->last_poll_data);
d->last_poll_data = NULL;
d->last_idx = 0;
- for(i = 0; i < d->ds_num; i++)
+
+ for(int i = 0; i < d->ds_num; i++)
{
sfree(d->ds_names[i]);
}
/* count_parts returns the number of elements a "foo.bar.baz" style key has. */
static size_t count_parts (char const *key)
{
- char const *ptr;
size_t parts_num = 0;
- for (ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.'))
+ for (const char *ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.'))
parts_num++;
return parts_num;
{
uint32_t type;
char ds_name[DATA_MAX_NAME_LEN];
- memset(ds_name, 0, sizeof(ds_name));
if(convert_special_metrics)
{
return -ENOMEM;
}
- d->ds_names[d->ds_num] = malloc(sizeof(char) * DATA_MAX_NAME_LEN);
+ d->ds_names[d->ds_num] = malloc(DATA_MAX_NAME_LEN);
if(!d->ds_names[d->ds_num])
{
return -ENOMEM;
static int cc_add_daemon_config(oconfig_item_t *ci)
{
- int ret, i;
- struct ceph_daemon *nd, cd;
+ int ret;
+ struct ceph_daemon *nd, cd = { 0 };
struct ceph_daemon **tmp;
- memset(&cd, 0, sizeof(struct ceph_daemon));
if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
return ret;
}
- for(i=0; i < ci->children_num; i++)
+ for(int i=0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
}
g_daemons = tmp;
- nd = malloc(sizeof(*nd));
+ nd = malloc(sizeof (*nd));
if(!nd)
{
return ENOMEM;
static int ceph_config(oconfig_item_t *ci)
{
- int ret, i;
+ int ret;
- for(i = 0; i < ci->children_num; ++i)
+ for(int i = 0; i < ci->children_num; ++i)
{
oconfig_item_t *child = ci->children + i;
if(strcasecmp("Daemon", child->key) == 0)
static int add_last(struct ceph_daemon *d, const char *ds_n, double cur_sum,
uint64_t cur_count)
{
- d->last_poll_data[d->last_idx] = malloc(1 * sizeof(struct last_data));
+ d->last_poll_data[d->last_idx] = malloc(sizeof (*d->last_poll_data[d->last_idx]));
if(!d->last_poll_data[d->last_idx])
{
return -ENOMEM;
if(!d->last_poll_data)
{
- d->last_poll_data = malloc(1 * sizeof(struct last_data *));
+ d->last_poll_data = malloc(sizeof (*d->last_poll_data));
if(!d->last_poll_data)
{
return -ENOMEM;
*/
static int backup_search_for_last_avg(struct ceph_daemon *d, const char *ds_n)
{
- int i = 0;
- for(; i < d->last_idx; i++)
+ for(int i = 0; i < d->last_idx; i++)
{
if(strcmp(d->last_poll_data[i]->ds_name, ds_n) == 0)
{
*/
static uint32_t backup_search_for_type(struct ceph_daemon *d, char *ds_name)
{
- int idx = 0;
- for(; idx < d->ds_num; idx++)
+ for(int i = 0; i < d->ds_num; i++)
{
- if(strcmp(d->ds_names[idx], ds_name) == 0)
+ if(strcmp(d->ds_names[i], ds_name) == 0)
{
- return d->ds_types[idx];
+ return d->ds_types[i];
}
}
return DSET_TYPE_UNFOUND;
int index = vtmp->index;
char ds_name[DATA_MAX_NAME_LEN];
- memset(ds_name, 0, sizeof(ds_name));
if (parse_keys (ds_name, sizeof (ds_name), key))
{
static int cconn_connect(struct cconn *io)
{
- struct sockaddr_un address;
+ struct sockaddr_un address = { 0 };
int flags, fd, err;
if(io->state != CSTATE_UNCONNECTED)
{
"failed: error %d", err);
return err;
}
- memset(&address, 0, sizeof(struct sockaddr_un));
address.sun_family = AF_UNIX;
snprintf(address.sun_path, sizeof(address.sun_path), "%s",
io->d->asok_path);
*/
static int cconn_main_loop(uint32_t request_type)
{
- int i, ret, some_unreachable = 0;
+ int ret, some_unreachable = 0;
struct timeval end_tv;
struct cconn io_array[g_num_daemons];
/* create cconn array */
memset(io_array, 0, sizeof(io_array));
- for(i = 0; i < g_num_daemons; ++i)
+ for(int i = 0; i < g_num_daemons; ++i)
{
io_array[i].d = g_daemons[i];
io_array[i].request_type = request_type;
struct pollfd fds[g_num_daemons];
memset(fds, 0, sizeof(fds));
nfds = 0;
- for(i = 0; i < g_num_daemons; ++i)
+ for(int i = 0; i < g_num_daemons; ++i)
{
struct cconn *io = io_array + i;
ret = cconn_prepare(io, fds + nfds);
ERROR("ceph plugin: poll(2) error: %d", ret);
goto done;
}
- for(i = 0; i < nfds; ++i)
+ for(int i = 0; i < nfds; ++i)
{
struct cconn *io = polled_io_array[i];
int revents = fds[i].revents;
}
}
}
- done: for(i = 0; i < g_num_daemons; ++i)
+ done: for(int i = 0; i < g_num_daemons; ++i)
{
cconn_close(io_array + i);
}
static int ceph_shutdown(void)
{
- int i;
- for(i = 0; i < g_num_daemons; ++i)
+ for(int i = 0; i < g_num_daemons; ++i)
{
ceph_daemon_free(g_daemons[i]);
}