database.
* Logging is, as everything in collectd, provided by plugins. The following
- plugins keep up informed about what's going on:
+ plugins keep us informed about what's going on:
- logfile
Writes log messages to a file or STDOUT/STDERR.
AC_DEFINE(_REENTRANT, 1, [Define to enable reentrancy interfaces.])
AC_MSG_CHECKING([whether compiler builds 64bit binaries])
- AC_PREPROC_IFELSE([AC_LANG_PROGRAM([
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#ifndef _LP64
# error "Compiler not in 64bit mode."
#endif
#endif
])
-AC_CHECK_TYPES([struct ip6_ext], [], [],
+have_ip6_ext="no"
+AC_CHECK_TYPES([struct ip6_ext], [have_ip6_ext="yes"], [have_ip6_ext="no"],
[#if HAVE_STDINT_H
# include <stdint.h>
#endif
#endif
])
+if test "x$have_ip6_ext" = "xno"; then
+ SAVE_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -DSOLARIS2=8"
+
+ AC_CHECK_TYPES([struct ip6_ext],
+ [have_ip6_ext="yes, with -DSOLARIS2=8"],
+ [have_ip6_ext="no"],
+[#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_NETINET_IN_SYSTM_H
+# include <netinet/in_systm.h>
+#endif
+#if HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#if HAVE_NETINET_IP6_H
+# include <netinet/ip6.h>
+#endif
+])
+
+ if test "x$have_ip6_ext" = "xno"; then
+ CFLAGS="$SAVE_CFLAGS"
+ fi
+fi
+
# For cpu modules
AC_CHECK_HEADERS(sys/dkstat.h)
if test "x$ac_system" = "xDarwin"
if test "x$have_asm_msrindex_h" = "xyes"
then
- AC_CACHE_CHECK([whether asm/msr-index.h has MSR_CORE_C3_RESIDENCY],
+ AC_CACHE_CHECK([whether asm/msr-index.h has MSR_PKG_C10_RESIDENCY],
[c_cv_have_usable_asm_msrindex_h],
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[[
#include<asm/msr-index.h>
]]],
[[[
-int y = MSR_CORE_C3_RESIDENCY;
+int y = MSR_PKG_C10_RESIDENCY;
return(y);
]]]
)],
License: GPLv2
Group: System Environment/Daemons
BuildRoot: %{_tmppath}/%{name}-%{version}-root
-BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel, flex, bison
+BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel
Vendor: collectd development team <collectd@verplant.org>
%if 0%{?el7:1}
%define _with_zookeeper --disable-zookeeper
%endif
-export YACC=bison
-export YFLAGS=-y
-
%configure CFLAGS="%{optflags} -DLT_LAZY_OR_NOW=\"RTLD_LAZY|RTLD_GLOBAL\"" \
--disable-static \
--without-included-ltdl \
AUTOMAKE_OPTIONS = subdir-objects
-noinst_LTLIBRARIES = libmount.la liblookup.la
+noinst_LTLIBRARIES =
+check_PROGRAMS =
+TESTS =
+noinst_LTLIBRARIES += liblookup.la
+liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h
+liblookup_la_LIBADD = daemon/libavltree.la
+check_PROGRAMS += test_utils_vl_lookup
+TESTS += test_utils_vl_lookup
+test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c testing.h
+test_utils_vl_lookup_LDADD = liblookup.la daemon/libcommon.la daemon/libplugin_mock.la
+
+noinst_LTLIBRARIES += libmount.la
libmount_la_SOURCES = utils_mount.c utils_mount.h
-libmount_la_LIBADD = daemon/libcommon.la
+check_PROGRAMS += test_utils_mount
+TESTS += test_utils_mount
+test_utils_mount_SOURCES = utils_mount_test.c testing.h
+test_utils_mount_LDADD = libmount.la daemon/libcommon.la daemon/libplugin_mock.la
-liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h
-liblookup_la_LIBADD = daemon/libavltree.la daemon/libcommon.la
sbin_PROGRAMS = collectdmon
bin_PROGRAMS = collectd-nagios collectdctl collectd-tg
statsd_la_SOURCES = statsd.c \
utils_latency.h utils_latency.c
statsd_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-statsd_la_LIBADD = -lpthread
+statsd_la_LIBADD = -lpthread -lm
endif
if BUILD_PLUGIN_SWAP
rm -f $(DESTDIR)$(sysconfdir)/collectd.conf
rm -f $(DESTDIR)$(pkgdatadir)/postgresql_default.conf;
-check_PROGRAMS = test_utils_mount test_utils_vl_lookup
-
-test_utils_mount_SOURCES = utils_mount_test.c testing.h
-test_utils_mount_LDADD = libmount.la daemon/libplugin_mock.la
-
-test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c testing.h
-test_utils_vl_lookup_LDADD = liblookup.la daemon/libplugin_mock.la
-TESTS = test_utils_mount test_utils_vl_lookup
continue;
}
- status = camqp_read_header (conf);
+ camqp_read_header (conf);
amqp_maybe_release_buffers (conf->connection);
} /* while (subscriber_threads_running) */
curl_easy_cleanup(st->curl);
st->curl = NULL;
}
+ sfree (st);
} /* apache_free */
static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb,
*
* @return Zero when successful
*/
-static int averaging_create(averaging_t * avg, int size)
+static int averaging_create(averaging_t *avg, int size)
{
- int a;
-
- avg->ring_buffer = (long int *) malloc(size * sizeof(*avg));
+ avg->ring_buffer = calloc ((size_t) size, sizeof (*avg->ring_buffer));
if (avg->ring_buffer == NULL)
{
ERROR ("barometer: averaging_create - ring buffer allocation of size %d failed",
return -1;
}
- for (a=0; a<size; ++a)
- {
- avg->ring_buffer[a] = 0L;
- }
-
avg->ring_buffer_size = size;
avg->ring_buffer_sum = 0L;
avg->ring_buffer_head = 0;
return 0;
}
-/**
+/**
* Read the MPL115 sensor conversion coefficients.
*
* These are (device specific) constants so we can read them just once.
*/
static int MPL115_read_coeffs(void)
{
- uint8_t mpl115_coeffs[MPL115_NUM_COEFFS];
+ uint8_t mpl115_coeffs[MPL115_NUM_COEFFS] = { 0 };
int32_t res;
int8_t sia0MSB, sia0LSB, sib1MSB, sib1LSB, sib2MSB, sib2LSB;
int8_t sic12MSB, sic12LSB, sic11MSB, sic11LSB, sic22MSB, sic22LSB;
int16_t sia0, sib1, sib2, sic12, sic11, sic22;
-
+
char errbuf[1024];
- res = i2c_smbus_read_i2c_block_data(i2c_bus_fd,
- MPL115_ADDR_COEFFS,
- MPL115_NUM_COEFFS,
+ res = i2c_smbus_read_i2c_block_data(i2c_bus_fd,
+ MPL115_ADDR_COEFFS,
+ STATIC_ARRAY_SIZE (mpl115_coeffs),
mpl115_coeffs);
if (res < 0)
{
sstrerror (errno, errbuf, sizeof (errbuf)));
return -1;
}
-
+
/* Using perhaps less elegant/efficient code, but more readable. */
/* a0: 16total 1sign 12int 4fract 0pad */
sia0MSB = mpl115_coeffs[0];
sia0 += (int16_t) sia0LSB & 0x00FF; /* Add LSB to 16bit number */
mpl115_coeffA0 = (double) (sia0);
mpl115_coeffA0 /= 8.0; /* 3 fract bits */
-
+
/* b1: 16total 1sign 2int 13fract 0pad */
sib1MSB= mpl115_coeffs[2];
sib1LSB= mpl115_coeffs[3];
sib1 += sib1LSB & 0x00FF; /* Add LSB to 16bit number */
mpl115_coeffB1 = (double) (sib1);
mpl115_coeffB1 /= 8192.0; /* 13 fract */
-
+
/* b2: 16total 1sign 1int 14fract 0pad */
sib2MSB= mpl115_coeffs[4];
sib2LSB= mpl115_coeffs[5];
mpl115_coeffC22 /= 33554432.0; /* 10+15=25 fract */
DEBUG("barometer: MPL115_read_coeffs: a0=%lf, b1=%lf, b2=%lf, c12=%lf, c11=%lf, c22=%lf",
- mpl115_coeffA0,
- mpl115_coeffB1,
- mpl115_coeffB2,
- mpl115_coeffC12,
- mpl115_coeffC11,
+ mpl115_coeffA0,
+ mpl115_coeffB1,
+ mpl115_coeffB2,
+ mpl115_coeffC12,
+ mpl115_coeffC11,
mpl115_coeffC22);
return 0;
}
}
-/**
+/**
* Read sensor averegaed measurements
*
* @param pressure averaged measured pressure
*/
static int MPL115_read_averaged(double * pressure, double * temperature)
{
- uint8_t mpl115_conv[MPL115_NUM_CONV];
+ uint8_t mpl115_conv[MPL115_NUM_CONV] = { 0 };
int8_t res;
int retries;
int conv_pressure;
*pressure = 0.0;
*temperature = 0.0;
-
+
/* start conversion of both temp and presure */
retries = MPL115_CONVERSION_RETRIES;
while (retries>0)
{
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd,
MPL115_ADDR_CONV,
- MPL115_NUM_CONV,
- mpl115_conv);
+ STATIC_ARRAY_SIZE (mpl115_conv),
+ mpl115_conv);
if (res >= 0)
break;
return -1;
}
}
-
+
conv_pressure = ((mpl115_conv[0] << 8) | mpl115_conv[1]) >> 6;
conv_temperature = ((mpl115_conv[2] << 8) | mpl115_conv[3]) >> 6;
DEBUG ("barometer: MPL115_read_averaged, raw pressure ADC value = %d, " \
adc_temperature,
*pressure,
*temperature);
-
+
return 0;
}
ssnprintf (filename, sizeof (filename), "%s/%s/info", dir, power_supply);
fh = fopen (filename, "r");
- if ((fh = fopen (filename, "r")) == NULL)
+ if (fh == NULL)
return (errno);
/* last full capacity: 40090 mWh */
ssnprintf (filename, sizeof (filename), "%s/%s/state", dir, power_supply);
fh = fopen (filename, "r");
- if ((fh = fopen (filename, "r")) == NULL)
+ if (fh == NULL)
{
if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT))
return (0);
static int cc_add_daemon_config(oconfig_item_t *ci)
{
int ret, i;
- struct ceph_daemon *array, *nd, cd;
+ struct ceph_daemon *nd, cd;
+ struct ceph_daemon **tmp;
memset(&cd, 0, sizeof(struct ceph_daemon));
if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
return -EINVAL;
}
- array = realloc(g_daemons,
- sizeof(struct ceph_daemon *) * (g_num_daemons + 1));
- if(array == NULL)
+ tmp = realloc(g_daemons, (g_num_daemons+1) * sizeof(*g_daemons));
+ if(tmp == NULL)
{
/* The positive return value here indicates that this is a
* runtime error, not a configuration error. */
return ENOMEM;
}
- g_daemons = (struct ceph_daemon**) array;
- nd = malloc(sizeof(struct ceph_daemon));
+ g_daemons = tmp;
+
+ nd = malloc(sizeof(*nd));
if(!nd)
{
return ENOMEM;
}
- memcpy(nd, &cd, sizeof(struct ceph_daemon));
+ memcpy(nd, &cd, sizeof(*nd));
g_daemons[g_num_daemons++] = nd;
return 0;
}
=head2 Plugin C<curl_json>
The B<curl_json plugin> collects values from JSON data to be parsed by
-B<libyajl> (L<http://www.lloydforge.org/projects/yajl/>) retrieved via
+B<libyajl> (L<https://lloyd.github.io/yajl/>) retrieved via
either B<libcurl> (L<http://curl.haxx.se/>) or read directly from a
unix socket. The former can be used, for example, to collect values
from CouchDB documents (which are stored JSON notation), and the
Sets the URL to use to connect to the I<OpenLDAP> server. This option is
I<mandatory>.
+=item B<BindDN> I<BindDN>
+
+Name in the form of an LDAP distinguished name intended to be used for
+authentication. Defaults to empty string to establish an anonymous authorization.
+
+=item B<Password> I<Password>
+
+Password for simple bind authentication. If this option is not set,
+unauthenticated bind operation is used.
+
=item B<StartTLS> B<true|false>
Defines whether TLS must be used when connecting to the I<OpenLDAP> server.
openlog ("collectdmon", LOG_CONS | LOG_PID, LOG_DAEMON);
if (-1 == daemonize ())
+ {
+ free (collectd_argv);
return 1;
+ }
sa.sa_handler = sig_int_term_handler;
sa.sa_flags = 0;
if (0 != sigaction (SIGINT, &sa, NULL)) {
syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+ free (collectd_argv);
return 1;
}
if (0 != sigaction (SIGTERM, &sa, NULL)) {
syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+ free (collectd_argv);
return 1;
}
if (0 != sigaction (SIGHUP, &sa, NULL)) {
syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+ free (collectd_argv);
return 1;
}
} /* while (status == 0) */
if (status != 0)
+ {
+ cc_web_match_free (match);
return (status);
+ }
match->match = match_create_simple (match->regex, match->exclude_regex,
match->dstype);
{
ERROR ("curl_json plugin: cj_config: "
"Invalid key: %s", ci->key);
+ cj_key_free (key);
return (-1);
}
db->tree = cj_avl_create();
tree = db->tree;
- name = key->path;
ptr = key->path;
if (*ptr == '/')
++ptr;
{
ERROR ("curl_json plugin: cj_config: "
"Invalid key: %s", ci->key);
+ cj_free (db);
return (-1);
}
if (status != 0)
{
ERROR ("curl_xml plugin: cx_config: "
"Invalid key: %s", ci->key);
+ cx_free (db);
return (-1);
}
static int pidfile_remove (void)
{
const char *file = global_option_get ("PIDFile");
+ if (file == NULL)
+ return 0;
- DEBUG ("unlink (%s)", (file != NULL) ? file : "<null>");
return (unlink (file));
} /* static int pidfile_remove (const char *file) */
#endif /* COLLECT_DAEMON */
return ((int) i);
}
-int strjoin (char *dst, size_t dst_len,
+int strjoin (char *buffer, size_t buffer_size,
char **fields, size_t fields_num,
const char *sep)
{
- size_t field_len;
+ size_t avail;
+ char *ptr;
size_t sep_len;
- int i;
-
- memset (dst, '\0', dst_len);
+ size_t i;
- if (fields_num <= 0)
+ if ((buffer_size < 1) || (fields_num <= 0))
return (-1);
+ memset (buffer, 0, buffer_size);
+ ptr = buffer;
+ avail = buffer_size - 1;
+
sep_len = 0;
if (sep != NULL)
sep_len = strlen (sep);
- for (i = 0; i < (int)fields_num; i++)
+ for (i = 0; i < fields_num; i++)
{
+ size_t field_len;
+
if ((i > 0) && (sep_len > 0))
{
- if (dst_len <= sep_len)
+ if (avail < sep_len)
return (-1);
- strncat (dst, sep, dst_len);
- dst_len -= sep_len;
+ memcpy (ptr, sep, sep_len);
+ ptr += sep_len;
+ avail -= sep_len;
}
field_len = strlen (fields[i]);
-
- if (dst_len <= field_len)
+ if (avail < field_len)
return (-1);
- strncat (dst, fields[i], dst_len);
- dst_len -= field_len;
+ memcpy (ptr, fields[i], field_len);
+ ptr += field_len;
+ avail -= field_len;
}
- return (strlen (dst));
+ assert (buffer[buffer_size - 1] == 0);
+ return (strlen (buffer));
}
int strsubstitute (char *str, char c_from, char c_to)
typedef struct cf_value_map_s
{
char *key;
- int (*func) (const oconfig_item_t *);
+ int (*func) (oconfig_item_t *);
} cf_value_map_t;
typedef struct cf_global_option_s
/*
* Prototypes of callback functions
*/
-static int dispatch_value_typesdb (const oconfig_item_t *ci);
-static int dispatch_value_plugindir (const oconfig_item_t *ci);
-static int dispatch_loadplugin (const oconfig_item_t *ci);
+static int dispatch_value_typesdb (oconfig_item_t *ci);
+static int dispatch_value_plugindir (oconfig_item_t *ci);
+static int dispatch_loadplugin (oconfig_item_t *ci);
+static int dispatch_block_plugin (oconfig_item_t *ci);
/*
* Private variables
{
{"TypesDB", dispatch_value_typesdb},
{"PluginDir", dispatch_value_plugindir},
- {"LoadPlugin", dispatch_loadplugin}
+ {"LoadPlugin", dispatch_loadplugin},
+ {"Plugin", dispatch_block_plugin}
};
static int cf_value_map_num = STATIC_ARRAY_SIZE (cf_value_map);
int ret;
int i;
+ if (orig_key == NULL)
+ return (EINVAL);
+
DEBUG ("type = %s, key = %s, value = %s",
ESCAPE_NULL(type),
- ESCAPE_NULL(orig_key),
+ orig_key,
ESCAPE_NULL(orig_value));
if ((cf_cb = cf_search (type)) == NULL)
free (key);
free (value);
- DEBUG ("cf_dispatch: return (%i)", ret);
-
return (ret);
} /* int cf_dispatch */
return (-1);
} /* int dispatch_global_option */
-static int dispatch_value_typesdb (const oconfig_item_t *ci)
+static int dispatch_value_typesdb (oconfig_item_t *ci)
{
int i = 0;
return (0);
} /* int dispatch_value_typesdb */
-static int dispatch_value_plugindir (const oconfig_item_t *ci)
+static int dispatch_value_plugindir (oconfig_item_t *ci)
{
assert (strcasecmp (ci->key, "PluginDir") == 0);
return (0);
}
-static int dispatch_loadplugin (const oconfig_item_t *ci)
+static int dispatch_loadplugin (oconfig_item_t *ci)
{
int i;
const char *name;
return (cf_dispatch (plugin, ci->key, buffer_ptr));
} /* int dispatch_value_plugin */
-static int dispatch_value (const oconfig_item_t *ci)
+static int dispatch_value (oconfig_item_t *ci)
{
int ret = -2;
int i;
filenames[filenames_num - 1] = sstrdup (name);
}
+ if (filenames == NULL)
+ return (root);
+
qsort ((void *) filenames, filenames_num, sizeof (*filenames),
cf_compare_string);
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
- status = 0;
if (strcasecmp ("Match", option->key) == 0)
status = fc_config_add_match (&rule->matches, option);
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
- status = 0;
if (strcasecmp ("Rule", option->key) == 0)
status = fc_config_add_rule (chain, option);
c_avl_node_t *y;
c_avl_node_t *b;
+ assert (x != NULL);
+ assert (x->left != NULL);
+
p = x->parent;
y = x->left;
b = y->right;
y->height = calc_height (y);
return (y);
-} /* void rotate_left */
+} /* void rotate_right */
/*
* (x) (y)
c_avl_node_t *y;
c_avl_node_t *b;
+ assert (x != NULL);
+ assert (x->right != NULL);
+
p = x->parent;
y = x->right;
b = y->left;
n = t->root;
while ((n->left != NULL) || (n->right != NULL))
{
- int height_left = (n->left == NULL) ? 0 : n->left->height;
- int height_right = (n->right == NULL) ? 0 : n->right->height;
+ if (n->left == NULL)
+ {
+ n = n->right;
+ continue;
+ }
+ else if (n->right == NULL)
+ {
+ n = n->left;
+ continue;
+ }
- if (height_left > height_right)
+ if (n->left->height > n->right->height)
n = n->left;
else
n = n->right;
pthread_mutex_unlock (&cache_lock);
if (keys_len == 0)
+ {
+ /* realloc() may have been called for these. */
+ sfree (keys);
+ sfree (keys_time);
+ sfree (keys_interval);
return (0);
+ }
/* Call the "missing" callback for each value. Do this before removing the
* value from the cache, so that callbacks can still access the data stored,
if (status != 0)
{
ERROR ("uc_check_timeout: parse_identifier_vl (\"%s\") failed.", keys[i]);
- cache_free (ce);
continue;
}
if (status != 0)
{
size_t i;
-
+
for (i = 0; i < number; i++)
{
sfree (names[i]);
}
sfree (names);
+ sfree (times);
return (-1);
}
*ret_names = names;
if (ret_times != NULL)
*ret_times = times;
+ else
+ sfree (times);
*ret_number = number;
return (0);
{
llentry_t *prev;
+ if ((l == NULL) || (e == NULL))
+ return;
+
prev = l->head;
while ((prev != NULL) && (prev->next != e))
prev = prev->next;
uint64_t blk_reserved;
uint64_t blk_used;
- if (ignorelist_match (il_device,
- (mnt_ptr->spec_device != NULL)
- ? mnt_ptr->spec_device
- : mnt_ptr->device))
+ char const *dev = (mnt_ptr->spec_device != NULL)
+ ? mnt_ptr->spec_device
+ : mnt_ptr->device;
+
+ if (ignorelist_match (il_device, dev))
continue;
if (ignorelist_match (il_mountpoint, mnt_ptr->dir))
continue;
if (by_device)
{
/* eg, /dev/hda1 -- strip off the "/dev/" */
- if (strncmp (mnt_ptr->spec_device, "/dev/", strlen ("/dev/")) == 0)
- sstrncpy (disk_name, mnt_ptr->spec_device + strlen ("/dev/"), sizeof (disk_name));
+ if (strncmp (dev, "/dev/", strlen ("/dev/")) == 0)
+ sstrncpy (disk_name, dev + strlen ("/dev/"), sizeof (disk_name));
else
- sstrncpy (disk_name, mnt_ptr->spec_device, sizeof (disk_name));
+ sstrncpy (disk_name, dev, sizeof (disk_name));
if (strlen(disk_name) < 1)
{
io_registry_entry_t disk;
io_registry_entry_t disk_child;
io_iterator_t disk_list;
- CFDictionaryRef props_dict;
+ CFMutableDictionaryRef props_dict, child_dict;
CFDictionaryRef stats_dict;
- CFDictionaryRef child_dict;
CFStringRef tmp_cf_string_ref;
kern_return_t status;
- signed long long read_ops;
- signed long long read_byt;
- signed long long read_tme;
- signed long long write_ops;
- signed long long write_byt;
- signed long long write_tme;
+ signed long long read_ops, read_byt, read_tme;
+ signed long long write_ops, write_byt, write_tme;
- int disk_major;
- int disk_minor;
+ int disk_major, disk_minor;
char disk_name[DATA_MAX_NAME_LEN];
- char disk_name_bsd[DATA_MAX_NAME_LEN];
+ char child_disk_name_bsd[DATA_MAX_NAME_LEN], props_disk_name_bsd[DATA_MAX_NAME_LEN];
/* Get the list of all disk objects. */
- if (IOServiceGetMatchingServices (io_master_port,
- IOServiceMatching (kIOBlockStorageDriverClass),
- &disk_list) != kIOReturnSuccess)
- {
+ if (IOServiceGetMatchingServices (io_master_port, IOServiceMatching (kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) {
ERROR ("disk plugin: IOServiceGetMatchingServices failed.");
return (-1);
}
- while ((disk = IOIteratorNext (disk_list)) != 0)
- {
+ while ((disk = IOIteratorNext (disk_list)) != 0) {
props_dict = NULL;
stats_dict = NULL;
child_dict = NULL;
- /* `disk_child' must be released */
- if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child))
- != kIOReturnSuccess)
- {
- /* This fails for example for DVD/CD drives.. */
+ /* get child of disk entry and corresponding property dictionary */
+ if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) != kIOReturnSuccess) {
+ /* This fails for example for DVD/CD drives, which we want to ignore anyway */
DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
IOObjectRelease (disk);
continue;
}
-
- /* We create `props_dict' => we need to release it later */
- if (IORegistryEntryCreateCFProperties (disk,
- (CFMutableDictionaryRef *) &props_dict,
- kCFAllocatorDefault,
- kNilOptions)
- != kIOReturnSuccess)
- {
- ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
+ if (IORegistryEntryCreateCFProperties (disk_child, (CFMutableDictionaryRef *) &child_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || child_dict == NULL) {
+ ERROR ("disk plugin: IORegistryEntryCreateCFProperties (disk_child) failed.");
IOObjectRelease (disk_child);
IOObjectRelease (disk);
continue;
}
- if (props_dict == NULL)
- {
- DEBUG ("IORegistryEntryCreateCFProperties (disk) failed.");
- IOObjectRelease (disk_child);
- IOObjectRelease (disk);
- continue;
+ /* extract name and major/minor numbers */
+ memset (child_disk_name_bsd, 0, sizeof (child_disk_name_bsd));
+ tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (child_dict, CFSTR(kIOBSDNameKey));
+ if (tmp_cf_string_ref) {
+ assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
+ CFStringGetCString (tmp_cf_string_ref, child_disk_name_bsd, sizeof (child_disk_name_bsd), kCFStringEncodingUTF8);
}
+ disk_major = (int) dict_get_value (child_dict, kIOBSDMajorKey);
+ disk_minor = (int) dict_get_value (child_dict, kIOBSDMinorKey);
+ DEBUG ("disk plugin: child_disk_name_bsd=\"%s\" major=%d minor=%d", child_disk_name_bsd, disk_major, disk_minor);
+ CFRelease (child_dict);
+ IOObjectRelease (disk_child);
- /* tmp_cf_string_ref doesn't need to be released. */
- tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict,
- CFSTR(kIOBSDNameKey));
- if (!tmp_cf_string_ref)
- {
- DEBUG ("disk plugin: CFDictionaryGetValue("
- "kIOBSDNameKey) failed.");
- CFRelease (props_dict);
- IOObjectRelease (disk_child);
+ /* get property dictionary of the disk entry itself */
+ if (IORegistryEntryCreateCFProperties (disk, (CFMutableDictionaryRef *) &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || props_dict == NULL) {
+ ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
IOObjectRelease (disk);
continue;
}
- assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
- memset (disk_name_bsd, 0, sizeof (disk_name_bsd));
- CFStringGetCString (tmp_cf_string_ref,
- disk_name_bsd, sizeof (disk_name_bsd),
- kCFStringEncodingUTF8);
- if (disk_name_bsd[0] == 0)
- {
- ERROR ("disk plugin: CFStringGetCString() failed.");
- CFRelease (props_dict);
- IOObjectRelease (disk_child);
- IOObjectRelease (disk);
- continue;
+ /* extract name and stats dictionary */
+ memset (props_disk_name_bsd, 0, sizeof (props_disk_name_bsd));
+ tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict, CFSTR(kIOBSDNameKey));
+ if (tmp_cf_string_ref) {
+ assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
+ CFStringGetCString (tmp_cf_string_ref, props_disk_name_bsd, sizeof (props_disk_name_bsd), kCFStringEncodingUTF8);
}
- DEBUG ("disk plugin: disk_name_bsd = \"%s\"", disk_name_bsd);
-
- stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict,
- CFSTR (kIOBlockStorageDriverStatisticsKey));
-
- if (stats_dict == NULL)
- {
- DEBUG ("disk plugin: CFDictionaryGetValue ("
- "%s) failed.",
- kIOBlockStorageDriverStatisticsKey);
+ stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, CFSTR (kIOBlockStorageDriverStatisticsKey));
+ if (stats_dict == NULL) {
+ ERROR ("disk plugin: CFDictionaryGetValue (%s) failed.", kIOBlockStorageDriverStatisticsKey);
CFRelease (props_dict);
- IOObjectRelease (disk_child);
IOObjectRelease (disk);
continue;
}
-
- if (IORegistryEntryCreateCFProperties (disk_child,
- (CFMutableDictionaryRef *) &child_dict,
- kCFAllocatorDefault,
- kNilOptions)
- != kIOReturnSuccess)
- {
- DEBUG ("disk plugin: IORegistryEntryCreateCFProperties ("
- "disk_child) failed.");
- IOObjectRelease (disk_child);
- CFRelease (props_dict);
- IOObjectRelease (disk);
- continue;
+ DEBUG ("disk plugin: props_disk_name_bsd=\"%s\"", props_disk_name_bsd);
+
+ /* choose name */
+ if (use_bsd_name) {
+ if (child_disk_name_bsd[0] != 0)
+ sstrncpy (disk_name, child_disk_name_bsd, sizeof (disk_name));
+ else if (props_disk_name_bsd[0] != 0)
+ sstrncpy (disk_name, props_disk_name_bsd, sizeof (disk_name));
+ else {
+ ERROR ("disk plugin: can't find bsd disk name.");
+ ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
+ }
}
-
- /* kIOBSDNameKey */
- disk_major = (int) dict_get_value (child_dict,
- kIOBSDMajorKey);
- disk_minor = (int) dict_get_value (child_dict,
- kIOBSDMinorKey);
- read_ops = dict_get_value (stats_dict,
- kIOBlockStorageDriverStatisticsReadsKey);
- read_byt = dict_get_value (stats_dict,
- kIOBlockStorageDriverStatisticsBytesReadKey);
- read_tme = dict_get_value (stats_dict,
- kIOBlockStorageDriverStatisticsTotalReadTimeKey);
- write_ops = dict_get_value (stats_dict,
- kIOBlockStorageDriverStatisticsWritesKey);
- write_byt = dict_get_value (stats_dict,
- kIOBlockStorageDriverStatisticsBytesWrittenKey);
- /* This property describes the number of nanoseconds spent
- * performing writes since the block storage driver was
- * instantiated. It is one of the statistic entries listed
- * under the top-level kIOBlockStorageDriverStatisticsKey
- * property table. It has an OSNumber value. */
- write_tme = dict_get_value (stats_dict,
- kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
-
- if (use_bsd_name)
- sstrncpy (disk_name, disk_name_bsd, sizeof (disk_name));
else
- ssnprintf (disk_name, sizeof (disk_name), "%i-%i",
- disk_major, disk_minor);
- DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
+ ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
+
+ /* extract the stats */
+ read_ops = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsReadsKey);
+ read_byt = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesReadKey);
+ read_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalReadTimeKey);
+ write_ops = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsWritesKey);
+ write_byt = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesWrittenKey);
+ write_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
+ CFRelease (props_dict);
+ IOObjectRelease (disk);
+ /* and submit */
+ DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
if ((read_byt != -1LL) || (write_byt != -1LL))
disk_submit (disk_name, "disk_octets", read_byt, write_byt);
if ((read_ops != -1LL) || (write_ops != -1LL))
disk_submit (disk_name, "disk_ops", read_ops, write_ops);
if ((read_tme != -1LL) || (write_tme != -1LL))
- disk_submit (disk_name, "disk_time",
- read_tme / 1000,
- write_tme / 1000);
+ disk_submit (disk_name, "disk_time", read_tme / 1000, write_tme / 1000);
- CFRelease (child_dict);
- IOObjectRelease (disk_child);
- CFRelease (props_dict);
- IOObjectRelease (disk);
}
IOObjectRelease (disk_list);
/* #endif HAVE_IOKIT_IOKITLIB_H */
collector_t *this = (collector_t *)arg;
while (1) {
- int loop = 1;
-
conn_t *connection;
pthread_mutex_lock (&conns_mutex);
log_debug ("collect: handling connection on fd #%i",
fileno (this->socket));
- while (loop) {
+ while (42) {
/* 256 bytes ought to be enough for anybody ;-) */
char line[256 + 1]; /* line + '\0' */
int len = 0;
errno = 0;
if (NULL == fgets (line, sizeof (line), this->socket)) {
- loop = 0;
-
if (0 != errno) {
char errbuf[1024];
log_err ("collect: reading from socket (fd #%i) "
else {
log_err ("collect: unknown type '%c'", line[0]);
}
- } /* while (loop) */
+ } /* while (42) */
log_debug ("Shutting down connection on fd #%i",
fileno (this->socket));
return (0);
} /* int email_init */
-static int email_shutdown (void)
+static void type_list_free (type_list_t *t)
{
- type_t *ptr = NULL;
+ type_t *this;
+ this = t->head;
+ while (this != NULL)
+ {
+ type_t *next = this->next;
+
+ sfree (this->name);
+ sfree (this);
+
+ this = next;
+ }
+
+ t->head = NULL;
+ t->tail = NULL;
+}
+
+static int email_shutdown (void)
+{
int i = 0;
if (connector != ((pthread_t) 0)) {
pthread_mutex_unlock (&conns_mutex);
- for (ptr = list_count.head; NULL != ptr; ptr = ptr->next) {
- free (ptr->name);
- free (ptr);
- }
-
- for (ptr = list_count_copy.head; NULL != ptr; ptr = ptr->next) {
- free (ptr->name);
- free (ptr);
- }
-
- for (ptr = list_size.head; NULL != ptr; ptr = ptr->next) {
- free (ptr->name);
- free (ptr);
- }
-
- for (ptr = list_size_copy.head; NULL != ptr; ptr = ptr->next) {
- free (ptr->name);
- free (ptr);
- }
-
- for (ptr = list_check.head; NULL != ptr; ptr = ptr->next) {
- free (ptr->name);
- free (ptr);
- }
-
- for (ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next) {
- free (ptr->name);
- free (ptr);
- }
+ type_list_free (&list_count);
+ type_list_free (&list_count_copy);
+ type_list_free (&list_size);
+ type_list_free (&list_size_copy);
+ type_list_free (&list_check);
+ type_list_free (&list_check_copy);
unlink ((NULL == sock_file) ? SOCK_PATH : sock_file);
exit (-1);
}
- status = execvp (pl->exec, pl->argv);
+ execvp (pl->exec, pl->argv);
ERROR ("exec plugin: Failed to execute ``%s'': %s",
pl->exec, sstrerror (errno, errbuf, sizeof (errbuf)));
struct addrinfo *ai_ptr;
int ai_return;
- socket_entry_t *sockets;
- size_t sockets_num;
+ socket_entry_t *sockets = NULL;
+ size_t sockets_num = 0;
int status;
-
- sockets = *ret_sockets;
- sockets_num = *ret_sockets_num;
+
+ if (*ret_sockets != NULL)
+ return (EINVAL);
memset (&ai_hints, 0, sizeof (ai_hints));
ai_hints.ai_flags = 0;
freeaddrinfo (ai_list);
- if ((*ret_sockets_num) >= sockets_num)
+ if (sockets_num == 0)
+ {
+ sfree (sockets);
return (-1);
+ }
*ret_sockets = sockets;
*ret_sockets_num = sockets_num;
if ((map->ds_type == DS_TYPE_COUNTER)
|| (map->ds_type == DS_TYPE_ABSOLUTE))
val_copy = value_counter;
- if (map->ds_type == DS_TYPE_GAUGE)
+ else if (map->ds_type == DS_TYPE_GAUGE)
val_copy = value_gauge;
else if (map->ds_type == DS_TYPE_DERIVE)
val_copy = value_derive;
int i = 0;
if (0 != get_pi (se, pi, sizeof (pi)))
+ {
+ free (dests);
return;
+ }
cipvs_submit_connections (pi, NULL, stats.conns);
cipvs_submit_if (pi, "if_packets", NULL, stats.inpkts, stats.outpkts);
pthread_mutex_unlock (&java_callbacks_lock);
ERROR ("java plugin: cjni_callback_info_create: strdup failed.");
(*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
+ sfree (cbi);
return (NULL);
}
if (cbi->object == NULL)
{
ERROR ("java plugin: cjni_callback_info_create: NewGlobalRef failed.");
- free (cbi);
+ sfree (cbi->name);
+ sfree (cbi);
return (NULL);
}
if (cbi->class == NULL)
{
ERROR ("java plugin: cjni_callback_info_create: GetObjectClass failed.");
- free (cbi);
+ (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object);
+ sfree (cbi->name);
+ sfree (cbi);
return (NULL);
}
ERROR ("java plugin: cjni_callback_info_create: "
"Cannot find the `%s' method with signature `%s'.",
method_name, method_signature);
- free (cbi);
+ (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object);
+ sfree (cbi->name);
+ sfree (cbi);
return (NULL);
}
if (fd < 0)
{
status = errno;
- fd = -1;
continue;
}
{
status = errno;
close (fd);
- fd = -1;
continue;
}
{
status = errno;
close (fd);
- fd = -1;
continue;
}
noinst_LTLIBRARIES = liboconfig.la
-liboconfig_la_LDFLAGS = -version-info 0:0:0 $(LEXLIB)
+liboconfig_la_LDFLAGS = -avoid-version $(LEXLIB)
liboconfig_la_SOURCES = oconfig.c oconfig.h aux_types.h scanner.l parser.y
#include "oconfig.h"
extern FILE *yyin;
+extern int yyparse (void);
oconfig_item_t *ci_root;
const char *c_file;
/* Lexer variables */
extern int yylineno;
extern char *yytext;
+extern int yylex (void);
extern oconfig_item_t *ci_root;
extern char *c_file;
*/
%{
+/* lex and yacc do some weird stuff, so turn off some warnings. */
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunused-function"
+# pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
+#endif
+
#include <stdlib.h>
#include "oconfig.h"
#include "aux_types.h"
} /* while (status == 0) */
if (status != 0)
+ {
+ cmc_web_match_free (match);
return (status);
+ }
match->match = match_create_simple (match->regex, match->exclude_regex,
match->dstype);
uint16_t values[2];
int values_num;
const data_set_t *ds;
- int status;
+ int status = 0;
if ((host == NULL) || (slave == NULL) || (data == NULL))
return (EINVAL);
else
values_num = 1;
- status = 0;
if (host->connection == NULL)
{
status = EBADF;
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
- status = 0;
if (strcasecmp ("Type", child->key) == 0)
status = cf_util_get_string_buffer (child,
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
- status = 0;
if (strcasecmp ("Instance", child->key) == 0)
status = cf_util_get_string_buffer (child,
else if (strcmp (key, "Innodb_buffer_pool_pages_dirty") == 0)
gauge_submit ("mysql_bpool_pages", "dirty", val, db);
else if (strcmp (key, "Innodb_buffer_pool_pages_flushed") == 0)
- counter_submit ("mysql_bpool_pages", "flushed", val, db);
+ counter_submit ("mysql_bpool_counters", "pages_flushed", val, db);
else if (strcmp (key, "Innodb_buffer_pool_pages_free") == 0)
gauge_submit ("mysql_bpool_pages", "free", val, db);
else if (strcmp (key, "Innodb_buffer_pool_pages_misc") == 0)
static int network_config_ttl = 0;
/* Ethernet - (IPv6 + UDP) = 1500 - (40 + 8) = 1452 */
static size_t network_config_packet_size = 1452;
-static int network_config_forward = 0;
-static int network_config_stats = 0;
+static _Bool network_config_forward = 0;
+static _Bool network_config_stats = 0;
static sockent_t *sending_sockets = NULL;
_Bool received = 0;
int status;
- if (network_config_forward != 0)
+ if (network_config_forward)
return (1);
if (vl->meta == NULL)
if (type == SOCKENT_TYPE_SERVER)
{
se->data.server.fd = NULL;
+ se->data.server.fd_num = 0;
#if HAVE_LIBGCRYPT
se->data.server.security_level = SECURITY_LEVEL_NONE;
se->data.server.auth_file = NULL;
if (se == NULL)
return (-1);
+ assert (se->data.server.fd == NULL);
+ assert (se->data.server.fd_num == 0);
+
node = se->node;
service = se->service;
int buffer_len;
int i;
- int status;
+ int status = 0;
receive_list_entry_t *private_list_head;
receive_list_entry_t *private_list_tail;
uint64_t private_list_length;
- assert (listen_sockets_num > 0);
+ assert (listen_sockets_num > 0);
private_list_head = NULL;
private_list_tail = NULL;
while (listen_loop == 0)
{
status = poll (listen_sockets_pollfd, listen_sockets_num, -1);
-
if (status <= 0)
{
char errbuf[1024];
if (errno == EINTR)
continue;
- ERROR ("poll failed: %s",
+ ERROR ("network plugin: poll(2) failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
+ break;
}
for (i = 0; (i < listen_sockets_num) && (status > 0); i++)
if (buffer_len < 0)
{
char errbuf[1024];
- ERROR ("recv failed: %s",
- sstrerror (errno, errbuf,
- sizeof (errbuf)));
- return (-1);
+ status = (errno != 0) ? errno : -1;
+ ERROR ("network plugin: recv(2) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ break;
}
stats_octets_rx += ((uint64_t) buffer_len);
if (ent == NULL)
{
ERROR ("network plugin: malloc failed.");
- return (-1);
+ status = ENOMEM;
+ break;
}
memset (ent, 0, sizeof (receive_list_entry_t));
ent->data = malloc (network_config_packet_size);
{
sfree (ent);
ERROR ("network plugin: malloc failed.");
- return (-1);
+ status = ENOMEM;
+ break;
}
ent->fd = listen_sockets_pollfd[i].fd;
ent->next = NULL;
private_list_tail = NULL;
private_list_length = 0;
}
+
+ status = 0;
} /* for (listen_sockets_pollfd) */
+
+ if (status != 0)
+ break;
} /* while (listen_loop == 0) */
/* Make sure everything is dispatched before exiting. */
receive_list_tail = private_list_tail;
receive_list_length += private_list_length;
- private_list_head = NULL;
- private_list_tail = NULL;
- private_list_length = 0;
-
pthread_cond_signal (&receive_list_cond);
pthread_mutex_unlock (&receive_list_lock);
}
- return (0);
+ return (status);
} /* }}} int network_receive */
static void *receive_thread (void __attribute__((unused)) *arg)
return ((status < 0) ? -1 : 0);
} /* int network_write */
-static int network_config_set_boolean (const oconfig_item_t *ci, /* {{{ */
- int *retval)
-{
- if ((ci->values_num != 1)
- || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN)
- && (ci->values[0].type != OCONFIG_TYPE_STRING)))
- {
- ERROR ("network plugin: The `%s' config option needs "
- "exactly one boolean argument.", ci->key);
- return (-1);
- }
-
- if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
- {
- if (ci->values[0].value.boolean)
- *retval = 1;
- else
- *retval = 0;
- }
- else
- {
- char *str = ci->values[0].value.string;
-
- if (IS_TRUE (str))
- *retval = 1;
- else if (IS_FALSE (str))
- *retval = 0;
- else
- {
- ERROR ("network plugin: Cannot parse string value `%s' of the `%s' "
- "option as boolean value.",
- str, ci->key);
- return (-1);
- }
- }
-
- return (0);
-} /* }}} int network_config_set_boolean */
-
static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
{
- int tmp;
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
- {
- WARNING ("network plugin: The `TimeToLive' config option needs exactly "
- "one numeric argument.");
- return (-1);
- }
+ int tmp = 0;
- tmp = (int) ci->values[0].value.number;
- if ((tmp > 0) && (tmp <= 255))
+ if (cf_util_get_int (ci, &tmp) != 0)
+ return (-1);
+ else if ((tmp > 0) && (tmp <= 255))
network_config_ttl = tmp;
else {
WARNING ("network plugin: The `TimeToLive' must be between 1 and 255.");
static int network_config_set_interface (const oconfig_item_t *ci, /* {{{ */
int *interface)
{
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("network plugin: The `Interface' config option needs exactly "
- "one string argument.");
- return (-1);
- }
+ char if_name[256];
- if (interface == NULL)
+ if (cf_util_get_string_buffer (ci, if_name, sizeof (if_name)) != 0)
return (-1);
- *interface = if_nametoindex (ci->values[0].value.string);
-
+ *interface = if_nametoindex (if_name);
return (0);
} /* }}} int network_config_set_interface */
static int network_config_set_buffer_size (const oconfig_item_t *ci) /* {{{ */
{
- int tmp;
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
- {
- WARNING ("network plugin: The `MaxPacketSize' config option needs exactly "
- "one numeric argument.");
- return (-1);
- }
+ int tmp = 0;
- tmp = (int) ci->values[0].value.number;
- if ((tmp >= 1024) && (tmp <= 65535))
+ if (cf_util_get_int (ci, &tmp) != 0)
+ return (-1);
+ else if ((tmp >= 1024) && (tmp <= 65535))
network_config_packet_size = tmp;
-
- return (0);
-} /* }}} int network_config_set_buffer_size */
-
-#if HAVE_LIBGCRYPT
-static int network_config_set_string (const oconfig_item_t *ci, /* {{{ */
- char **ret_string)
-{
- char *tmp;
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("network plugin: The `%s' config option needs exactly "
- "one string argument.", ci->key);
+ else {
+ WARNING ("network plugin: The `MaxPacketSize' must be between 1024 and 65535.");
return (-1);
}
- tmp = strdup (ci->values[0].value.string);
- if (tmp == NULL)
- return (-1);
-
- sfree (*ret_string);
- *ret_string = tmp;
-
return (0);
-} /* }}} int network_config_set_string */
-#endif /* HAVE_LIBGCRYPT */
+} /* }}} int network_config_set_buffer_size */
#if HAVE_LIBGCRYPT
static int network_config_set_security_level (oconfig_item_t *ci, /* {{{ */
#if HAVE_LIBGCRYPT
if (strcasecmp ("AuthFile", child->key) == 0)
- network_config_set_string (child, &se->data.server.auth_file);
+ cf_util_get_string (child, &se->data.server.auth_file);
else if (strcasecmp ("SecurityLevel", child->key) == 0)
network_config_set_security_level (child,
&se->data.server.security_level);
else
#endif /* HAVE_LIBGCRYPT */
if (strcasecmp ("Interface", child->key) == 0)
- network_config_set_interface (child,
- &se->interface);
+ network_config_set_interface (child, &se->interface);
else
{
WARNING ("network plugin: Option `%s' is not allowed here.",
#if HAVE_LIBGCRYPT
if (strcasecmp ("Username", child->key) == 0)
- network_config_set_string (child, &se->data.client.username);
+ cf_util_get_string (child, &se->data.client.username);
else if (strcasecmp ("Password", child->key) == 0)
- network_config_set_string (child, &se->data.client.password);
+ cf_util_get_string (child, &se->data.client.password);
else if (strcasecmp ("SecurityLevel", child->key) == 0)
network_config_set_security_level (child,
&se->data.client.security_level);
else
#endif /* HAVE_LIBGCRYPT */
if (strcasecmp ("Interface", child->key) == 0)
- network_config_set_interface (child,
- &se->interface);
- else if (strcasecmp ("ResolveInterval", child->key) == 0)
- cf_util_get_cdtime(child, &se->data.client.resolve_interval);
+ network_config_set_interface (child, &se->interface);
+ else if (strcasecmp ("ResolveInterval", child->key) == 0)
+ cf_util_get_cdtime(child, &se->data.client.resolve_interval);
else
{
WARNING ("network plugin: Option `%s' is not allowed here.",
else if (strcasecmp ("MaxPacketSize", child->key) == 0)
network_config_set_buffer_size (child);
else if (strcasecmp ("Forward", child->key) == 0)
- network_config_set_boolean (child, &network_config_forward);
+ cf_util_get_boolean (child, &network_config_forward);
else if (strcasecmp ("ReportStats", child->key) == 0)
- network_config_set_boolean (child, &network_config_stats);
+ cf_util_get_boolean (child, &network_config_stats);
else
{
WARNING ("network plugin: Option `%s' is not allowed here.",
network_init_gcrypt ();
#endif
- if (network_config_stats != 0)
+ if (network_config_stats)
plugin_register_read ("network", network_stats_read);
plugin_register_shutdown ("network", network_shutdown);
case 42:
case 44:
proc40_names_num = 36;
+ break;
case 46:
case 47:
case 51:
(items_num + pkt_item_num) * res_item_size);
if (items == NULL)
{
- items = *res_data;
ERROR ("ntpd plugin: realloc failed.");
continue;
}
if (endptr == NULL)
{
ERROR ("onewire plugin: Buffer is not a number: %s", buffer);
- status = -1;
continue;
}
if (endptr == NULL)
{
ERROR ("onewire plugin: Buffer is not a number: %s", buffer);
- status = -1;
continue;
}
{
char *name;
+ char *binddn;
+ char *password;
char *cacert;
char *host;
int state;
if (st == NULL)
return;
+ sfree (st->binddn);
+ sfree (st->password);
sfree (st->cacert);
sfree (st->host);
sfree (st->name);
}
struct berval cred;
- cred.bv_val = "";
- cred.bv_len = 0;
+ if (st->password != NULL)
+ {
+ cred.bv_val = st->password;
+ cred.bv_len = strlen (st->password);
+ }
+ else
+ {
+ cred.bv_val = "";
+ cred.bv_len = 0;
+ }
- rc = ldap_sasl_bind_s (st->ld, NULL, NULL, &cred, NULL, NULL, NULL);
+ rc = ldap_sasl_bind_s (st->ld, st->binddn, LDAP_SASL_SIMPLE, &cred,
+ NULL, NULL, NULL);
if (rc != LDAP_SUCCESS)
{
ERROR ("openldap plugin: Failed to bind to %s: %s",
{
oconfig_item_t *child = ci->children + i;
- if (strcasecmp ("CACert", child->key) == 0)
+ if (strcasecmp ("BindDN", child->key) == 0)
+ status = cf_util_get_string (child, &st->binddn);
+ else if (strcasecmp ("Password", child->key) == 0)
+ status = cf_util_get_string (child, &st->password);
+ else if (strcasecmp ("CACert", child->key) == 0)
status = cf_util_get_string (child, &st->cacert);
else if (strcasecmp ("StartTLS", child->key) == 0)
status = cf_util_get_boolean (child, &st->starttls);
st->name, st->url);
status = -1;
}
- else
+
+ if ((status == 0) && (ludpp->lud_host != NULL))
{
st->host = strdup (ludpp->lud_host);
}
post_compress = 0;
pre_decompress = 0;
post_decompress = 0;
- overhead_rx = 0;
- overhead_tx = 0;
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
static int openvpn_read (void)
{
FILE *fh;
- int i, vpn_read, read;
+ int i, read;
- vpn_read = read = 0;
+ read = 0;
/* call the right read function for every status entry in the list */
for (i = 0; i < vpn_num; i++)
{
+ int vpn_read = 0;
+
fh = fopen (vpn_list[i]->file, "r");
if (fh == NULL)
{
if (NULL == (tmp = hv_fetch (hash, "value", 5, 0))) {
log_warn ("av2notification_meta: Skipping invalid "
"meta information.");
- free ((*m)->name);
free (*m);
continue;
}
* `ts_wait'. */
time_calc (&ts_wait, &ts_int, &tv_begin, &tv_end);
- status = pthread_cond_timedwait (&ping_cond, &ping_lock, &ts_wait);
+ pthread_cond_timedwait (&ping_cond, &ping_lock, &ts_wait);
if (ping_thread_loop <= 0)
break;
} /* while (ping_thread_loop > 0) */
timeout.tv_sec=5;
timeout.tv_usec=0;
status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof (timeout));
+ if (status != 0)
+ {
+ FUNC_ERROR ("setsockopt");
+ close (sd);
+ return (-1);
+ }
status = connect (sd, (struct sockaddr *) &item->sockaddr,
sizeof (item->sockaddr));
buffer[buffer_size] = 0;
} /* while (42) */
close (sd);
- sd = -1;
if (status < 0)
{
return (0);
} /* }}} int powerdns_read_recursor */
-static int powerdns_config_add_string (const char *name, /* {{{ */
- char **dest,
- oconfig_item_t *ci)
-{
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- WARNING ("powerdns plugin: `%s' needs exactly one string argument.",
- name);
- return (-1);
- }
-
- sfree (*dest);
- *dest = strdup (ci->values[0].value.string);
- if (*dest == NULL)
- return (-1);
-
- return (0);
-} /* }}} int powerdns_config_add_string */
-
static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
oconfig_item_t *ci)
{
if (strcasecmp ("Collect", option->key) == 0)
status = powerdns_config_add_collect (item, option);
else if (strcasecmp ("Socket", option->key) == 0)
- status = powerdns_config_add_string ("Socket", &socket_temp, option);
+ status = cf_util_get_string (option, &socket_temp);
else
{
ERROR ("powerdns plugin: Option `%s' not allowed here.", option->key);
if (status != 0)
{
+ sfree (socket_temp);
sfree (item);
return (-1);
}
DEBUG ("powerdns plugin: Add server: instance = %s;", item->instance);
+ sfree (socket_temp);
return (0);
} /* }}} int powerdns_config_add_server */
new_rc = 1;
}
+ assert (value_time > 0); /* plugin_dispatch() ensures this. */
if (rc->last_value >= value_time)
{
pthread_mutex_unlock (&cache_lock);
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
- status = 0;
if (strcasecmp ("Type", option->key) == 0)
status = cf_util_get_string(option, &dd->type);
return (-1);
}
assert (ds->ds_num == data->values_len);
+ assert (data->values_len > 0);
instance_list_ptr = instance_list;
- value_table_ptr = malloc (sizeof (*value_table_ptr) * data->values_len);
+ value_table_ptr = calloc ((size_t) data->values_len, sizeof (*value_table_ptr));
if (value_table_ptr == NULL)
return (-1);
for (i = 0; i < data->values_len; i++)
value_table_ptr[i] = value_table[i];
- vl.values_len = ds->ds_num;
+ vl.values_len = data->values_len;
vl.values = malloc (sizeof (*vl.values) * vl.values_len);
if (vl.values == NULL)
{
data->type, ds->ds_num, data->values_len);
return (-1);
}
+ assert (data->values_len > 0);
/* We need a copy of all the OIDs, because GETNEXT will destroy them. */
memcpy (oid_list, data->values, data->values_len * sizeof (oid_t));
for (vb = res->variables, i = 0; (vb != NULL); vb = vb->next_variable, i++)
{
/* Calculate value index from todo list */
- while (!oid_list_todo[i] && (i < oid_list_len))
+ while ((i < oid_list_len) && !oid_list_todo[i])
i++;
/* An instance is configured and the res variable we process is the
if (NULL == tbl->sep) {
log_err ("Table \"%s\" does not specify any separator.", tbl->file);
status = 1;
+ } else {
+ strunescape (tbl->sep, strlen (tbl->sep) + 1);
}
- strunescape (tbl->sep, strlen (tbl->sep) + 1);
if (NULL == tbl->instance) {
tbl->instance = sstrdup (tbl->file);
cdtime_t interval = 0;
char *plugin_instance = NULL;
int num_matches = 0;
- int status;
int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
return (-1);
}
- status = 0;
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
+ int status = 0;
if (strcasecmp ("Instance", option->key) == 0)
status = cf_util_get_string (option, &plugin_instance);
for (i = 0; i < ci->children_num; ++i){
oconfig_item_t *option = ci->children + i;
- status = 0;
if (strcasecmp("Type", option->key) == 0)
status = cf_util_get_string(option, &md->type);
if (status != 0)
{
- tn_destroy ((void *) data);
+ tn_destroy ((void *) &data);
return (status);
}
/* Loop until we find the end of the package */
end_flag = 0;
- escape_flag = 0;
package_buffer_pos = 0;
while (end_flag == 0)
{
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
- status = 0;
if (strcasecmp ("Instance", option->key) == 0)
status = ut_config_type_instance (&th, option);
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
- status = 0;
if (strcasecmp ("Type", option->key) == 0)
status = ut_config_type (&th, option);
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
- status = 0;
if (strcasecmp ("Type", option->key) == 0)
status = ut_config_type (&th, option);
if (state == STATE_OKAY)
{
if (state_old == STATE_MISSING)
- status = ssnprintf (buf, bufsize,
- ": Value is no longer missing.");
+ ssnprintf (buf, bufsize, ": Value is no longer missing.");
else
- status = ssnprintf (buf, bufsize,
+ ssnprintf (buf, bufsize,
": All data sources are within range again. "
"Current value of \"%s\" is %f.",
ds->ds[ds_index].name, values[ds_index]);
- buf += status;
- bufsize -= status;
}
else
{
{
if (!isnan (min) && !isnan (max))
{
- status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+ ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
"%f. That is within the %s region of %f%s and %f%s.",
ds->ds[ds_index].name, values[ds_index],
(state == STATE_ERROR) ? "failure" : "warning",
}
else
{
- status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
- "%f. That is %s the %s threshold of %f%s.",
- ds->ds[ds_index].name, values[ds_index],
- isnan (min) ? "below" : "above",
- (state == STATE_ERROR) ? "failure" : "warning",
- isnan (min) ? max : min,
- ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
+ ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+ "%f. That is %s the %s threshold of %f%s.",
+ ds->ds[ds_index].name, values[ds_index],
+ isnan (min) ? "below" : "above",
+ (state == STATE_ERROR) ? "failure" : "warning",
+ isnan (min) ? max : min,
+ ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
}
}
else if (th->flags & UT_FLAG_PERCENTAGE)
else
value = 100.0 * values[ds_index] / sum;
- status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+ ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
"%g (%.2f%%). That is %s the %s threshold of %.2f%%.",
ds->ds[ds_index].name, values[ds_index], value,
(value < min) ? "below" : "above",
}
else /* is not inverted */
{
- status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
- "%f. That is %s the %s threshold of %f.",
- ds->ds[ds_index].name, values[ds_index],
- (values[ds_index] < min) ? "below" : "above",
- (state == STATE_ERROR) ? "failure" : "warning",
- (values[ds_index] < min) ? min : max);
+ ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+ "%f. That is %s the %s threshold of %f.",
+ ds->ds[ds_index].name, values[ds_index],
+ (values[ds_index] < min) ? "below" : "above",
+ (state == STATE_ERROR) ? "failure" : "warning",
+ (values[ds_index] < min) ? min : max);
}
- buf += status;
- bufsize -= status;
}
plugin_dispatch_notification (&n);
for (i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
- status = 0;
if (strcasecmp ("Type", option->key) == 0)
status = ut_config_type (&th, option);
unsigned int i;
unsigned int total_threads, total_cores;
+ if ((topology.num_threads == 0)
+ || (topology.num_cores == 0)
+ || (topology.num_packages == 0))
+ {
+ ERROR ("turbostat plugin: Invalid topology: %u threads, %u cores, %u packages",
+ topology.num_threads, topology.num_cores, topology.num_packages);
+ return -1;
+ }
+
total_threads = topology.num_threads * topology.num_cores * topology.num_packages;
*threads = calloc(total_threads, sizeof(struct thread_data));
if (*threads == NULL)
- goto err;
+ {
+ ERROR ("turbostat plugin: calloc failed");
+ return -1;
+ }
for (i = 0; i < total_threads; ++i)
(*threads)[i].cpu_id = topology.max_cpu_id + 1;
total_cores = topology.num_cores * topology.num_packages;
*cores = calloc(total_cores, sizeof(struct core_data));
if (*cores == NULL)
- goto err_clean_threads;
+ {
+ ERROR ("turbostat plugin: calloc failed");
+ sfree (threads);
+ return -1;
+ }
*packages = calloc(topology.num_packages, sizeof(struct pkg_data));
if (*packages == NULL)
- goto err_clean_cores;
+ {
+ ERROR ("turbostat plugin: calloc failed");
+ sfree (cores);
+ sfree (threads);
+ return -1;
+ }
return 0;
-
-err_clean_cores:
- free(*cores);
-err_clean_threads:
- free(*threads);
-err:
- ERROR("turbostat plugin: Failled to allocate memory for counters");
- return -1;
}
static void
#include "plugin.h"
#include "utils_parse_option.h"
-#define print_to_socket(fh, ...) \
- do { \
- if (fprintf (fh, __VA_ARGS__) < 0) { \
- char errbuf[1024]; \
- WARNING ("handle_flush: failed to write to socket #%i: %s", \
- fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
- return -1; \
- } \
- fflush(fh); \
- } while (0)
-
-static int add_to_array (char ***array, int *array_num, char *value)
-{
- char **temp;
-
- temp = (char **) realloc (*array, sizeof (char *) * (*array_num + 1));
- if (temp == NULL)
- return (-1);
-
- *array = temp;
- (*array)[*array_num] = value;
- (*array_num)++;
-
- return (0);
-} /* int add_to_array */
-
int handle_flush (FILE *fh, char *buffer)
{
int success = 0;
double timeout = 0.0;
char **plugins = NULL;
- int plugins_num = 0;
+ size_t plugins_num = 0;
char **identifiers = NULL;
- int identifiers_num = 0;
+ size_t identifiers_num = 0;
- int i;
+ size_t i;
+
+#define PRINT_TO_SOCK(fh, ...) \
+ do { \
+ if (fprintf (fh, __VA_ARGS__) < 0) { \
+ char errbuf[1024]; \
+ WARNING ("handle_flush: failed to write to socket #%i: %s", \
+ fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+ strarray_free (plugins, plugins_num); \
+ strarray_free (identifiers, identifiers_num); \
+ return -1; \
+ } \
+ fflush(fh); \
+ } while (0)
if ((fh == NULL) || (buffer == NULL))
return (-1);
if (strncasecmp ("FLUSH", buffer, strlen ("FLUSH")) != 0)
{
- print_to_socket (fh, "-1 Cannot parse command.\n");
+ PRINT_TO_SOCK (fh, "-1 Cannot parse command.\n");
return (-1);
}
buffer += strlen ("FLUSH");
status = parse_option (&buffer, &opt_key, &opt_value);
if (status != 0)
{
- print_to_socket (fh, "-1 Parsing options failed.\n");
- sfree (plugins);
- sfree (identifiers);
+ PRINT_TO_SOCK (fh, "-1 Parsing options failed.\n");
+ strarray_free (plugins, plugins_num);
+ strarray_free (identifiers, identifiers_num);
return (-1);
}
if (strcasecmp ("plugin", opt_key) == 0)
- {
- add_to_array (&plugins, &plugins_num, opt_value);
- }
+ strarray_add (&plugins, &plugins_num, opt_value);
else if (strcasecmp ("identifier", opt_key) == 0)
- {
- add_to_array (&identifiers, &identifiers_num, opt_value);
- }
+ strarray_add (&identifiers, &identifiers_num, opt_value);
else if (strcasecmp ("timeout", opt_key) == 0)
{
char *endptr;
-
+
errno = 0;
endptr = NULL;
timeout = strtod (opt_value, &endptr);
if ((endptr == opt_value) || (errno != 0) || (!isfinite (timeout)))
{
- print_to_socket (fh, "-1 Invalid value for option `timeout': "
+ PRINT_TO_SOCK (fh, "-1 Invalid value for option `timeout': "
"%s\n", opt_value);
- sfree (plugins);
- sfree (identifiers);
+ strarray_free (plugins, plugins_num);
+ strarray_free (identifiers, identifiers_num);
return (-1);
}
else if (timeout < 0.0)
}
else
{
- print_to_socket (fh, "-1 Cannot parse option %s\n", opt_key);
- sfree (plugins);
- sfree (identifiers);
+ PRINT_TO_SOCK (fh, "-1 Cannot parse option %s\n", opt_key);
+ strarray_free (plugins, plugins_num);
+ strarray_free (identifiers, identifiers_num);
return (-1);
}
} /* while (*buffer != 0) */
- /* Add NULL entries for `any plugin' and/or `any value' if nothing was
- * specified. */
- if (plugins_num == 0)
- add_to_array (&plugins, &plugins_num, NULL);
-
- if (identifiers_num == 0)
- add_to_array (&identifiers, &identifiers_num, NULL);
-
- for (i = 0; i < plugins_num; i++)
+ for (i = 0; (i == 0) || (i < plugins_num); i++)
{
- char *plugin;
+ char *plugin = NULL;
int j;
- plugin = plugins[i];
+ if (plugins_num != 0)
+ plugin = plugins[i];
- for (j = 0; j < identifiers_num; j++)
+ for (j = 0; (j == 0) || (j < identifiers_num); j++)
{
- char *identifier;
+ char *identifier = NULL;
int status;
- identifier = identifiers[j];
+ if (identifiers_num != 0)
+ identifier = identifiers[j];
+
status = plugin_flush (plugin,
DOUBLE_TO_CDTIME_T (timeout),
identifier);
}
}
- if ((success + error) > 0)
- {
- print_to_socket (fh, "0 Done: %i successful, %i errors\n",
- success, error);
- }
- else
- {
- plugin_flush (NULL, DOUBLE_TO_CDTIME_T (timeout), NULL);
- print_to_socket (fh, "0 Done\n");
- }
+ PRINT_TO_SOCK (fh, "0 Done: %i successful, %i errors\n",
+ success, error);
- sfree (plugins);
- sfree (identifiers);
+ strarray_free (plugins, plugins_num);
+ strarray_free (identifiers, identifiers_num);
return (0);
+#undef PRINT_TO_SOCK
} /* int handle_flush */
/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
char errbuf[1024]; \
WARNING ("handle_putval: failed to write to socket #%i: %s", \
fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+ sfree (vl.values); \
return -1; \
} \
fflush(fh); \
} while (0)
-static int dispatch_values (const data_set_t *ds, value_list_t *vl,
- FILE *fh, char *buffer)
-{
- int status;
-
- status = parse_values (buffer, vl, ds);
- if (status != 0)
- {
- print_to_socket (fh, "-1 Parsing the values string failed.\n");
- return (-1);
- }
-
- plugin_dispatch_values (vl);
- return (0);
-} /* int dispatch_values */
-
static int set_option (value_list_t *vl, const char *key, const char *value)
{
if ((vl == NULL) || (key == NULL) || (value == NULL))
const data_set_t *ds;
value_list_t vl = VALUE_LIST_INIT;
+ vl.values = NULL;
DEBUG ("utils_cmd_putval: handle_putval (fh = %p, buffer = %s);",
(void *) fh, buffer);
/* parse_option failed, buffer has been modified.
* => we need to abort */
print_to_socket (fh, "-1 Misformatted option.\n");
+ sfree (vl.values);
return (-1);
}
else if (status == 0)
if (status != 0)
{
print_to_socket (fh, "-1 Misformatted value.\n");
+ sfree (vl.values);
return (-1);
}
assert (string != NULL);
- status = dispatch_values (ds, &vl, fh, string);
+ status = parse_values (string, &vl, ds);
if (status != 0)
{
- /* An error has already been printed. */
+ print_to_socket (fh, "-1 Parsing the values string failed.\n");
+ sfree (vl.values);
return (-1);
}
+
+ plugin_dispatch_values (&vl);
values_submitted++;
} /* while (*buffer != 0) */
/* Done parsing the options. */
values_submitted,
(values_submitted == 1) ? "value has" : "values have");
- sfree (vl.values);
-
+ sfree (vl.values);
return (0);
} /* int handle_putval */
assert (r != NULL);
assert (r_area->ds != NULL);
assert (((size_t) r_area->ds->ds_num) == r->values_num);
+ assert (r->values_num > 0);
- vl.values = (value_t *) calloc (r_area->ds->ds_num, sizeof (value_t));
+ vl.values = (value_t *) calloc (r->values_num, sizeof (value_t));
if (vl.values == NULL)
{
ERROR ("db query utils: malloc failed.");
udb_result_preparation_area_t **next_r_area;
udb_result_t *r;
- q_area = (udb_query_preparation_area_t *)malloc (sizeof (*q_area));
+ q_area = malloc (sizeof (*q_area));
if (q_area == NULL)
return NULL;
-
memset (q_area, 0, sizeof (*q_area));
next_r_area = &q_area->result_prep_areas;
{
udb_result_preparation_area_t *r_area;
- r_area = (udb_result_preparation_area_t *)malloc (sizeof (*r_area));
+ r_area = malloc (sizeof (*r_area));
if (r_area == NULL)
{
- for (r_area = q_area->result_prep_areas;
- r_area != NULL; r_area = r_area->next)
+ udb_result_preparation_area_t *a = q_area->result_prep_areas;
+
+ while (a != NULL)
{
- free (r_area);
+ udb_result_preparation_area_t *next = a->next;
+ sfree (a);
+ a = next;
}
+
free (q_area);
return NULL;
}
if (errsize)
sfree (regerr);
regfree (regtemp);
+ sfree (regtemp);
return (1);
}
DEBUG("regex compiled: %s - %i", entry, rcompile);
{
ERROR ("cannot allocate new config entry");
regfree (regtemp);
+ sfree (regtemp);
return (1);
}
memset (new, '\0', sizeof(ignorelist_item_t));
if (this->rmatch != NULL)
{
regfree (this->rmatch);
+ sfree (this->rmatch);
this->rmatch = NULL;
}
#endif
lc = malloc (sizeof (*lc));
if (lc == NULL)
return (NULL);
+ memset (lc, 0, sizeof (*lc));
latency_counter_reset (lc);
lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH;
int rra_max;
- int span;
-
int cdp_num;
int cdp_len;
int i, j;
- char buffer[128];
-
/* The stepsize we use here: If it is user-set, use it. If not, use the
* interval of the value-list. */
int ss;
}
rra_max = rts_num * rra_types_num;
+ assert (rra_max > 0);
- if ((rra_def = (char **) malloc ((rra_max + 1) * sizeof (char *))) == NULL)
+ if ((rra_def = malloc ((rra_max + 1) * sizeof (*rra_def))) == NULL)
return (-1);
- memset (rra_def, '\0', (rra_max + 1) * sizeof (char *));
+ memset (rra_def, 0, (rra_max + 1) * sizeof (*rra_def));
rra_num = 0;
cdp_len = 0;
for (i = 0; i < rts_num; i++)
{
- span = rts[i];
+ int span = rts[i];
if ((span / ss) < cfg->rrarows)
span = ss * cfg->rrarows;
for (j = 0; j < rra_types_num; j++)
{
+ char buffer[128];
int status;
if (rra_num >= rra_max)
}
}
+ if (rra_num <= 0)
+ {
+ sfree (rra_def);
+ return (0);
+ }
+
*ret = rra_def;
return (rra_num);
} /* }}} int rra_get */
char max[32];
char buffer[128];
- ds_def = (char **) malloc (ds->ds_num * sizeof (char *));
+ assert (ds->ds_num > 0);
+
+ ds_def = malloc (ds->ds_num * sizeof (*ds_def));
if (ds_def == NULL)
{
char errbuf[1024];
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
- memset (ds_def, '\0', ds->ds_num * sizeof (char *));
+ memset (ds_def, 0, ds->ds_num * sizeof (*ds_def));
for (ds_num = 0; ds_num < ds->ds_num; ds_num++)
{
return (-1);
}
+ if (ds_num <= 0)
+ {
+ sfree (ds_def);
+ return (0);
+ }
+
*ret = ds_def;
return (ds_num);
} /* }}} int ds_get */
{
char **argv;
int argc;
- char **rra_def;
+ char **rra_def = NULL;
int rra_num;
- char **ds_def;
+ char **ds_def = NULL;
int ds_num;
int status = 0;
time_t last_up;
if ((ds_num = ds_get (&ds_def, ds, vl, cfg)) < 1)
{
ERROR ("cu_rrd_create_file failed: Could not calculate DSes");
+ rra_free (rra_num, rra_def);
return (-1);
}
char errbuf[1024];
ERROR ("cu_rrd_create_file failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
+ rra_free (rra_num, rra_def);
+ ds_free (ds_num, ds_def);
return (-1);
}
}
else /* synchronous */
{
- status = srrd_create (filename, stepsize, last_up,
- argc, (const char **) argv);
-
+ status = lock_file (filename);
if (status != 0)
{
- WARNING ("cu_rrd_create_file: srrd_create (%s) returned status %i.",
- filename, status);
+ if (status == EEXIST)
+ NOTICE ("cu_rrd_create_file: File \"%s\" is already being created.",
+ filename);
+ else
+ ERROR ("cu_rrd_create_file: Unable to lock file \"%s\".",
+ filename);
}
else
{
- DEBUG ("cu_rrd_create_file: Successfully created RRD file \"%s\".",
- filename);
+ status = srrd_create (filename, stepsize, last_up,
+ argc, (const char **) argv);
+
+ if (status != 0)
+ {
+ WARNING ("cu_rrd_create_file: srrd_create (%s) returned status %i.",
+ filename, status);
+ }
+ else
+ {
+ DEBUG ("cu_rrd_create_file: Successfully created RRD file \"%s\".",
+ filename);
+ }
+ unlock_file (filename);
}
}
int new_size = sizeof (interface_devices[0]) * (nr_interface_devices+1);
char *path_copy, *address_copy, number_string[15];
+ if ((path == NULL) || (address == NULL))
+ return EINVAL;
+
path_copy = strdup (path);
if (!path_copy) return -1;
char *name;
int n, r;
+ if ((domname == NULL) || (devpath == NULL))
+ return 0;
+
n = sizeof (char) * (strlen (domname) + strlen (devpath) + 2);
name = malloc (n);
if (name == NULL) {
#undef APPEND
+ status = format_values (value_ptr, value_size, ds, vl, /* store rates = */ 0);
pthread_mutex_lock (&node->lock);
+ if (status != 0)
+ return (status);
if (node->conn == NULL)
{
int reference_count;
};
-static char *sensu_tags;
-static char **sensu_attrs;
+static char *sensu_tags = NULL;
+static char **sensu_attrs = NULL;
static size_t sensu_attrs_num;
static int add_str_to_list(struct str_list *strs,
const char *p, *q;
size_t oldlen = strlen(old);
size_t count = strlen(new);
- size_t retlen = count;
+ size_t retlen;
size_t newlen = count;
int samesize = (oldlen == newlen);
sensu_tags_arr.nb_strs = 0;
sensu_tags_arr.strs = NULL;
- sensu_tags = malloc(sizeof(char));
- if (sensu_tags == NULL) {
- ERROR("write_sensu plugin: Unable to alloc memory");
- return -1;
- }
- sensu_tags[0] = '\0';
for (i = 0; i < ci->children_num; i++) {
child = &ci->children[i];
if (strcasecmp("Node", child->key) == 0) {
sensu_config_node(child);
} else if (strcasecmp(child->key, "attribute") == 0) {
- char *key = NULL;
- char *val = NULL;
-
if (child->values_num != 2) {
WARNING("sensu attributes need both a key and a value.");
- free(sensu_tags);
- return -1;
+ continue;
}
if (child->values[0].type != OCONFIG_TYPE_STRING ||
- child->values[1].type != OCONFIG_TYPE_STRING) {
+ child->values[1].type != OCONFIG_TYPE_STRING) {
WARNING("sensu attribute needs string arguments.");
- free(sensu_tags);
- return -1;
- }
- if ((key = strdup(child->values[0].value.string)) == NULL) {
- ERROR("write_sensu plugin: Unable to alloc memory");
- free(sensu_tags);
- return -1;
- }
- if ((val = strdup(child->values[1].value.string)) == NULL) {
- free(sensu_tags);
- free(key);
- ERROR("write_sensu plugin: Unable to alloc memory");
- return -1;
+ continue;
}
- strarray_add(&sensu_attrs, &sensu_attrs_num, key);
- strarray_add(&sensu_attrs, &sensu_attrs_num, val);
- DEBUG("write_sensu: got attr: %s => %s", key, val);
- sfree(key);
- sfree(val);
+
+ strarray_add(&sensu_attrs, &sensu_attrs_num, child->values[0].value.string);
+ strarray_add(&sensu_attrs, &sensu_attrs_num, child->values[1].value.string);
+
+ DEBUG("write_sensu plugin: New attribute: %s => %s",
+ child->values[0].value.string,
+ child->values[1].value.string);
} else if (strcasecmp(child->key, "tag") == 0) {
char *tmp = NULL;
status = cf_util_get_string(child, &tmp);
}
}
if (sensu_tags_arr.nb_strs > 0) {
- free(sensu_tags);
+ sfree (sensu_tags);
sensu_tags = build_json_str_list("tags", &sensu_tags_arr);
free_str_list(&sensu_tags_arr);
if (sensu_tags == NULL) {