projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
treewide: add blank line below collectd.h
[collectd.git]
/
src
/
daemon
/
common.c
diff --git
a/src/daemon/common.c
b/src/daemon/common.c
index
dd4f9b1
..
87b86d4
100644
(file)
--- a/
src/daemon/common.c
+++ b/
src/daemon/common.c
@@
-32,14
+32,11
@@
#endif
#include "collectd.h"
#endif
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_cache.h"
#include "common.h"
#include "plugin.h"
#include "utils_cache.h"
-#if HAVE_PTHREAD_H
-# include <pthread.h>
-#endif
-
#ifdef HAVE_MATH_H
# include <math.h>
#endif
#ifdef HAVE_MATH_H
# include <math.h>
#endif
@@
-115,10
+112,9
@@
char *ssnprintf_alloc (char const *format, ...) /* {{{ */
return (strdup (static_buffer));
/* Allocate a buffer large enough to hold the string. */
return (strdup (static_buffer));
/* Allocate a buffer large enough to hold the string. */
- alloc_buffer =
malloc (
alloc_buffer_size);
+ alloc_buffer =
calloc (1,
alloc_buffer_size);
if (alloc_buffer == NULL)
return (NULL);
if (alloc_buffer == NULL)
return (NULL);
- memset (alloc_buffer, 0, alloc_buffer_size);
/* Print again into this new buffer. */
va_start (ap, format);
/* Print again into this new buffer. */
va_start (ap, format);
@@
-144,7
+140,7
@@
char *sstrdup (const char *s)
/* Do not use `strdup' here, because it's not specified in POSIX. It's
* ``only'' an XSI extension. */
sz = strlen (s) + 1;
/* Do not use `strdup' here, because it's not specified in POSIX. It's
* ``only'' an XSI extension. */
sz = strlen (s) + 1;
- r =
(char *) malloc (sizeof (char) *
sz);
+ r =
malloc (
sz);
if (r == NULL)
{
ERROR ("sstrdup: Out of memory.");
if (r == NULL)
{
ERROR ("sstrdup: Out of memory.");
@@
-276,6
+272,9
@@
ssize_t swrite (int fd, const void *buf, size_t count)
ptr = (const char *) buf;
nleft = count;
ptr = (const char *) buf;
nleft = count;
+ if (fd < 0)
+ return (-1);
+
/* checking for closed peer connection */
pfd.fd = fd;
pfd.events = POLLIN | POLLHUP;
/* checking for closed peer connection */
pfd.fd = fd;
pfd.events = POLLIN | POLLHUP;
@@
-336,7
+335,7
@@
int strjoin (char *buffer, size_t buffer_size,
size_t sep_len;
size_t i;
size_t sep_len;
size_t i;
- if ((buffer_size < 1) || (fields_num
<
= 0))
+ if ((buffer_size < 1) || (fields_num
=
= 0))
return (-1);
memset (buffer, 0, buffer_size);
return (-1);
memset (buffer, 0, buffer_size);
@@
-374,27
+373,6
@@
int strjoin (char *buffer, size_t buffer_size,
return ((int) strlen (buffer));
}
return ((int) strlen (buffer));
}
-int strsubstitute (char *str, char c_from, char c_to)
-{
- int ret;
-
- if (str == NULL)
- return (-1);
-
- ret = 0;
- while (*str != '\0')
- {
- if (*str == c_from)
- {
- *str = c_to;
- ret++;
- }
- str++;
- }
-
- return (ret);
-} /* int strsubstitute */
-
int escape_string (char *buffer, size_t buffer_size)
{
char *temp;
int escape_string (char *buffer, size_t buffer_size)
{
char *temp;
@@
-409,10
+387,9
@@
int escape_string (char *buffer, size_t buffer_size)
if (buffer_size < 3)
return (EINVAL);
if (buffer_size < 3)
return (EINVAL);
- temp =
(char *) malloc (
buffer_size);
+ temp =
calloc (1,
buffer_size);
if (temp == NULL)
return (ENOMEM);
if (temp == NULL)
return (ENOMEM);
- memset (temp, 0, buffer_size);
temp[0] = '"';
j = 1;
temp[0] = '"';
j = 1;
@@
-1542,7
+1519,7
@@
int service_name_to_port_number (const char *service_name)
{
struct addrinfo *ai_list;
struct addrinfo *ai_ptr;
{
struct addrinfo *ai_list;
struct addrinfo *ai_ptr;
- struct addrinfo ai_hints;
+ struct addrinfo ai_hints
= { 0 }
;
int status;
int service_number;
int status;
int service_number;
@@
-1550,7
+1527,6
@@
int service_name_to_port_number (const char *service_name)
return (-1);
ai_list = NULL;
return (-1);
ai_list = NULL;
- memset (&ai_hints, 0, sizeof (ai_hints));
ai_hints.ai_family = AF_UNSPEC;
status = getaddrinfo (/* node = */ NULL, service_name,
ai_hints.ai_family = AF_UNSPEC;
status = getaddrinfo (/* node = */ NULL, service_name,