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.5' into collectd-5.6
[collectd.git]
/
src
/
libcollectdclient
/
client.c
diff --git
a/src/libcollectdclient/client.c
b/src/libcollectdclient/client.c
index
c90107d
..
4dbee1e
100644
(file)
--- a/
src/libcollectdclient/client.c
+++ b/
src/libcollectdclient/client.c
@@
-85,7
+85,7
@@
_b[sizeof (_b) - 1] = 0; \
SSTRCAT ((d), _b); \
} while (0)
_b[sizeof (_b) - 1] = 0; \
SSTRCAT ((d), _b); \
} while (0)
-
+
#define LCC_SET_ERRSTR(c, ...) do { \
snprintf ((c)->errbuf, sizeof ((c)->errbuf), __VA_ARGS__); \
#define LCC_SET_ERRSTR(c, ...) do { \
snprintf ((c)->errbuf, sizeof ((c)->errbuf), __VA_ARGS__); \
@@
-113,6
+113,7
@@
typedef struct lcc_response_s lcc_response_t;
/*
* Private functions
*/
/*
* Private functions
*/
+__attribute__ ((format (printf, 1, 0)))
static int lcc_tracef(char const *format, ...)
{
va_list ap;
static int lcc_tracef(char const *format, ...)
{
va_list ap;
@@
-246,12
+247,10
@@
static void lcc_chomp (char *str) /* {{{ */
static void lcc_response_free (lcc_response_t *res) /* {{{ */
{
static void lcc_response_free (lcc_response_t *res) /* {{{ */
{
- size_t i;
-
if (res == NULL)
return;
if (res == NULL)
return;
- for (i = 0; i < res->lines_num; i++)
+ for (
size_t
i = 0; i < res->lines_num; i++)
free (res->lines[i]);
free (res->lines);
res->lines = NULL;
free (res->lines[i]);
free (res->lines);
res->lines = NULL;
@@
-277,13
+276,11
@@
static int lcc_send (lcc_connection_t *c, const char *command) /* {{{ */
static int lcc_receive (lcc_connection_t *c, /* {{{ */
lcc_response_t *ret_res)
{
static int lcc_receive (lcc_connection_t *c, /* {{{ */
lcc_response_t *ret_res)
{
- lcc_response_t res;
+ lcc_response_t res
= { 0 }
;
char *ptr;
char buffer[4096];
size_t i;
char *ptr;
char buffer[4096];
size_t i;
- memset (&res, 0, sizeof (res));
-
/* Read the first line, containing the status and a message */
ptr = fgets (buffer, sizeof (buffer), c->fh);
if (ptr == NULL)
/* Read the first line, containing the status and a message */
ptr = fgets (buffer, sizeof (buffer), c->fh);
if (ptr == NULL)
@@
-298,7
+295,7
@@
static int lcc_receive (lcc_connection_t *c, /* {{{ */
* beginning of the message. */
ptr = NULL;
errno = 0;
* beginning of the message. */
ptr = NULL;
errno = 0;
- res.status = strtol (buffer, &ptr, 0);
+ res.status =
(int)
strtol (buffer, &ptr, 0);
if ((errno != 0) || (ptr == &buffer[0]))
{
lcc_set_errno (c, errno);
if ((errno != 0) || (ptr == &buffer[0]))
{
lcc_set_errno (c, errno);
@@
-323,7
+320,7
@@
static int lcc_receive (lcc_connection_t *c, /* {{{ */
/* Allocate space for the char-pointers */
res.lines_num = (size_t) res.status;
res.status = 0;
/* Allocate space for the char-pointers */
res.lines_num = (size_t) res.status;
res.status = 0;
- res.lines =
(char **) malloc (res.lines_num * sizeof (char *
));
+ res.lines =
malloc (res.lines_num * sizeof (*res.lines
));
if (res.lines == NULL)
{
lcc_set_errno (c, ENOMEM);
if (res.lines == NULL)
{
lcc_set_errno (c, ENOMEM);
@@
-369,7
+366,7
@@
static int lcc_receive (lcc_connection_t *c, /* {{{ */
static int lcc_sendreceive (lcc_connection_t *c, /* {{{ */
const char *command, lcc_response_t *ret_res)
{
static int lcc_sendreceive (lcc_connection_t *c, /* {{{ */
const char *command, lcc_response_t *ret_res)
{
- lcc_response_t res;
+ lcc_response_t res
= { 0 }
;
int status;
if (c->fh == NULL)
int status;
if (c->fh == NULL)
@@
-382,7
+379,6
@@
static int lcc_sendreceive (lcc_connection_t *c, /* {{{ */
if (status != 0)
return (status);
if (status != 0)
return (status);
- memset (&res, 0, sizeof (res));
status = lcc_receive (c, &res);
if (status == 0)
memcpy (ret_res, &res, sizeof (*ret_res));
status = lcc_receive (c, &res);
if (status == 0)
memcpy (ret_res, &res, sizeof (*ret_res));
@@
-392,7
+388,7
@@
static int lcc_sendreceive (lcc_connection_t *c, /* {{{ */
static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */
{
static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */
{
- struct sockaddr_un sa;
+ struct sockaddr_un sa
= { 0 }
;
int fd;
int status;
int fd;
int status;
@@
-409,7
+405,6
@@
static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */
return (-1);
}
return (-1);
}
- memset (&sa, 0, sizeof (sa));
sa.sun_family = AF_UNIX;
strncpy (sa.sun_path, path, sizeof (sa.sun_path) - 1);
sa.sun_family = AF_UNIX;
strncpy (sa.sun_path, path, sizeof (sa.sun_path) - 1);
@@
-435,9
+430,7
@@
static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */
static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
const char *addr_orig)
{
static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
const char *addr_orig)
{
- struct addrinfo ai_hints;
struct addrinfo *ai_res;
struct addrinfo *ai_res;
- struct addrinfo *ai_ptr;
char addr_copy[NI_MAXHOST];
char *addr;
char *port;
char addr_copy[NI_MAXHOST];
char *addr;
char *port;
@@
-452,14
+445,6
@@
static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
addr_copy[sizeof(addr_copy) - 1] = '\0';
addr = addr_copy;
addr_copy[sizeof(addr_copy) - 1] = '\0';
addr = addr_copy;
- memset (&ai_hints, 0, sizeof (ai_hints));
- ai_hints.ai_flags = 0;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
-
port = NULL;
if (*addr == '[') /* IPv6+port format */
{
port = NULL;
if (*addr == '[') /* IPv6+port format */
{
@@
-495,7
+480,12
@@
static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
}
}
}
}
- ai_res = NULL;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM
+ };
+
status = getaddrinfo (addr,
port == NULL ? LCC_DEFAULT_PORT : port,
&ai_hints, &ai_res);
status = getaddrinfo (addr,
port == NULL ? LCC_DEFAULT_PORT : port,
&ai_hints, &ai_res);
@@
-505,7
+495,7
@@
static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
return (-1);
}
return (-1);
}
- for (ai_ptr = ai_res; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (
struct addrinfo *
ai_ptr = ai_res; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0)
{
fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0)
@@
-595,10
+585,9
@@
int lcc_connect (const char *address, lcc_connection_t **ret_con) /* {{{ */
if (ret_con == NULL)
return (-1);
if (ret_con == NULL)
return (-1);
- c =
(lcc_connection_t *) malloc (
sizeof (*c));
+ c =
calloc (1,
sizeof (*c));
if (c == NULL)
return (-1);
if (c == NULL)
return (-1);
- memset (c, 0, sizeof (*c));
status = lcc_open_socket (c, address);
if (status != 0)
status = lcc_open_socket (c, address);
if (status != 0)
@@
-698,14
+687,14
@@
int lcc_getval (lcc_connection_t *c, lcc_identifier_t *ident, /* {{{ */
/* Allocate space for the values */
if (ret_values != NULL)
{
/* Allocate space for the values */
if (ret_values != NULL)
{
- values =
(gauge_t *)
malloc (values_num * sizeof (*values));
+ values = malloc (values_num * sizeof (*values));
if (values == NULL)
BAIL_OUT (ENOMEM);
}
if (ret_values_names != NULL)
{
if (values == NULL)
BAIL_OUT (ENOMEM);
}
if (ret_values_names != NULL)
{
- values_names =
(char **)
calloc (values_num, sizeof (*values_names));
+ values_names = calloc (values_num, sizeof (*values_names));
if (values_names == NULL)
BAIL_OUT (ENOMEM);
}
if (values_names == NULL)
BAIL_OUT (ENOMEM);
}
@@
-761,7
+750,6
@@
int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */
char command[1024] = "";
lcc_response_t res;
int status;
char command[1024] = "";
lcc_response_t res;
int status;
- size_t i;
if ((c == NULL) || (vl == NULL) || (vl->values_len < 1)
|| (vl->values == NULL) || (vl->values_types == NULL))
if ((c == NULL) || (vl == NULL) || (vl->values_len < 1)
|| (vl->values == NULL) || (vl->values_types == NULL))
@@
-786,7
+774,7
@@
int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */
else
SSTRCAT (command, " N");
else
SSTRCAT (command, " N");
- for (i = 0; i < vl->values_len; i++)
+ for (
size_t
i = 0; i < vl->values_len; i++)
{
if (vl->values_types[i] == LCC_TYPE_COUNTER)
SSTRCATF (command, ":%"PRIu64, vl->values[i].counter);
{
if (vl->values_types[i] == LCC_TYPE_COUNTER)
SSTRCATF (command, ":%"PRIu64, vl->values[i].counter);
@@
-878,7
+866,6
@@
int lcc_listval (lcc_connection_t *c, /* {{{ */
lcc_identifier_t **ret_ident, size_t *ret_ident_num)
{
lcc_response_t res;
lcc_identifier_t **ret_ident, size_t *ret_ident_num)
{
lcc_response_t res;
- size_t i;
int status;
lcc_identifier_t *ident;
int status;
lcc_identifier_t *ident;
@@
-905,7
+892,7
@@
int lcc_listval (lcc_connection_t *c, /* {{{ */
}
ident_num = res.lines_num;
}
ident_num = res.lines_num;
- ident =
(lcc_identifier_t *)
malloc (ident_num * sizeof (*ident));
+ ident = malloc (ident_num * sizeof (*ident));
if (ident == NULL)
{
lcc_response_free (&res);
if (ident == NULL)
{
lcc_response_free (&res);
@@
-913,7
+900,7
@@
int lcc_listval (lcc_connection_t *c, /* {{{ */
return (-1);
}
return (-1);
}
- for (i = 0; i < res.lines_num; i++)
+ for (
size_t
i = 0; i < res.lines_num; i++)
{
char *time_str;
char *ident_str;
{
char *time_str;
char *ident_str;
@@
-1074,9
+1061,11
@@
int lcc_string_to_identifier (lcc_connection_t *c, /* {{{ */
return (0);
} /* }}} int lcc_string_to_identifier */
return (0);
} /* }}} int lcc_string_to_identifier */
-int lcc_identifier_compare (const
lcc_identifier_t *i0
, /* {{{ */
- const
lcc_identifier_t *i1
)
+int lcc_identifier_compare (const
void *a
, /* {{{ */
+ const
void *b
)
{
{
+ const lcc_identifier_t *i0 = a;
+ const lcc_identifier_t *i1 = b;
int status;
if ((i0 == NULL) && (i1 == NULL))
int status;
if ((i0 == NULL) && (i1 == NULL))
@@
-1113,7
+1102,7
@@
int lcc_sort_identifiers (lcc_connection_t *c, /* {{{ */
}
qsort (idents, idents_num, sizeof (*idents),
}
qsort (idents, idents_num, sizeof (*idents),
-
(void *)
lcc_identifier_compare);
+ lcc_identifier_compare);
return (0);
} /* }}} int lcc_sort_identifiers */
return (0);
} /* }}} int lcc_sort_identifiers */