+env:
+ global:
+ # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
+ # via the "travis encrypt" command using the project repo's public key
+ - secure: "ZdWWp0XX3C4sLIp4lqeQTWC7vt+GsWjmyRiD17T9833NBAW4dddz310I6iyeXe6oX09ZFFiVIN4ogx9ANcNBx9jriGXI2/82nBhpxOJBebet8JCNS5VeTr4rDSfQOKP+Oc+ko5KbbghTuAtO2CFYiH3jZUcn4TdsYbVanf+TwUs="
+
sudo: required
dist: trusty
compiler:
- clang
language: c
before_install:
+ # When building the coverity_scan branch, allow only the first job to continue to avoid travis-ci/travis-ci#1975.
+ - if [[ "${TRAVIS_BRANCH}" == "coverity_scan" && ! "${TRAVIS_JOB_NUMBER}" =~ \.1$ ]]; then exit 0; fi
- sudo apt-get update -qq
- sudo apt-get install -qq --no-install-recommends
+ autotools-dev
iptables-dev
libatasmart-dev
libcap-dev
libi2c-dev
libldap2-dev
libltdl-dev
+ liblua50-dev
+ liblua5.1-0-dev
liblua5.2-dev
liblvm2-dev
libmemcached-dev
libprotobuf-c0-dev
librabbitmq-dev
librdkafka-dev
+ libriemann-client-dev
librrd-dev
libsensors4-dev
libsigrok-dev
libupsclient-dev
libvarnish-dev
libvirt-dev
+ libxen-dev
libxml2-dev
libyajl-dev
linux-libc-dev
perl
protobuf-c-compiler
+ python3-dev
python-dev
-script: sh build.sh && ./configure && make distcheck
+ xfslibs-dev
+before_script: autoreconf -fi
+script:
+ - if [[ "${TRAVIS_BRANCH}" == "coverity_scan" ]]; then exit 0; fi
+ - ./configure
+ - make -j 4
+ - make check
+
+addons:
+ coverity_scan:
+ project:
+ name: "collectd/collectd"
+ description: "Build submitted via Travis CI"
+ notification_email: collectd-changes@verplant.org
+ build_command_prepend: "./configure; make clean"
+ build_command: "make -j 4"
+ branch_pattern: coverity_scan
+2017-11-17, Version 5.8.0
+ * collectd: The core daemon is now completely licensed under the MIT
+ license.
+ * collectd: Added daemon option to avoid making BaseDir. Thanks to
+ Nathaniel Wesley Filardo and Florian Forster. #2422
+ * collectd: Global variables have been moved to their own module to make
+ porting collectd easier. Thanks to Sean Campbell. #2467
+ * collectd as well as Apache, memcached, OpenLDAP, Perl, RouterOS, SNMP,
+ Tail-CSV plugins: Free userdata for "plugin_register_complex_read()".
+ Thanks to Pavel Rochnyack. #2349
+ * Collectd client library: Added parsing and server code. Thanks to
+ Florian Forster. #2258
+ * Build system: Dependency on libltdl has been removed, support for
+ libtool 1 has been dropped. Thanks to Ruben Kerkhof. #1898
+ * Build system: The build system has been switched to non-recursive
+ make. Thanks to Ruben Kerkhof. #2085
+ * APC UPS plugin: The plugin's configuration is now optional. Without a
+ "<Plugin />" block reasonable defaults will be used. Thanks to Pavel
+ Rochnyack. #2351
+ * Chrony plugin: Several issues found when working with a stratum-1
+ server have been fixed. Thanks to Miroslav Lichvar. #2190
+ * Ceph plugin: Support for the Ceph version "Luminous" has been added.
+ Thanks to Aleksei Zakharov. #2464
+ * CPU plugin : Linux-specific "guest" states have been added. Thanks to
+ Xavier G. #2439
+ * cURL plugin, cURL-JSON, cURL-XML, DBI, FileCount, memcachec, Oracle,
+ PostgreSQL, Table, Tail, Tail CSV plugins: The ability to configure
+ the "plugin" field of generated metrics has been added. Thanks to
+ Pavel Rochnyack. #1944, #1681, #1558
+ * cURL-JSON plugin: Parsing of arrays has been fixed. Thanks to Florian
+ Forster. #2281
+ * DPDKEvents plugin: This new plugin reports link status and keep alive
+ events. Thanks to Maryam Tahhan, Harry van Haaren, Serhiy Pshyk,
+ Kim-Marie Jones, Krzysztof Matczak, Przemyslaw Szczerbik, Christian
+ Ehrhardt and Luca Boccassi. #2157, #2348, #2400, #2405, #2417
+ * DPDKStat plugin: The plugin has been refactored to make DPDK related
+ utility functions reusable. Thanks to Krzysztof Matczak, Przemyslaw
+ Szczerbik, Christian Ehrhardt and Luca Boccassi. #2130, #2348, #2400,
+ #2405, #2417
+ * DPDKStat plugin: The "LogLevel" and "RteDriverLibPath" config options
+ have been added. Thanks to Jiri Prokes. #2505
+ * Email plugin as well as Exec and Unixsock plugins: Use
+ "_SC_GETPW_R_SIZE_MAX". Thanks to Florian Forster. #2451
+ * FileCount plugin: Custom values for reported plugin, type and type
+ instance. Thanks to Pavel Rochnyack. #1979
+ * GenericJMX plugin: Support for "AtomicInteger" and "AtomicLong" has
+ been added. Thanks to Pierre Mauduit. #2158
+ * gRPC plugin: Support for meta data has been added. Thanks to Taylor
+ Cramer. #2378
+ * IPC plugin: Fixed failed compilation on AIX. Thanks to Pavel
+ Rochnyack. #2357
+ * Intel PMU plugin: This new plugin collects CPU performance metrics
+ using Intel's Performance Monitoring Unit (PMU). Scaling information
+ added to metadata. Thanks to Serhiy Pshyk and Roman Korynkevych.
+ #2276, #2398, #2374
+ * Intel RDT plugin: Support for collectd's logging infrastructure has
+ been added. PQoS monitoring groups are being reset on start-up to fix
+ potential previous unclean shutdowns. Thanks to Roman Korynkevych.
+ #2089.
+ * IPMI plugin: Support for System Event Log (SEL) has been added. Thanks
+ to Roman Korynkevych. #2091
+ * IPMI plugin: Support for remote IPMI controllers has been added.
+ Thanks to Pavel Rochnyack. #2024
+ * LVM plugin: A check for the "CAP_SYS_ADMIN" capability has been added.
+ This will give users an informative warning when the process is not
+ running with the required privileges for this plugin. Thanks to
+ Florian Forster. #2426, #2499
+ * mcelog plugin: This new plugin subscribes to Machine Check Exceptions
+ (MCE) and dispatches notifications. Metadata reset. Thanks to Maryam
+ Tahhan, Volodymyr Mytnyk, Taras Chornyi, Krzysztof Matczak and Roman
+ Korynkevych. #2003, #2246, #2380
+ * MQTT plugin: Add support for TLS in "Subscriber" blocks. Thanks to
+ Florian Forster. #2434
+ * memcached plugin: Persistent connections have been implemented. Fix
+ hit ratio reporting, add connections rate report. Thanks to Pavel
+ Rochnyack. #2388, #2385
+ * memcached plugin: The type of the "listen_disabled" metric has been
+ changed to "total_events". Thanks to Florian Forster. #2386, #2468
+ * Netlink plugin: The dropped packets metric has been added. Thanks to
+ Denys Fedoryshchenko. #2053
+ * NFS plugin: Support for NFS 4.2 metrics has been added. Thanks to
+ Marek Becka. #2369
+ * NFS plugin: Config options to ignore specified NFS versions have been
+ added. Thanks to Christian Bartolomäus. #2430
+ * NUT plugin: The "ConnectTimeout", "ForceSSL", "VerifyPeer" and
+ "CAPath" options have been added. Thanks to Pavel Rochnyack and Steven
+ Bell. #2145, #2354
+ * OpenLDAP plugin: A segfault after a connection failure has been fixed.
+ Thanks to Pavel Rochnyack. #2377
+ * Openvpn plugin: Added support for status files from latest OpenVPN-2.4
+ and possible from future versions. Thanks to Pavel Rochnyack. #2352
+ * OVS Events plugin: This new plugin reports link state changes from
+ Open vSwitch (OVS). Thanks to Volodymyr Mytnyk. #1971
+ * OVS Stats plugin: This new plugin reports bridge / interface
+ statistics from Open vSwitch (OVS). Thanks to Volodymyr Mytnyk and
+ Taras Chornyi. #2137
+ * Perl plugin: Bugfix, added check of proper interpreter initialization.
+ Thanks to Pavel Rochnyack. #2391
+ * PostgreSQL plugin: The plugin now sets the "application_name"
+ parameter when connecting to the database. Thanks to daniacs. #2497
+ * Processes plugin: The I/O operations reported for selected processes
+ has been fixed. The metric "ps_disk_octets" has been renamed to
+ "io_octets" because it actually contains the number of I/O operation
+ by the process, not just disk related I/O. Same for "io_ops"
+ (previously "ps_disk_ops"). The new metric "disk_octets" has been
+ added and is reporting disk I/O only. Add option to collect the count
+ of active memory maps for Linux processes. The "CollectFileDescriptor"
+ and "CollectContextSwitch" options have been added. Thanks to Pavel
+ Rochnyack and to Wilfried Goesgens. #2232, #2454, #1989
+ * Processes and TCPConns plugins: The OpenBSD implementation has been
+ changed to use "kvm_openfiles" with "KVM_NO_FILES". Thanks to Jeremie
+ Courreges-Anglas. #2061
+ * Python plugin: Extend Notification class to include metadata. Thanks
+ to Volodymyr Mytnyk. #2135
+ * Python plugin: The "CollectdException" class has been added. This
+ allows to throw an exception without a stack trace being logged.
+ Thanks to Sven Trenkel. #2330, #2346
+ * Sensors plugin: Support for (electrical) current has been added.
+ Thanks to Clemens Gruber. #2255
+ * SNMP plugin: Error handling has been improved: a potential double-free
+ is now avoided (potentially leaking memory) and handling of
+ non-failing subtrees has been fixed. Thanks to Pavel Rochnyack. #2449
+ * SNMP plugin: The "Timeout" and "Retries" config options have been
+ added. Thanks to Carlos Vicente. #1472, #2488
+ * SNMP Agent plugin: This new plugin implements an SNMP AgentX subagent
+ that receives and handles queries from SNMP master agent and returns
+ configured metrics. Thanks to Roman Korynkevych, Serhiy Pshyk and
+ Pavel Rochnyack. #2105, #2362
+ * Synproxy plugin: This new plugin provides statistics for Linux
+ SYNPROXY. Thanks to Marek Bečka. #2381
+ * Tail plugin: Allow the calculation of several distributions in one
+ "tail" instance through a "bucket" type. Thanks to Pavel Rochnyack.
+ #2442
+ * Turbostat plugin: Import "msr-index.h" header from Linux and better
+ support for mutliple packages. Thanks to Vincent Brillault. #2445,
+ #2446
+ * Uptime plugin: Changed implementation to read from "/proc/uptime"
+ instead of "/proc/stat". Update for Linux and AIX, uptime is read
+ directly using a system call. Update for BSD and Solaris, uptime is
+ calculated by subtracting boot time from current time. Thanks to Ivan
+ Kurnosov and Marcin Jurkowski. #2431, #2034
+ * UUID plugin: Support for libhal has been removed. Thanks to Ruben
+ Kerkhof. #2080
+ * Varnish plugin: Extended the varnish plugin with varnish-plus
+ counters. Fixed invalid data source type. Thanks to Denes Matetelki.
+ #2453, #2463
+ * virt plugin: The plugin has been updated to use
+ "virConnectListAllDomains()". Thanks to Denis Silakov. #2051
+ * virt plugin: Support for domain tags has been added. Thanks to
+ Francesco Romani. #2048
+ * virt plugin: Connection handling has been improved. Thanks to
+ Francesco Romani. #2100, #2101
+ * virt plugin: Many metrics have been added, including disk, hypervisor
+ CPU usage, performance monitoring events, domain state, CPU pinning
+ (affinity), file system, and job statistics. Thanks to Francesco
+ Romani and Przemyslaw Szczerbik. #2103, #2175, #2168
+ * Write Graphite plugin: Additional tests have been added. Thanks to
+ Florian Forster.
+ * Write HTTP plugin: The "Attribute" and "TTL" options for the KairosDB
+ format have been added. Implementation of "Prefix" option. Thanks to
+ jaroug, Denis Pompilio and Pavel Rochnyack. #2199, #2252, #2482
+ * Write MongoDB plugin: Memory leaks have been fixed. Thanks to
+ Saikrishna Arcot. #2307
+ * Write Prometheus plugin: Label values are now properly escaped. Thanks
+ to Florian Forster. #2035
+ * Write Redis plugin: Add "max_set_duration" to set duration for value.
+ Thanks to Tomofumi Hayashi. #2440
+ * Write Riemann plugin: Export times with microsecond resolution. Thanks
+ to mcorbin. #2315
+ * Write TSDB plugin: The options "ResolveInterval" and "ResolveJitter"
+ have been added to control DNS lookup behavior. This prevents DNS
+ flooding in case TSDB is not available. Thanks to Yves Mettier and
+ Florian Forster. #2059
+ * ZFS ARC plugin: Header lines are now ignored in the Linux
+ implementation. Thanks to YmrDtnJu. #2097
+
2017-06-06, Version 5.7.2
* Build system: The Notify Email plugin is no longer linked with
indirect dependencies. Thanks to Marc Fournier.
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $with_libvarnish_cflags"
- AC_CHECK_HEADERS([vapi/vsc.h],
- [AC_DEFINE([HAVE_VARNISH_V4], [1], [Varnish 4 API support])],
- [
- AC_CHECK_HEADERS([vsc.h],
- [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support]) ],
- [
- AC_CHECK_HEADERS([varnishapi.h],
- [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])],
- [with_libvarnish="no (found none of the varnish header files)"]
- )
- ]
- )
- ]
- )
+ $PKG_CONFIG --atleast-version=5.2 'varnishapi' 2>/dev/null
+ if test $? -eq 0; then
+ AC_DEFINE([HAVE_VARNISH_V5], [1], [Varnish 5 API support])
+ else
+ AC_CHECK_HEADERS([vapi/vsc.h],
+ [AC_DEFINE([HAVE_VARNISH_V4], [1], [Varnish 4 API support])],
+ [
+ AC_CHECK_HEADERS([vsc.h],
+ [AC_DEFINE([HAVE_VARNISH_V3], [1], [Varnish 3 API support]) ],
+ [
+ AC_CHECK_HEADERS([varnishapi.h],
+ [AC_DEFINE([HAVE_VARNISH_V2], [1], [Varnish 2 API support])],
+ [with_libvarnish="no (found none of the varnish header files)"]
+ )
+ ]
+ )
+ ]
+ )
+ fi
CPPFLAGS="$SAVE_CPPFLAGS"
fi
d="`dirname "${i}"`"
o="`TMPDIR="${d}" mktemp format.XXXXXX`"
- curl --silent --data-binary "@-" https://clang-format.appspot.com/ <"${i}" >"${o}"
+ curl --silent --data-binary "@-" https://format.collectd.org/ <"${i}" >"${o}"
if test $? -eq 0; then
cat "${o}" >"${i}"
fi
%define with_snmp_agent 0%{!?_without_snmp_agent:1}
%define with_statsd 0%{!?_without_statsd:1}
%define with_swap 0%{!?_without_swap:1}
+%define with_synproxy 0%{!?_without_synproxy:0}
%define with_syslog 0%{!?_without_syslog:1}
%define with_table 0%{!?_without_table:1}
%define with_tail 0%{!?_without_tail:1}
Summary: Statistics collection and monitoring daemon
Name: collectd
Version: 5.7.1
-Release: 7%{?dist}
+Release: 8%{?dist}
URL: https://collectd.org
Source: https://collectd.org/files/%{name}-%{version}.tar.bz2
License: GPLv2
%define _with_swap --disable-swap
%endif
+%if %{with_synproxy}
+%define _with_synproxy --enable-synproxy
+%else
+%define _with_synproxy --disable-synproxy
+%endif
+
%if %{with_syslog}
%define _with_syslog --enable-syslog
%else
%{?_with_snmp_agent} \
%{?_with_statsd} \
%{?_with_swap} \
+ %{?_with_synproxy} \
%{?_with_syslog} \
%{?_with_table} \
%{?_with_tail_csv} \
%if %{with_swap}
%{_libdir}/%{name}/swap.so
%endif
+%if %{with_synproxy}
+%{_libdir}/%{name}/synproxy.so
+%endif
%if %{with_syslog}
%{_libdir}/%{name}/syslog.so
%endif
%{_includedir}/collectd/network_buffer.h
%{_includedir}/collectd/lcc_features.h
%{_libdir}/pkgconfig/libcollectdclient.pc
+%{_includedir}/collectd/network_parse.h
+%{_includedir}/collectd/server.h
+%{_includedir}/collectd/types.h
%{_libdir}/libcollectdclient.so
%files -n libcollectdclient
%doc contrib/
%changelog
+* Thu Sep 28 2017 xakru <calvinxakru@gmail.com> - 5.7.1-8
+- Add new libcollectdclient/network_parse
+- Add new libcollectdclient/server
+- Add new libcollectdclient/types
+- Add new synproxy plugin
+
* Fri Aug 18 2017 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.7.1-7
- Add new intel_pmu plugin
READ_FUNC(average, (inst->sum / ((gauge_t)inst->num)));
READ_FUNC(min, inst->min);
READ_FUNC(max, inst->max);
- READ_FUNC(stddev, sqrt((((gauge_t)inst->num) * inst->squares_sum) -
- (inst->sum * inst->sum)) /
- ((gauge_t)inst->num));
+ READ_FUNC(stddev,
+ sqrt((((gauge_t)inst->num) * inst->squares_sum) -
+ (inst->sum * inst->sum)) /
+ ((gauge_t)inst->num));
}
/* Reset internal state. */
static int agg_config_aggregation(oconfig_item_t *ci) /* {{{ */
{
- aggregation_t *agg;
- _Bool is_valid;
- int status;
-
- agg = calloc(1, sizeof(*agg));
+ aggregation_t *agg = calloc(1, sizeof(*agg));
if (agg == NULL) {
ERROR("aggregation plugin: calloc failed.");
return -1;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
+ int status = 0;
if (strcasecmp("Host", child->key) == 0)
- cf_util_get_string_buffer(child, agg->ident.host,
- sizeof(agg->ident.host));
+ status = cf_util_get_string_buffer(child, agg->ident.host,
+ sizeof(agg->ident.host));
else if (strcasecmp("Plugin", child->key) == 0)
- cf_util_get_string_buffer(child, agg->ident.plugin,
- sizeof(agg->ident.plugin));
+ status = cf_util_get_string_buffer(child, agg->ident.plugin,
+ sizeof(agg->ident.plugin));
else if (strcasecmp("PluginInstance", child->key) == 0)
- cf_util_get_string_buffer(child, agg->ident.plugin_instance,
- sizeof(agg->ident.plugin_instance));
+ status = cf_util_get_string_buffer(child, agg->ident.plugin_instance,
+ sizeof(agg->ident.plugin_instance));
else if (strcasecmp("Type", child->key) == 0)
- cf_util_get_string_buffer(child, agg->ident.type,
- sizeof(agg->ident.type));
+ status = cf_util_get_string_buffer(child, agg->ident.type,
+ sizeof(agg->ident.type));
else if (strcasecmp("TypeInstance", child->key) == 0)
- cf_util_get_string_buffer(child, agg->ident.type_instance,
- sizeof(agg->ident.type_instance));
+ status = cf_util_get_string_buffer(child, agg->ident.type_instance,
+ sizeof(agg->ident.type_instance));
else if (strcasecmp("SetHost", child->key) == 0)
- cf_util_get_string(child, &agg->set_host);
+ status = cf_util_get_string(child, &agg->set_host);
else if (strcasecmp("SetPlugin", child->key) == 0)
- cf_util_get_string(child, &agg->set_plugin);
+ status = cf_util_get_string(child, &agg->set_plugin);
else if (strcasecmp("SetPluginInstance", child->key) == 0)
- cf_util_get_string(child, &agg->set_plugin_instance);
+ status = cf_util_get_string(child, &agg->set_plugin_instance);
else if (strcasecmp("SetTypeInstance", child->key) == 0)
- cf_util_get_string(child, &agg->set_type_instance);
+ status = cf_util_get_string(child, &agg->set_type_instance);
else if (strcasecmp("GroupBy", child->key) == 0)
- agg_config_handle_group_by(child, agg);
+ status = agg_config_handle_group_by(child, agg);
else if (strcasecmp("CalculateNum", child->key) == 0)
- cf_util_get_boolean(child, &agg->calc_num);
+ status = cf_util_get_boolean(child, &agg->calc_num);
else if (strcasecmp("CalculateSum", child->key) == 0)
- cf_util_get_boolean(child, &agg->calc_sum);
+ status = cf_util_get_boolean(child, &agg->calc_sum);
else if (strcasecmp("CalculateAverage", child->key) == 0)
- cf_util_get_boolean(child, &agg->calc_average);
+ status = cf_util_get_boolean(child, &agg->calc_average);
else if (strcasecmp("CalculateMinimum", child->key) == 0)
- cf_util_get_boolean(child, &agg->calc_min);
+ status = cf_util_get_boolean(child, &agg->calc_min);
else if (strcasecmp("CalculateMaximum", child->key) == 0)
- cf_util_get_boolean(child, &agg->calc_max);
+ status = cf_util_get_boolean(child, &agg->calc_max);
else if (strcasecmp("CalculateStddev", child->key) == 0)
- cf_util_get_boolean(child, &agg->calc_stddev);
+ status = cf_util_get_boolean(child, &agg->calc_stddev);
else
WARNING("aggregation plugin: The \"%s\" key is not allowed inside "
"<Aggregation /> blocks and will be ignored.",
child->key);
- }
+
+ if (status != 0) {
+ sfree(agg);
+ return status;
+ }
+ } /* for (int i = 0; i < ci->children_num; i++) */
if (agg_is_regex(agg->ident.host))
agg->regex_fields |= LU_GROUP_BY_HOST;
agg->regex_fields |= LU_GROUP_BY_TYPE_INSTANCE;
/* Sanity checking */
- is_valid = 1;
+ _Bool is_valid = 1;
if (strcmp("/.*/", agg->ident.type) == 0) /* {{{ */
{
ERROR("aggregation plugin: It appears you did not specify the required "
is_valid = 0;
} /* }}} */
- if (!is_valid) /* {{{ */
- {
+ if (!is_valid) { /* {{{ */
sfree(agg);
return -1;
} /* }}} */
- status = lookup_add(lookup, &agg->ident, agg->group_by, agg);
+ int status = lookup_add(lookup, &agg->ident, agg->group_by, agg);
if (status != 0) {
ERROR("aggregation plugin: lookup_add failed with status %i.", status);
sfree(agg);
status = amqp_socket_open(socket, CONF(conf, host), conf->port);
if (status < 0) {
- char errbuf[1024];
status *= -1;
- ERROR("amqp plugin: amqp_socket_open failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: amqp_socket_open failed: %s", STRERROR(status));
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
return status;
/* this interface is deprecated as of rabbitmq-c 0.4 */
sockfd = amqp_open_socket(CONF(conf, host), conf->port);
if (sockfd < 0) {
- char errbuf[1024];
status = (-1) * sockfd;
- ERROR("amqp plugin: amqp_open_socket failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: amqp_open_socket failed: %s", STRERROR(status));
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
return status;
while (received < body_size) {
status = amqp_simple_wait_frame(conf->connection, &frame);
if (status < 0) {
- char errbuf[1024];
status = (-1) * status;
- ERROR("amqp plugin: amqp_simple_wait_frame failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: amqp_simple_wait_frame failed: %s", STRERROR(status));
camqp_close_connection(conf);
return status;
}
status = amqp_simple_wait_frame(conf->connection, &frame);
if (status < 0) {
- char errbuf[1024];
status = (-1) * status;
- ERROR("amqp plugin: amqp_simple_wait_frame failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: amqp_simple_wait_frame failed: %s", STRERROR(status));
camqp_close_connection(conf);
return status;
}
status = plugin_thread_create(tmp, /* attr = */ NULL, camqp_subscribe_thread,
conf, "amqp subscribe");
if (status != 0) {
- char errbuf[1024];
- ERROR("amqp plugin: pthread_create failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("amqp plugin: pthread_create failed: %s", STRERROR(status));
return status;
}
status = getaddrinfo(node, service, &ai_hints, &ai_return);
if (status != 0) {
- char errbuf[1024];
INFO("apcups plugin: getaddrinfo failed: %s",
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return -1;
}
if (status != 0) /* `connect(2)' failed */
{
- char errbuf[1024];
- INFO("apcups plugin: connect failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ INFO("apcups plugin: connect failed: %s", STRERRNO);
close(sd);
return -1;
}
char recvline[1024];
char *tokptr;
char *toksaveptr;
- int try = 0;
+ int try
+ = 0;
int status;
#if APCMAIN
/* net_send closes the socket on error. */
assert(global_sockfd < 0);
if (try == 0) {
- try++;
+ try
+ ++;
count_retries++;
continue;
}
net_shutdown(&global_sockfd);
if (n < 0) {
- char errbuf[1024];
- ERROR("apcups plugin: Reading from socket failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("apcups plugin: Reading from socket failed: %s", STRERROR(status));
return -1;
}
int status = apc_query_server(conf_node, conf_service, &apcups_detail);
if (status != 0) {
- DEBUG("apcups plugin: apc_query_server (\"%s\", \"%s\") = %d",
- conf_node, conf_service, status);
+ DEBUG("apcups plugin: apc_query_server (\"%s\", \"%s\") = %d", conf_node,
+ conf_service, status);
return status;
}
char type_instance[DATA_MAX_NAME_LEN];
if (libaquaero5_poll(conf_device, &aq_data, &err_msg) < 0) {
- char errbuf[1024];
ERROR("aquaero plugin: Failed to poll device \"%s\": %s (%s)",
- conf_device ? conf_device : "default", err_msg,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ conf_device ? conf_device : "default", err_msg, STRERRNO);
return -1;
}
if (libaquaero5_getsettings(conf_device, &aq_sett, &err_msg) < 0) {
- char errbuf[1024];
ERROR("aquaero plugin: Failed to get settings "
"for device \"%s\": %s (%s)",
- conf_device ? conf_device : "default", err_msg,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ conf_device ? conf_device : "default", err_msg, STRERRNO);
return -1;
}
*/
static int MPL115_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL115_I2C_ADDRESS) < 0) {
ERROR("barometer: MPL115_detect problem setting i2c slave address to "
"0x%02X: %s",
- MPL115_I2C_ADDRESS, sstrerror(errno, errbuf, sizeof(errbuf)));
+ MPL115_I2C_ADDRESS, STRERRNO);
return 0;
}
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,
STATIC_ARRAY_SIZE(mpl115_coeffs),
mpl115_coeffs);
if (res < 0) {
- ERROR("barometer: MPL115_read_coeffs - problem reading data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL115_read_coeffs - problem reading data: %s", STRERRNO);
return -1;
}
int conv_temperature;
double adc_pressure;
double adc_temperature;
- char errbuf[1024];
*pressure = 0.0;
*temperature = 0.0;
if (retries > 0) {
ERROR("barometer: MPL115_read_averaged - requesting conversion: %s, "
"will retry at most %d more times",
- sstrerror(errno, errbuf, sizeof(errbuf)), retries);
+ STRERRNO, retries);
} else {
ERROR("barometer: MPL115_read_averaged - requesting conversion: %s, "
"too many failed retries",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
}
if (retries > 0) {
ERROR("barometer: MPL115_read_averaged - reading conversion: %s, "
"will retry at most %d more times",
- sstrerror(errno, errbuf, sizeof(errbuf)), retries);
+ STRERRNO, retries);
} else {
ERROR("barometer: MPL115_read_averaged - reading conversion: %s, "
"too many failed retries",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
}
*/
static int MPL3115_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, MPL3115_I2C_ADDRESS) < 0) {
ERROR("barometer: MPL3115_detect problem setting i2c slave address to "
"0x%02X: %s",
- MPL3115_I2C_ADDRESS, sstrerror(errno, errbuf, sizeof(errbuf)));
+ MPL3115_I2C_ADDRESS, STRERRNO);
return 0;
}
__s32 ctrl;
__u8 data[MPL3115_NUM_CONV_VALS];
long int tmp_value = 0;
- char errbuf[1024];
/* Set Active - activate the device from standby */
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1);
if (res < 0) {
- ERROR("barometer: MPL3115_read - cannot read CTRL_REG1: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - cannot read CTRL_REG1: %s", STRERRNO);
return 1;
}
ctrl = res;
res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_CTRL_REG1,
ctrl | MPL3115_CTRL_REG1_SBYB);
if (res < 0) {
- ERROR("barometer: MPL3115_read - problem activating: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - problem activating: %s", STRERRNO);
return 1;
}
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
if (res < 0) {
ERROR("barometer: MPL3115_read - cannot read status register: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
res = i2c_smbus_read_byte_data(i2c_bus_fd, MPL3115_REG_STATUS);
if (res < 0) {
ERROR("barometer: MPL3115_read - cannot read status register: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
}
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, MPL3115_REG_OUT_P_MSB,
MPL3115_NUM_CONV_VALS, data);
if (res < 0) {
- ERROR("barometer: MPL3115_read - cannot read data registers: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: MPL3115_read - cannot read data registers: %s", STRERRNO);
return 1;
}
static int MPL3115_init_sensor(void) {
__s32 res;
__s8 offset;
- char errbuf[1024];
/* Reset the sensor. It will reset immediately without ACKing */
/* the transaction, so no error handling here. */
res = i2c_smbus_write_byte_data(i2c_bus_fd, MPL3115_REG_OFF_T, offset);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem setting temp offset: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
if (res < 0) {
ERROR(
"barometer: MPL3115_init_sensor - problem setting pressure offset: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
MPL3115_PT_DATA_TDEF);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem setting PT_DATA_CFG: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
mpl3115_oversample);
if (res < 0) {
ERROR("barometer: MPL3115_init_sensor - problem configuring CTRL_REG1: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
*/
static int BMP085_detect(void) {
__s32 res;
- char errbuf[1024];
if (ioctl(i2c_bus_fd, I2C_SLAVE_FORCE, BMP085_I2C_ADDRESS) < 0) {
ERROR("barometer: BMP085_detect - problem setting i2c slave address to "
"0x%02X: %s",
- BMP085_I2C_ADDRESS, sstrerror(errno, errbuf, sizeof(errbuf)));
+ BMP085_I2C_ADDRESS, STRERRNO);
return 0;
}
res = i2c_smbus_read_byte_data(i2c_bus_fd, BMP085_ADDR_VERSION);
if (res < 0) {
ERROR("barometer: BMP085_detect - problem checking chip version: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 0;
}
DEBUG("barometer: BMP085_detect - chip version ML:0x%02X AL:0x%02X",
static int BMP085_read_coeffs(void) {
__s32 res;
__u8 coeffs[BMP085_NUM_COEFFS];
- char errbuf[1024];
res = i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_COEFFS,
BMP085_NUM_COEFFS, coeffs);
if (res < 0) {
- ERROR("barometer: BMP085_read_coeffs - problem reading data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("barometer: BMP085_read_coeffs - problem reading data: %s", STRERRNO);
return -1;
}
long adc_pressure;
long adc_temperature;
- char errbuf[1024];
-
/* start conversion of temperature */
res = i2c_smbus_write_byte_data(i2c_bus_fd, BMP085_ADDR_CTRL_REG,
BMP085_CMD_CONVERT_TEMP);
if (res < 0) {
ERROR("barometer: BMP085_read - problem requesting temperature conversion: "
"%s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_CONV, 2, measBuff);
if (res < 0) {
ERROR("barometer: BMP085_read - problem reading temperature data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
bmp085_cmdCnvPress);
if (res < 0) {
ERROR("barometer: BMP085_read - problem requesting pressure conversion: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
i2c_smbus_read_i2c_block_data(i2c_bus_fd, BMP085_ADDR_CONV, 3, measBuff);
if (res < 0) {
ERROR("barometer: BMP085_read - problem reading pressure data: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
* @return Zero when successful.
*/
static int collectd_barometer_init(void) {
- char errbuf[1024];
DEBUG("barometer: collectd_barometer_init");
if (i2c_bus_fd < 0) {
ERROR("barometer: collectd_barometer_init problem opening I2C bus device "
"\"%s\": %s (is loaded mod i2c-dev?)",
- config_device, sstrerror(errno, errbuf, sizeof(errbuf)));
+ config_device, STRERRNO);
return -1;
}
#if HAVE_TIMEGM
time_t t = timegm(&tm);
if (t == ((time_t)-1)) {
- char errbuf[1024];
- ERROR("bind plugin: timegm() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("bind plugin: timegm() failed: %s", STRERRNO);
return -1;
}
*ret_value = t;
#else
time_t t = mktime(&tm);
if (t == ((time_t)-1)) {
- char errbuf[1024];
- ERROR("bind plugin: mktime() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("bind plugin: mktime() failed: %s", STRERRNO);
return -1;
}
/* mktime assumes that tm is local time. Luckily, it also sets timezone to
* the same type of other "Bytes". Instead of keeping an "average" or
* "rate", use the "sum" in the pair and assign that to the derive
* value. */
- if (convert_special_metrics && (state->depth >= 2) &&
+ if (convert_special_metrics && (state->depth > 2) &&
(strcmp("filestore", state->stack[state->depth - 2]) == 0) &&
(strcmp("journal_wr_bytes", state->stack[state->depth - 1]) == 0) &&
(strcmp("avgcount", state->key) == 0)) {
cgroup_name);
fh = fopen(abs_path, "r");
if (fh == NULL) {
- char errbuf[1024];
- ERROR("cgroups plugin: fopen (\"%s\") failed: %s", abs_path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cgroups plugin: fopen (\"%s\") failed: %s", abs_path, STRERRNO);
return -1;
}
# <Database bar>
# Interval 60
# Service "service_name"
-# Query backend # predefined
+# Query backends # predefined
# Query rt36_tickets
# </Database>
# <Database qux>
<Database bar>
Interval 300
Service "service_name"
- Query backend # predefined
+ Query backends # predefined
Query rt36_tickets
</Database>
fh = fopen("/proc/stat", "r");
if (fh == NULL) {
- ERROR("contextswitch plugin: unable to open /proc/stat: %s",
- sstrerror(errno, buffer, sizeof(buffer)));
+ ERROR("contextswitch plugin: unable to open /proc/stat: %s", STRERRNO);
return -1;
}
status =
perfstat_cpu_total(NULL, &perfcputotal, sizeof(perfstat_cpu_total_t), 1);
if (status < 0) {
- char errbuf[1024];
- ERROR("contextswitch plugin: perfstat_cpu_total: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("contextswitch plugin: perfstat_cpu_total: %s", STRERRNO);
return -1;
}
#define COLLECTD_CPU_STATE_GUEST_NICE 9
#define COLLECTD_CPU_STATE_IDLE 10
#define COLLECTD_CPU_STATE_ACTIVE 11 /* sum of (!idle) */
-#define COLLECTD_CPU_STATE_MAX 12 /* #states */
+#define COLLECTD_CPU_STATE_MAX 12 /* #states */
#if HAVE_STATGRAB_H
#include <statgrab.h>
#error "No applicable input method."
#endif
-static const char *cpu_state_names[] = {"user", "system", "wait", "nice",
- "swap", "interrupt", "softirq", "steal",
- "guest", "guest_nice", "idle", "active"};
+static const char *cpu_state_names[] = {
+ "user", "system", "wait", "nice", "swap", "interrupt",
+ "softirq", "steal", "guest", "guest_nice", "idle", "active"};
#ifdef PROCESSOR_CPU_LOAD_INFO
static mach_port_t port_host;
static _Bool report_guest = 0;
static _Bool subtract_guest = 1;
-static const char *config_keys[] = {"ReportByCpu", "ReportByState",
- "ReportNumCpu", "ValuesPercentage",
+static const char *config_keys[] = {"ReportByCpu", "ReportByState",
+ "ReportNumCpu", "ValuesPercentage",
"ReportGuestState", "SubtractGuestState"};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
status = sysctl(mib, STATIC_ARRAY_SIZE(mib), &numcpu, &numcpu_size, NULL, 0);
if (status == -1) {
- char errbuf[1024];
- WARNING("cpu plugin: sysctl: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("cpu plugin: sysctl: %s", STRERRNO);
return -1;
}
/* #endif CAN_USE_SYSCTL */
numcpu_size = sizeof(numcpu);
if (sysctlbyname("hw.ncpu", &numcpu, &numcpu_size, NULL, 0) < 0) {
- char errbuf[1024];
- WARNING("cpu plugin: sysctlbyname(hw.ncpu): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("cpu plugin: sysctlbyname(hw.ncpu): %s", STRERRNO);
return -1;
}
numcpu_size = sizeof(maxcpu);
if (sysctlbyname("kern.smp.maxcpus", &maxcpu, &numcpu_size, NULL, 0) < 0) {
- char errbuf[1024];
- WARNING("cpu plugin: sysctlbyname(kern.smp.maxcpus): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("cpu plugin: sysctlbyname(kern.smp.maxcpus): %s", STRERRNO);
return -1;
}
#else
perfstat_cpu_total_t cputotal = {0};
if (!perfstat_cpu_total(NULL, &cputotal, sizeof(cputotal), 1)) {
- char errbuf[1024];
- WARNING("cpu plugin: perfstat_cpu_total: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("cpu plugin: perfstat_cpu_total: %s", STRERRNO);
return;
}
for (size_t cpu_num = 0; cpu_num < global_cpu_num; cpu_num++) {
cpu_state_t *this_cpu_states = get_cpu_state(cpu_num, 0);
- gauge_t local_rates[COLLECTD_CPU_STATE_MAX] = {NAN, NAN, NAN, NAN, NAN,
- NAN, NAN, NAN, NAN, NAN,
- NAN, NAN };
+ gauge_t local_rates[COLLECTD_CPU_STATE_MAX] = {
+ NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN};
for (size_t state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
if (this_cpu_states[state].has_value)
int numfields;
if ((fh = fopen("/proc/stat", "r")) == NULL) {
- char errbuf[1024];
- ERROR("cpu plugin: fopen (/proc/stat) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cpu plugin: fopen (/proc/stat) failed: %s", STRERRNO);
return -1;
}
cpu = atoi(fields[0] + 3);
- /* Do not stage User and Nice immediately: we may need to alter them later: */
+ /* Do not stage User and Nice immediately: we may need to alter them later:
+ */
long long user_value = atoll(fields[1]);
long long nice_value = atoll(fields[2]);
cpu_stage(cpu, COLLECTD_CPU_STATE_SYSTEM, (derive_t)atoll(fields[3]), now);
now);
cpu_stage(cpu, COLLECTD_CPU_STATE_SOFTIRQ, (derive_t)atoll(fields[7]),
now);
- }
+ }
if (numfields >= 9) { /* Steal (since Linux 2.6.11) */
cpu_stage(cpu, COLLECTD_CPU_STATE_STEAL, (derive_t)atoll(fields[8]), now);
/* Guest is included in User; optionally subtract Guest from User: */
if (subtract_guest) {
user_value -= value;
- if (user_value < 0) user_value = 0;
+ if (user_value < 0)
+ user_value = 0;
}
}
}
Nice: */
if (subtract_guest) {
nice_value -= value;
- if (nice_value < 0) nice_value = 0;
+ if (nice_value < 0)
+ nice_value = 0;
}
}
}
status = sysctl(mib, STATIC_ARRAY_SIZE(mib), cpuinfo[i], &cpuinfo_size,
NULL, 0);
if (status == -1) {
- char errbuf[1024];
- ERROR("cpu plugin: sysctl failed: %s.",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cpu plugin: sysctl failed: %s.", STRERRNO);
return -1;
}
}
status = sysctl(mib, STATIC_ARRAY_SIZE(mib), &cpuinfo_tmp, &cpuinfo_size,
NULL, 0);
if (status == -1) {
- char errbuf[1024];
- ERROR("cpu plugin: sysctl failed: %s.",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cpu plugin: sysctl failed: %s.", STRERRNO);
return -1;
}
cpuinfo_size = sizeof(cpuinfo);
if (sysctlbyname("kern.cp_times", &cpuinfo, &cpuinfo_size, NULL, 0) < 0) {
- char errbuf[1024];
- ERROR("cpu plugin: sysctlbyname failed: %s.",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cpu plugin: sysctlbyname failed: %s.", STRERRNO);
return -1;
}
cpuinfo_size = sizeof(cpuinfo);
if (sysctlbyname("kern.cp_time", &cpuinfo, &cpuinfo_size, NULL, 0) < 0) {
- char errbuf[1024];
- ERROR("cpu plugin: sysctlbyname failed: %s.",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cpu plugin: sysctlbyname failed: %s.", STRERRNO);
return -1;
}
numcpu = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0);
if (numcpu == -1) {
- char errbuf[1024];
- WARNING("cpu plugin: perfstat_cpu: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("cpu plugin: perfstat_cpu: %s", STRERRNO);
return -1;
}
id.name[0] = '\0';
if ((cpus = perfstat_cpu(&id, perfcpu, sizeof(perfstat_cpu_t), numcpu)) < 0) {
- char errbuf[1024];
- WARNING("cpu plugin: perfstat_cpu: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("cpu plugin: perfstat_cpu: %s", STRERRNO);
return -1;
}
csv = fopen(filename, "w");
if (csv == NULL) {
- char errbuf[1024];
- ERROR("csv plugin: fopen (%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("csv plugin: fopen (%s) failed: %s", filename, STRERRNO);
return -1;
}
if (csv_create_file(filename, ds))
return -1;
} else {
- char errbuf[1024];
- ERROR("stat(%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("stat(%s) failed: %s", filename, STRERRNO);
return -1;
}
} else if (!S_ISREG(statbuf.st_mode)) {
csv = fopen(filename, "a");
if (csv == NULL) {
- char errbuf[1024];
- ERROR("csv plugin: fopen (%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("csv plugin: fopen (%s) failed: %s", filename, STRERRNO);
return -1;
}
csv_fd = fileno(csv);
status = fcntl(csv_fd, F_SETLK, &fl);
if (status != 0) {
- char errbuf[1024];
- ERROR("csv plugin: flock (%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("csv plugin: flock (%s) failed: %s", filename, STRERRNO);
fclose(csv);
return -1;
}
static int cj_sock_perform(cj_t *db) /* {{{ */
{
- char errbuf[1024];
struct sockaddr_un sa_unix = {
.sun_family = AF_UNIX,
};
return -1;
if (connect(fd, (struct sockaddr *)&sa_unix, sizeof(sa_unix)) < 0) {
ERROR("curl_json plugin: connect(%s) failed: %s",
- (db->sock != NULL) ? db->sock : "<null>",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ (db->sock != NULL) ? db->sock : "<null>", STRERRNO);
close(fd);
return -1;
}
red = read(fd, buffer, sizeof(buffer));
if (red < 0) {
ERROR("curl_json plugin: read(%s) failed: %s",
- (db->sock != NULL) ? db->sock : "<null>",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ (db->sock != NULL) ? db->sock : "<null>", STRERRNO);
close(fd);
return -1;
}
dir = strdup(orig_dir);
if (dir == NULL) {
- char errbuf[1024];
- ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("strdup failed: %s", STRERRNO);
return -1;
}
free(dir);
return 0;
} else if (!create || (errno != ENOENT)) {
- char errbuf[1024];
- ERROR("change_basedir: chdir (%s): %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("change_basedir: chdir (%s): %s", dir, STRERRNO);
free(dir);
return -1;
}
status = mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
if (status != 0) {
- char errbuf[1024];
- ERROR("change_basedir: mkdir (%s): %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("change_basedir: mkdir (%s): %s", dir, STRERRNO);
free(dir);
return -1;
}
status = chdir(dir);
if (status != 0) {
- char errbuf[1024];
- ERROR("change_basedir: chdir (%s): %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("change_basedir: chdir (%s): %s", dir, STRERRNO);
free(dir);
return -1;
}
while ((loop == 0) && (nanosleep(&ts_wait, &ts_wait) != 0)) {
if (errno != EINTR) {
- char errbuf[1024];
- ERROR("nanosleep failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("nanosleep failed: %s", STRERRNO);
return -1;
}
}
const char *file = global_option_get("PIDFile");
if ((fh = fopen(file, "w")) == NULL) {
- char errbuf[1024];
- ERROR("fopen (%s): %s", file, sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("fopen (%s): %s", file, STRERRNO);
return 1;
}
fd = socket(AF_UNIX, SOCK_DGRAM, /* protocol = */ 0);
#endif
if (fd < 0) {
- char errbuf[1024];
- ERROR("creating UNIX socket failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("creating UNIX socket failed: %s", STRERRNO);
return 0;
}
if (sendto(fd, buffer, strlen(buffer), MSG_NOSIGNAL, (void *)&su,
(socklen_t)su_size) < 0) {
- char errbuf[1024];
- ERROR("sendto(\"%s\") failed: %s", notifysocket,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("sendto(\"%s\") failed: %s", notifysocket, STRERRNO);
close(fd);
return 0;
}
if ((pid = fork()) == -1) {
/* error */
- char errbuf[1024];
- fprintf(stderr, "fork: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ fprintf(stderr, "fork: %s", STRERRNO);
return 1;
} else if (pid != 0) {
/* parent */
struct sigaction sig_int_action = {.sa_handler = sig_int_handler};
if (0 != sigaction(SIGINT, &sig_int_action, NULL)) {
- char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal INT: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
struct sigaction sig_term_action = {.sa_handler = sig_term_handler};
if (0 != sigaction(SIGTERM, &sig_term_action, NULL)) {
- char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal TERM: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
struct sigaction sig_usr1_action = {.sa_handler = sig_usr1_handler};
if (0 != sigaction(SIGUSR1, &sig_usr1_action, NULL)) {
- char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal USR1: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return 1;
}
if (EEXIST == errno)
continue;
- char errbuf[1024];
- ERROR("check_create_dir: mkdir (%s): %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("check_create_dir: mkdir (%s): %s", dir, STRERRNO);
return -1;
} else {
- char errbuf[1024];
- ERROR("check_create_dir: stat (%s): %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("check_create_dir: stat (%s): %s", dir, STRERRNO);
return -1;
}
} else if (!S_ISDIR(statbuf.st_mode)) {
failure = 0;
if ((dh = opendir(dir)) == NULL) {
- char errbuf[1024];
- ERROR("walk_directory: Cannot open '%s': %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("walk_directory: Cannot open '%s': %s", dir, STRERRNO);
return -1;
}
void *smalloc(size_t size);
char *sstrerror(int errnum, char *buf, size_t buflen);
+#ifndef ERRBUF_SIZE
+#define ERRBUF_SIZE 256
+#endif
+
+#define STRERROR(e) sstrerror((e), (char[ERRBUF_SIZE]){0}, ERRBUF_SIZE)
+#define STRERRNO STRERROR(errno)
+
/*
* NAME
* sread
dh = opendir(dir);
if (dh == NULL) {
- char errbuf[1024];
- ERROR("configfile: opendir failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("configfile: opendir failed: %s", STRERRNO);
return NULL;
}
status = stat(path_ptr, &statbuf);
if (status != 0) {
- char errbuf[1024];
- WARNING("configfile: stat (%s) failed: %s", path_ptr,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("configfile: stat (%s) failed: %s", path_ptr, STRERRNO);
continue;
}
status = stat(path, &statbuf);
if (status != 0) {
- char errbuf[1024];
- ERROR("configfile: stat (%s) failed: %s", path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("configfile: stat (%s) failed: %s", path, STRERRNO);
return NULL;
}
temp = md_strdup(actual);
if (temp == NULL) {
- pthread_mutex_unlock(&md->lock);
ERROR("meta_data_as_string: md_strdup failed for key `%s'.", key);
return -ENOMEM;
}
return 0;
} /* }}} int plugin_unregister */
-/*
- * (Try to) load the shared object `file'. Won't complain if it isn't a shared
- * object, but it will bitch about a shared object not having a
- * ``module_register'' symbol..
- */
-static int plugin_load_file(const char *file, _Bool global) {
- void (*reg_handle)(void);
-
+/* plugin_load_file loads the shared object "file" and calls its
+ * "module_register" function. Returns zero on success, non-zero otherwise. */
+static int plugin_load_file(char const *file, _Bool global) {
int flags = RTLD_NOW;
if (global)
flags |= RTLD_GLOBAL;
void *dlh = dlopen(file, flags);
-
if (dlh == NULL) {
char errbuf[1024] = "";
snprintf(errbuf, sizeof(errbuf),
- "dlopen (\"%s\") failed: %s. "
- "The most common cause for this problem is "
- "missing dependencies. Use ldd(1) to check "
- "the dependencies of the plugin "
- "/ shared object.",
+ "dlopen(\"%s\") failed: %s. "
+ "The most common cause for this problem is missing dependencies. "
+ "Use ldd(1) to check the dependencies of the plugin / shared "
+ "object.",
file, dlerror());
- ERROR("%s", errbuf);
- /* Make sure this is printed to STDERR in any case, but also
- * make sure it's printed only once. */
- if (list_log != NULL)
- fprintf(stderr, "ERROR: %s\n", errbuf);
+ /* This error is printed to STDERR unconditionally. If list_log is NULL,
+ * plugin_log() will also print to STDERR. We avoid duplicate output by
+ * checking that the list of log handlers, list_log, is not NULL. */
+ fprintf(stderr, "ERROR: %s\n", errbuf);
+ if (list_log != NULL) {
+ ERROR("%s", errbuf);
+ }
- return 1;
+ return ENOENT;
}
- reg_handle = (void (*)(void))dlsym(dlh, "module_register");
+ void (*reg_handle)(void) = dlsym(dlh, "module_register");
if (reg_handle == NULL) {
- WARNING("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file,
- dlerror());
+ ERROR("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file,
+ dlerror());
dlclose(dlh);
- return -1;
+ return ENOENT;
}
(*reg_handle)();
-
return 0;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
int status = pthread_setname_np(tid, n);
if (status != 0) {
- char errbuf[1024];
- ERROR("set_thread_name(\"%s\"): %s", n,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("set_thread_name(\"%s\"): %s", n, STRERROR(status));
}
#else /* if defined(HAVE_PTHREAD_SET_NAME_NP) */
pthread_set_name_np(tid, n);
/* attr = */ NULL, plugin_read_thread,
/* arg = */ NULL);
if (status != 0) {
- char errbuf[1024];
- ERROR("plugin: start_read_threads: pthread_create failed "
- "with status %i (%s).",
- status, sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("plugin: start_read_threads: pthread_create failed with status %i "
+ "(%s).",
+ status, STRERROR(status));
return;
}
/* attr = */ NULL, plugin_write_thread,
/* arg = */ NULL);
if (status != 0) {
- char errbuf[1024];
- ERROR("plugin: start_write_threads: pthread_create failed "
- "with status %i (%s).",
- status, sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("plugin: start_write_threads: pthread_create failed with status %i "
+ "(%s).",
+ status, STRERROR(status));
return;
}
}
if ((dh = opendir(dir)) == NULL) {
- char errbuf[1024];
- ERROR("plugin_load: opendir (%s) failed: %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("plugin_load: opendir (%s) failed: %s", dir, STRERRNO);
return -1;
}
}
if (lstat(filename, &statbuf) == -1) {
- char errbuf[1024];
- WARNING("plugin_load: stat (\"%s\") failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("plugin_load: stat (\"%s\") failed: %s", filename, STRERRNO);
continue;
} else if (!S_ISREG(statbuf.st_mode)) {
/* don't follow symlinks */
status = plugin_write_enqueue(vl);
if (status != 0) {
- char errbuf[1024];
- ERROR("plugin_dispatch_values: plugin_write_enqueue failed "
- "with status %i (%s).",
- status, sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("plugin_dispatch_values: plugin_write_enqueue failed with status %i "
+ "(%s).",
+ status, STRERROR(status));
return status;
}
ctx = malloc(sizeof(*ctx));
if (ctx == NULL) {
- char errbuf[1024];
- ERROR("Failed to allocate plugin context: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("Failed to allocate plugin context: %s", STRERRNO);
return NULL;
}
fh = fopen(file, "r");
if (fh == NULL) {
- char errbuf[1024];
fprintf(stderr, "Failed to open types database `%s': %s.\n", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
- ERROR("Failed to open types database `%s': %s", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
+ ERROR("Failed to open types database `%s': %s", file, STRERRNO);
return -1;
}
status = clock_gettime(CLOCK_REALTIME, &ts);
if (status != 0) {
- char errbuf[1024];
- ERROR("cdtime: clock_gettime failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cdtime: clock_gettime failed: %s", STRERRNO);
return 0;
}
status = gettimeofday(&tv, /* struct timezone = */ NULL);
if (status != 0) {
- char errbuf[1024];
- ERROR("cdtime: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cdtime: gettimeofday failed: %s", STRERRNO);
return 0;
}
NORMALIZE_TIMESPEC(t_spec);
if (gmtime_r(&t_spec.tv_sec, t_tm) == NULL) {
- char errbuf[1024];
int status = errno;
- ERROR("get_utc_time: gmtime_r failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("get_utc_time: gmtime_r failed: %s", STRERRNO);
return status;
}
NORMALIZE_TIMESPEC(t_spec);
if (localtime_r(&t_spec.tv_sec, t_tm) == NULL) {
- char errbuf[1024];
int status = errno;
- ERROR("get_local_time: localtime_r failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("get_local_time: localtime_r failed: %s", STRERRNO);
return status;
}
continue;
if (STATANYFS(mnt_ptr->dir, &statbuf) < 0) {
- char errbuf[1024];
- ERROR(STATANYFS_STR "(%s) failed: %s", mnt_ptr->dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR(STATANYFS_STR "(%s) failed: %s", mnt_ptr->dir, STRERRNO);
continue;
}
int rnumdisk;
if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0) {
- char errbuf[1024];
- WARNING("disk plugin: perfstat_disk: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("disk plugin: perfstat_disk: %s", STRERRNO);
return -1;
}
firstpath.name[0] = '\0';
if ((rnumdisk = perfstat_disk(&firstpath, stat_disk, sizeof(perfstat_disk_t),
numdisk)) < 0) {
- char errbuf[1024];
- WARNING("disk plugin: perfstat_disk : %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("disk plugin: perfstat_disk : %s", STRERRNO);
return -1;
}
#include "common.h"
#include "plugin.h"
-#include <poll.h>
#include "utils_dns.h"
+#include <poll.h>
#include <pcap.h>
status = plugin_thread_create(&listen_thread, NULL, dns_child_loop, (void *)0,
"dns listen");
if (status != 0) {
- char errbuf[1024];
- ERROR("dns plugin: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("dns plugin: pthread_create failed: %s", STRERRNO);
return -1;
}
shm_name);
}
- char errbuf[ERR_BUF_SIZE];
int fd = shm_open(shm_name, O_RDONLY, 0);
if (fd < 0) {
ERROR(DPDK_EVENTS_PLUGIN ": Failed to open %s as SHM:%s. Is DPDK KA "
"primary application running?",
- shm_name, sstrerror(errno, errbuf, sizeof(errbuf)));
+ shm_name, STRERRNO);
return errno;
}
ec->config.keep_alive.shm = (dpdk_keepalive_shm_t *)mmap(
0, sizeof(*(ec->config.keep_alive.shm)), PROT_READ, MAP_SHARED, fd, 0);
if (ec->config.keep_alive.shm == MAP_FAILED) {
- ERROR(DPDK_EVENTS_PLUGIN ": Failed to mmap KA SHM:%s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR(DPDK_EVENTS_PLUGIN ": Failed to mmap KA SHM:%s", STRERRNO);
close(fd);
return errno;
}
int ret = dpdk_helper_init(g_shm_name, sizeof(dpdk_stats_ctx_t), &g_hc);
if (ret != 0) {
- char errbuf[ERR_BUF_SIZE];
ERROR("%s: failed to initialize %s helper(error: %s)", DPDK_STATS_PLUGIN,
- g_shm_name, sstrerror(errno, errbuf, sizeof(errbuf)));
+ g_shm_name, STRERRNO);
return ret;
}
int ret;
ret = dpdk_helper_init(g_shm_name, data_size, &g_hc);
if (ret != 0) {
- char errbuf[ERR_BUF_SIZE];
ERROR("%s: failed to initialize %s helper(error: %s)", DPDK_STATS_PLUGIN,
- g_shm_name, sstrerror(errno, errbuf, sizeof(errbuf)));
+ g_shm_name, STRERRNO);
return ret;
}
errno = 0;
if (fgets(line, sizeof(line), this->socket) == NULL) {
if (errno != 0) {
- char errbuf[1024];
log_err("collect: reading from socket (fd #%i) "
"failed: %s",
- fileno(this->socket),
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ fileno(this->socket), STRERRNO);
}
break;
}
/* create UNIX socket */
errno = 0;
if ((connector_socket = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
- char errbuf[1024];
disabled = 1;
- log_err("socket() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("socket() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
if (bind(connector_socket, (struct sockaddr *)&addr,
offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) ==
-1) {
- char errbuf[1024];
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("bind() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("bind() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
errno = 0;
if (listen(connector_socket, 5) == -1) {
- char errbuf[1024];
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("listen() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("listen() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
grp = NULL;
status = getgrnam_r(group, &sg, grbuf, sizeof(grbuf), &grp);
if (status != 0) {
- char errbuf[1024];
- log_warn("getgrnam_r (%s) failed: %s", group,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ log_warn("getgrnam_r (%s) failed: %s", group, STRERROR(status));
} else if (grp == NULL) {
log_warn("No such group: `%s'", group);
} else {
status = chown(path, (uid_t)-1, grp->gr_gid);
if (status != 0) {
- char errbuf[1024];
log_warn("chown (%s, -1, %i) failed: %s", path, (int)grp->gr_gid,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
}
}
}
errno = 0;
if (chmod(path, sock_perms) != 0) {
- char errbuf[1024];
- log_warn("chmod() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_warn("chmod() failed: %s", STRERRNO);
}
{ /* initialize collector threads */
if (plugin_thread_create(&collectors[i]->thread, &ptattr, collect,
collectors[i], "email collector") != 0) {
- char errbuf[1024];
- log_err("plugin_thread_create() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("plugin_thread_create() failed: %s", STRERRNO);
collectors[i]->thread = (pthread_t)0;
}
}
remote = accept(connector_socket, NULL, NULL);
if (remote == -1) {
- char errbuf[1024];
-
if (errno == EINTR)
continue;
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("accept() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("accept() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
static int email_init(void) {
if (plugin_thread_create(&connector, NULL, open_connection, NULL,
"email listener") != 0) {
- char errbuf[1024];
disabled = 1;
- log_err("plugin_thread_create() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("plugin_thread_create() failed: %s", STRERRNO);
return -1;
}
fd = socket(AF_INET, SOCK_DGRAM, /* protocol = */ 0);
if (fd < 0) {
- char errbuf[1024];
- ERROR("ethstat plugin: Failed to open control socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ethstat plugin: Failed to open control socket: %s", STRERRNO);
return 1;
}
status = ioctl(fd, SIOCETHTOOL, &req);
if (status < 0) {
- char errbuf[1024];
close(fd);
ERROR("ethstat plugin: Failed to get driver information "
"from %s: %s",
- device, sstrerror(errno, errbuf, sizeof(errbuf)));
+ device, STRERRNO);
return -1;
}
req.ifr_data = (void *)strings;
status = ioctl(fd, SIOCETHTOOL, &req);
if (status < 0) {
- char errbuf[1024];
close(fd);
free(strings);
free(stats);
- ERROR("ethstat plugin: Cannot get strings from %s: %s", device,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ethstat plugin: Cannot get strings from %s: %s", device, STRERRNO);
return -1;
}
req.ifr_data = (void *)stats;
status = ioctl(fd, SIOCETHTOOL, &req);
if (status < 0) {
- char errbuf[1024];
close(fd);
free(strings);
free(stats);
ERROR("ethstat plugin: Reading statistics from %s failed: %s", device,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
int gid, int egid) /* {{{ */
{
int status;
- char errbuf[1024];
#if HAVE_SETGROUPS
if (getuid() == 0) {
status = setgid(gid);
if (status != 0) {
- ERROR("exec plugin: setgid (%i) failed: %s", gid,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("exec plugin: setgid (%i) failed: %s", gid, STRERRNO);
exit(-1);
}
if (egid != -1) {
status = setegid(egid);
if (status != 0) {
- ERROR("exec plugin: setegid (%i) failed: %s", egid,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("exec plugin: setegid (%i) failed: %s", egid, STRERRNO);
exit(-1);
}
}
status = setuid(uid);
if (status != 0) {
- ERROR("exec plugin: setuid (%i) failed: %s", uid,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("exec plugin: setuid (%i) failed: %s", uid, STRERRNO);
exit(-1);
}
execvp(pl->exec, pl->argv);
- ERROR("exec plugin: Failed to execute ``%s'': %s", pl->exec,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("exec plugin: Failed to execute ``%s'': %s", pl->exec, STRERRNO);
exit(-1);
} /* void exec_child }}} */
static int create_pipe(int fd_pipe[2]) /* {{{ */
{
- char errbuf[1024];
int status;
status = pipe(fd_pipe);
if (status != 0) {
- ERROR("exec plugin: pipe failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("exec plugin: pipe failed: %s", STRERRNO);
return -1;
}
int fd_pipe_in[2] = {-1, -1};
int fd_pipe_out[2] = {-1, -1};
int fd_pipe_err[2] = {-1, -1};
- char errbuf[1024];
int status;
int pid;
status = getpwnam_r(pl->user, &sp, nambuf, sizeof(nambuf), &sp_ptr);
if (status != 0) {
ERROR("exec plugin: Failed to get user information for user ``%s'': %s",
- pl->user, sstrerror(status, errbuf, sizeof(errbuf)));
+ pl->user, STRERROR(status));
goto failed;
}
if (status != 0) {
ERROR("exec plugin: Failed to get group information "
"for group ``%s'': %s",
- pl->group, sstrerror(status, errbuf, sizeof(errbuf)));
+ pl->group, STRERROR(status));
goto failed;
}
if (gr_ptr == NULL) {
pid = fork();
if (pid < 0) {
- ERROR("exec plugin: fork failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("exec plugin: fork failed: %s", STRERRNO);
goto failed;
} else if (pid == 0) {
int fd_num;
fh = fdopen(fd, "w");
if (fh == NULL) {
- char errbuf[1024];
- ERROR("exec plugin: fdopen (%i) failed: %s", fd,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("exec plugin: fdopen (%i) failed: %s", fd, STRERRNO);
kill(pid, SIGTERM);
close(fd);
sfree(arg);
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- plugin_thread_create(&t, &attr, exec_read_one, (void *)pl, "exec read");
+ int status =
+ plugin_thread_create(&t, &attr, exec_read_one, (void *)pl, "exec read");
+ if (status != 0) {
+ ERROR("exec plugin: plugin_thread_create failed.");
+ }
pthread_attr_destroy(&attr);
} /* for (pl) */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- plugin_thread_create(&t, &attr, exec_notification_one, (void *)pln,
- "exec notify");
+ int status = plugin_thread_create(&t, &attr, exec_notification_one,
+ (void *)pln, "exec notify");
+ if (status != 0) {
+ ERROR("exec plugin: plugin_thread_create failed.");
+ }
pthread_attr_destroy(&attr);
} /* for (pl) */
int prc_used, prc_unused;
char *fields[3];
char buffer[buffer_len];
- char errbuf[1024];
FILE *fp;
// Open file
fp = fopen("/proc/sys/fs/file-nr", "r");
if (fp == NULL) {
- ERROR("fhcount: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("fhcount: fopen: %s", STRERRNO);
return EXIT_FAILURE;
}
if (fgets(buffer, buffer_len, fp) == NULL) {
- ERROR("fhcount: fgets: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("fhcount: fgets: %s", STRERRNO);
fclose(fp);
return EXIT_FAILURE;
}
ai_return = getaddrinfo(node, service, &ai_hints, &ai_list);
if (ai_return != 0) {
- char errbuf[1024];
ERROR("gmond plugin: getaddrinfo (%s, %s) failed: %s",
(node == NULL) ? "(null)" : node,
(service == NULL) ? "(null)" : service,
- (ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(ai_return));
+ (ai_return == EAI_SYSTEM) ? STRERRNO : gai_strerror(ai_return));
return -1;
}
sockets[sockets_num].fd =
socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (sockets[sockets_num].fd < 0) {
- char errbuf[1024];
- ERROR("gmond plugin: socket failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: socket failed: %s", STRERRNO);
continue;
}
status = setsockopt(sockets[sockets_num].fd, SOL_SOCKET, SO_REUSEADDR,
(void *)&yes, sizeof(yes));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
}
status = bind(sockets[sockets_num].fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- ERROR("gmond plugin: bind failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: bind failed: %s", STRERRNO);
close(sockets[sockets_num].fd);
continue;
}
status = setsockopt(sockets[sockets_num].fd, IPPROTO_IP,
IP_MULTICAST_LOOP, (void *)&loop, sizeof(loop));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
struct ip_mreq mreq = {.imr_multiaddr.s_addr = addr->sin_addr.s_addr,
status = setsockopt(sockets[sockets_num].fd, IPPROTO_IP,
IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
} /* if (ai_ptr->ai_family == AF_INET) */
else if (ai_ptr->ai_family == AF_INET6) {
status = setsockopt(sockets[sockets_num].fd, IPPROTO_IPV6,
IPV6_MULTICAST_LOOP, (void *)&loop, sizeof(loop));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
struct ipv6_mreq mreq = {
status = setsockopt(sockets[sockets_num].fd, IPPROTO_IPV6,
IPV6_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq));
if (status != 0) {
- char errbuf[1024];
- WARNING("gmond plugin: setsockopt(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("gmond plugin: setsockopt(2) failed: %s", STRERRNO);
}
} /* if (ai_ptr->ai_family == AF_INET6) */
/* flags = */ 0, (struct sockaddr *)&mc_send_sockets[i].addr,
mc_send_sockets[i].addrlen);
if (status == -1) {
- char errbuf[1024];
- ERROR("gmond plugin: sendto(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: sendto(2) failed: %s", STRERRNO);
continue;
}
}
buffer_size = recv(p->fd, buffer, sizeof(buffer), /* flags = */ 0);
if (buffer_size <= 0) {
- char errbuf[1024];
- ERROR("gmond plugin: recv failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: recv failed: %s", STRERRNO);
p->revents = 0;
return -1;
}
while (mc_receive_thread_loop != 0) {
status = poll(mc_receive_sockets, mc_receive_sockets_num, -1);
if (status <= 0) {
- char errbuf[1024];
if (errno == EINTR)
continue;
- ERROR("gmond plugin: poll failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("gmond plugin: poll failed: %s", STRERRNO);
break;
}
* Marc Fournier <marc.fournier at camptocamp.com>
**/
+#include "collectd.h"
#include "common.h"
#include "plugin.h"
#include "utils_time.h"
-#include "collectd.h"
#define CGPS_TRUE 1
#define CGPS_FALSE 0
int ret = !cgps_thread_shutdown;
- pthread_mutex_lock(&cgps_thread_lock);
+ pthread_mutex_unlock(&cgps_thread_lock);
return ret;
}
free(res);
// Clean mutex:
- pthread_mutex_unlock(&cgps_thread_lock);
pthread_mutex_destroy(&cgps_thread_lock);
pthread_mutex_unlock(&cgps_data_lock);
pthread_mutex_destroy(&cgps_data_lock);
.ai_socktype = SOCK_STREAM};
if ((ai_return = getaddrinfo(host, port, &ai_hints, &ai_list)) != 0) {
- char errbuf[1024];
ERROR("hddtemp plugin: getaddrinfo (%s, %s): %s", host, port,
- (ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(ai_return));
+ (ai_return == EAI_SYSTEM) ? STRERRNO : gai_strerror(ai_return));
return NULL;
}
/* create our socket descriptor */
fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0) {
- char errbuf[1024];
- ERROR("hddtemp plugin: socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("hddtemp plugin: socket: %s", STRERRNO);
continue;
}
/* connect to the hddtemp daemon */
if (connect(fd, (struct sockaddr *)ai_ptr->ai_addr, ai_ptr->ai_addrlen)) {
- char errbuf[1024];
- INFO("hddtemp plugin: connect (%s, %s) failed: %s", host, port,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ INFO("hddtemp plugin: connect (%s, %s) failed: %s", host, port, STRERRNO);
close(fd);
fd = -1;
continue;
if (status == 0) {
break;
} else if (status == -1) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EINTR))
continue;
- ERROR("hddtemp plugin: Error reading from socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("hddtemp plugin: Error reading from socket: %s", STRERRNO);
close(fd);
free(buffer);
return NULL;
long page_size = strtol(result->d_name + strlen(hugepages_dir),
/* endptr = */ NULL, /* base = */ 10);
if (errno != 0) {
- char errbuf[1024];
ERROR("%s: failed to determine page size from directory name \"%s\": %s",
- g_plugin_name, result->d_name,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ g_plugin_name, result->d_name, STRERRNO);
continue;
}
int numfields;
if ((fh = fopen("/proc/net/dev", "r")) == NULL) {
- char errbuf[1024];
- WARNING("interface plugin: fopen: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("interface plugin: fopen: %s", STRERRNO);
return -1;
}
if ((nif = perfstat_netinterface(NULL, NULL, sizeof(perfstat_netinterface_t),
0)) < 0) {
- char errbuf[1024];
- WARNING("interface plugin: perfstat_netinterface: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("interface plugin: perfstat_netinterface: %s", STRERRNO);
return -1;
}
id.name[0] = '\0';
if ((ifs = perfstat_netinterface(&id, ifstat, sizeof(perfstat_netinterface_t),
nif)) < 0) {
- char errbuf[1024];
WARNING("interface plugin: perfstat_netinterface (interfaces=%d): %s", nif,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
status = semctl(/* id = */ 0, /* num = */ 0, SEM_INFO, arg);
if (status == -1) {
- char errbuf[1024];
ERROR("ipc plugin: semctl(2) failed: %s. "
"Maybe the kernel is not configured for semaphores?",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
status = shmctl(/* id = */ 0, SHM_INFO, (void *)&shm_info);
if (status == -1) {
- char errbuf[1024];
ERROR("ipc plugin: shmctl(2) failed: %s. "
"Maybe the kernel is not configured for shared memory?",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
if (get_ipc_info(cid, cmd, version, buff, &size) < 0) {
if (errno != ENOSPC) {
- char errbuf[1024];
- WARNING("ipc plugin: get_ipc_info: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("ipc plugin: get_ipc_info: %s", STRERRNO);
return NULL;
}
}
}
if (get_ipc_info(cid, cmd, version, buff, &size) < 0) {
- char errbuf[1024];
- WARNING("ipc plugin: get_ipc_info: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("ipc plugin: get_ipc_info: %s", STRERRNO);
free(buff);
return NULL;
}
value_copy = strdup(value);
if (value_copy == NULL) {
- char errbuf[1024];
- ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("strdup failed: %s", STRERRNO);
return 1;
}
list = realloc(chain_list, (chain_num + 1) * sizeof(ip_chain_t *));
if (list == NULL) {
- char errbuf[1024];
- ERROR("realloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("realloc failed: %s", STRERRNO);
sfree(temp.rule.comment);
return 1;
}
chain_list = list;
final = malloc(sizeof(*final));
if (final == NULL) {
- char errbuf[1024];
- ERROR("malloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("malloc failed: %s", STRERRNO);
sfree(temp.rule.comment);
return 1;
}
if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO, &ipvs_info, &len) ==
-1) {
- char errbuf[1024];
- log_err("ip_vs_get_services: getsockopt() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("ip_vs_get_services: getsockopt() failed: %s", STRERRNO);
return NULL;
}
if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_SERVICES, services, &len) ==
-1) {
- char errbuf[1024];
- log_err("ipvs_get_services: getsockopt failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("ipvs_get_services: getsockopt failed: %s", STRERRNO);
free(services);
return NULL;
dests->num_dests = se->num_dests;
if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_DESTS, dests, &len) == -1) {
- char errbuf[1024];
- log_err("ipvs_get_dests: getsockopt() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("ipvs_get_dests: getsockopt() failed: %s", STRERRNO);
free(dests);
return NULL;
}
struct ip_vs_getinfo ipvs_info;
if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) == -1) {
- char errbuf[1024];
- log_err("cipvs_init: socket() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("cipvs_init: socket() failed: %s", STRERRNO);
return -1;
}
if (getsockopt(sockfd, IPPROTO_IP, IP_VS_SO_GET_INFO, &ipvs_info, &len) ==
-1) {
- char errbuf[1024];
- log_err("cipvs_init: getsockopt() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("cipvs_init: getsockopt() failed: %s", STRERRNO);
close(sockfd);
sockfd = -1;
return -1;
*/
fh = fopen("/proc/interrupts", "r");
if (fh == NULL) {
- char errbuf[1024];
- ERROR("irq plugin: fopen (/proc/interrupts): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("irq plugin: fopen (/proc/interrupts): %s", STRERRNO);
return -1;
}
static int nb_add_values(char **ret_buffer, /* {{{ */
size_t *ret_buffer_len, const lcc_value_list_t *vl) {
+ if ((vl == NULL) || (vl->values_len < 1)) {
+ return EINVAL;
+ }
+
char *packet_ptr;
size_t packet_len;
#include <endian.h>
#elif HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
+#else /* fallback */
+__attribute__((const)) static uint16_t be16toh(uint16_t n) {
+ uint8_t tmp[2];
+ memmove(tmp, &n, sizeof(tmp));
+
+ return ((uint16_t)tmp[0] << 8) | ((uint16_t)tmp[1] << 0);
+}
+
+__attribute__((const)) static uint64_t be64toh(uint64_t n) {
+ uint8_t tmp[8];
+ memmove(tmp, &n, sizeof(tmp));
+
+ return ((uint64_t)tmp[0] << 56) | ((uint64_t)tmp[1] << 48) |
+ ((uint64_t)tmp[2] << 40) | ((uint64_t)tmp[3] << 32) |
+ ((uint64_t)tmp[4] << 24) | ((uint64_t)tmp[5] << 16) |
+ ((uint64_t)tmp[6] << 8) | ((uint64_t)tmp[7] << 0);
+}
#endif
#if HAVE_GCRYPT_H
return ret;
}
+#if HAVE_GCRYPT_H
static int test_verify_sha256() {
int ret = 0;
return ret;
}
+#endif
+#if HAVE_GCRYPT_H
static int test_decrypt_aes256() {
char const *iv_str = "4cbe2a747c9f9dcfa0e66f0c2fa74875";
uint8_t iv[16] = {0};
return 0;
}
+#endif
int main(void) {
int ret = 0;
- printf("libcollectdclient/server_test.c\n");
-
int status;
if ((status = test_network_parse())) {
ret = status;
ret = status;
}
+#if HAVE_GCRYPT_H
if ((status = test_verify_sha256())) {
ret = status;
}
if ((status = test_decrypt_aes256())) {
ret = status;
}
+#endif
return ret;
}
};
#else
struct ip_mreq mreq = {
- .imr_address.s_addr = INADDR_ANY, .imr_multiaddr.s_addr = sa->s_addr,
+ .imr_multiaddr.s_addr = sa->sin_addr.s_addr,
};
#endif
status = setsockopt(srv->conn, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
}
static void load_submit(gauge_t snum, gauge_t mnum, gauge_t lnum) {
int cores = 0;
- char errbuf[1024];
#ifdef _SC_NPROCESSORS_ONLN
if (report_relative_load) {
if ((cores = sysconf(_SC_NPROCESSORS_ONLN)) < 1) {
- WARNING("load: sysconf failed : %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("load: sysconf failed : %s", STRERRNO);
}
}
#endif
if (getloadavg(load, 3) == 3)
load_submit(load[LOADAVG_1MIN], load[LOADAVG_5MIN], load[LOADAVG_15MIN]);
else {
- char errbuf[1024];
- WARNING("load: getloadavg failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("load: getloadavg failed: %s", STRERRNO);
}
/* #endif HAVE_GETLOADAVG */
int numfields;
if ((loadavg = fopen("/proc/loadavg", "r")) == NULL) {
- char errbuf[1024];
- WARNING("load: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("load: fopen: %s", STRERRNO);
return -1;
}
if (fgets(buffer, 16, loadavg) == NULL) {
- char errbuf[1024];
- WARNING("load: fgets: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("load: fgets: %s", STRERRNO);
fclose(loadavg);
return -1;
}
if (fclose(loadavg)) {
- char errbuf[1024];
- WARNING("load: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("load: fclose: %s", STRERRNO);
}
numfields = strsplit(buffer, fields, 8);
if (perfstat_cpu_total(NULL, &cputotal, sizeof(perfstat_cpu_total_t), 1) <
0) {
- char errbuf[1024];
- WARNING("load: perfstat_cpu : %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("load: perfstat_cpu : %s", STRERRNO);
return -1;
}
}
if (fh == NULL) {
- char errbuf[1024];
fprintf(stderr, "log_logstash plugin: fopen (%s) failed: %s\n", log_file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
} else {
fprintf(fh, "%s\n", buf);
if (do_close) {
}
if (fh == NULL) {
- char errbuf[1024];
fprintf(stderr, "logfile plugin: fopen (%s) failed: %s\n", log_file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
} else {
if (print_timestamp)
fprintf(fh, "[%s] %s%s\n", timestamp_str, level_str, msg);
sizeof(perfstat_partition_total_t),
/* number = */ 1 /* (must be 1) */);
if (status != 1) {
- char errbuf[1024];
- ERROR("lpar plugin: perfstat_partition_total failed: %s (%i)",
- sstrerror(errno, errbuf, sizeof(errbuf)), status);
+ ERROR("lpar plugin: perfstat_partition_total failed: %s (%i)", STRERRNO,
+ status);
return -1;
}
&lparstats, sizeof(perfstat_partition_total_t),
/* number = */ 1 /* (must be 1) */);
if (status != 1) {
- char errbuf[1024];
- ERROR("lpar plugin: perfstat_partition_total failed: %s (%i)",
- sstrerror(errno, errbuf, sizeof(errbuf)), status);
+ ERROR("lpar plugin: perfstat_partition_total failed: %s (%i)", STRERRNO,
+ status);
return -1;
}
.ai_socktype = SOCK_STREAM};
if ((ai_return = getaddrinfo(host, port, &ai_hints, &ai_list)) != 0) {
- char errbuf[1024];
ERROR("mbmon: getaddrinfo (%s, %s): %s", host, port,
- (ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(ai_return));
+ (ai_return == EAI_SYSTEM) ? STRERRNO : gai_strerror(ai_return));
return -1;
}
/* create our socket descriptor */
if ((fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype,
ai_ptr->ai_protocol)) < 0) {
- char errbuf[1024];
- ERROR("mbmon: socket: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("mbmon: socket: %s", STRERRNO);
continue;
}
/* connect to the mbmon daemon */
if (connect(fd, (struct sockaddr *)ai_ptr->ai_addr, ai_ptr->ai_addrlen)) {
- char errbuf[1024];
- INFO("mbmon: connect (%s, %s): %s", host, port,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ INFO("mbmon: connect (%s, %s): %s", host, port, STRERRNO);
close(fd);
fd = -1;
continue;
while ((status = read(fd, buffer + buffer_fill, buffer_size - buffer_fill)) !=
0) {
if (status == -1) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EINTR))
continue;
- ERROR("mbmon: Error reading from socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("mbmon: Error reading from socket: %s", STRERRNO);
close(fd);
return -1;
}
#define MCELOG_UNCORRECTED_ERR_TYPE_INS "uncorrected_memory_errors"
typedef struct mcelog_config_s {
- char logfile[PATH_MAX]; /* mcelog logfile */
- pthread_t tid; /* poll thread id */
- llist_t *dimms_list; /* DIMMs list */
+ char logfile[PATH_MAX]; /* mcelog logfile */
+ pthread_t tid; /* poll thread id */
+ llist_t *dimms_list; /* DIMMs list */
pthread_mutex_t dimms_lock; /* lock for dimms cache */
_Bool persist;
} mcelog_config_t;
typedef struct mcelog_memory_rec_s {
int corrected_err_total; /* x total*/
int corrected_err_timed; /* x in 24h*/
- char corrected_err_timed_period[DATA_MAX_NAME_LEN];
+ char corrected_err_timed_period[DATA_MAX_NAME_LEN / 2];
int uncorrected_err_total; /* x total*/
int uncorrected_err_timed; /* x in 24h*/
- char uncorrected_err_timed_period[DATA_MAX_NAME_LEN];
- char location[DATA_MAX_NAME_LEN]; /* SOCKET x CHANNEL x DIMM x*/
- char dimm_name[DATA_MAX_NAME_LEN]; /* DMI_NAME "DIMM_F1" */
+ char uncorrected_err_timed_period[DATA_MAX_NAME_LEN / 2];
+ char location[DATA_MAX_NAME_LEN / 2]; /* SOCKET x CHANNEL x DIMM x*/
+ char dimm_name[DATA_MAX_NAME_LEN / 2]; /* DMI_NAME "DIMM_F1" */
} mcelog_memory_rec_t;
static int socket_close(socket_adapter_t *self);
int ret = 0;
pthread_rwlock_rdlock(&self->lock);
if (fcntl(self->sock_fd, F_GETFL) != -1) {
- char errbuf[MCELOG_BUFF_SIZE];
if (shutdown(self->sock_fd, SHUT_RDWR) != 0) {
- ERROR(MCELOG_PLUGIN ": Socket shutdown failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR(MCELOG_PLUGIN ": Socket shutdown failed: %s", STRERRNO);
ret = -1;
}
if (close(self->sock_fd) != 0) {
- ERROR(MCELOG_PLUGIN ": Socket close failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR(MCELOG_PLUGIN ": Socket close failed: %s", STRERRNO);
ret = -1;
}
}
}
static int socket_reinit(socket_adapter_t *self) {
- char errbuff[MCELOG_BUFF_SIZE];
int ret = -1;
cdtime_t interval = plugin_get_interval();
struct timeval socket_timeout = CDTIME_T_TO_TIMEVAL(interval);
self->sock_fd =
socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
if (self->sock_fd < 0) {
- ERROR(MCELOG_PLUGIN ": Could not create a socket. %s",
- sstrerror(errno, errbuff, sizeof(errbuff)));
+ ERROR(MCELOG_PLUGIN ": Could not create a socket. %s", STRERRNO);
pthread_rwlock_unlock(&self->lock);
return ret;
}
pthread_rwlock_rdlock(&self->lock);
if (connect(self->sock_fd, (struct sockaddr *)&(self->unix_sock),
sizeof(self->unix_sock)) < 0) {
- ERROR(MCELOG_PLUGIN ": Failed to connect to mcelog server. %s",
- sstrerror(errno, errbuff, sizeof(errbuff)));
+ ERROR(MCELOG_PLUGIN ": Failed to connect to mcelog server. %s", STRERRNO);
self->close(self);
ret = -1;
} else {
if ((res = poll(&poll_fd, 1, MCELOG_POLL_TIMEOUT)) <= 0) {
if (res != 0 && errno != EINTR) {
- char errbuf[MCELOG_BUFF_SIZE];
- ERROR("mcelog: poll failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("mcelog: poll failed: %s", STRERRNO);
}
pthread_rwlock_unlock(&self->lock);
return res;
}
static void *poll_worker(__attribute__((unused)) void *arg) {
- char errbuf[MCELOG_BUFF_SIZE];
mcelog_thread_running = 1;
FILE **pp_file = calloc(1, sizeof(*pp_file));
if (pp_file == NULL) {
- ERROR("mcelog: memory allocation failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("mcelog: memory allocation failed: %s", STRERRNO);
pthread_exit((void *)1);
}
} /* void md_submit */
static void md_process(const int minor, const char *path) {
- char errbuf[1024];
int fd;
struct stat st;
mdu_array_info_t array;
fd = open(path, O_RDONLY);
if (fd < 0) {
- WARNING("md: open(%s): %s", path, sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("md: open(%s): %s", path, STRERRNO);
return;
}
if (fstat(fd, &st) < 0) {
- WARNING("md: Unable to fstat file descriptor for %s: %s", path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("md: Unable to fstat file descriptor for %s: %s", path, STRERRNO);
close(fd);
return;
}
/* Retrieve md information */
if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) {
- WARNING("md: Unable to retrieve array info from %s: %s", path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("md: Unable to retrieve array info from %s: %s", path, STRERRNO);
close(fd);
return;
}
fh = fopen(PROC_DISKSTATS, "r");
if (fh == NULL) {
- char errbuf[1024];
- WARNING("md: Unable to open %s: %s", PROC_DISKSTATS,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("md: Unable to open %s: %s", PROC_DISKSTATS, STRERRNO);
return -1;
}
/* create our socket descriptor */
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
- char errbuf[1024];
ERROR("memcached plugin: memcached_connect_unix: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
int status = getaddrinfo(st->connhost, st->connport, &ai_hints, &ai_list);
if (status != 0) {
- char errbuf[1024];
ERROR("memcached plugin: memcached_connect_inet: "
"getaddrinfo(%s,%s) failed: %s",
st->connhost, st->connport,
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return -1;
}
/* create our socket descriptor */
fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0) {
- char errbuf[1024];
WARNING("memcached plugin: memcached_connect_inet: "
"socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
continue;
}
status = (int)swrite(st->fd, "stats\r\n", strlen("stats\r\n"));
if (status != 0) {
- char errbuf[1024];
ERROR("memcached plugin: Instance \"%s\": write(2) failed: %s", st->name,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
shutdown(st->fd, SHUT_RDWR);
close(st->fd);
st->fd = -1;
char const end_token[5] = {'E', 'N', 'D', '\r', '\n'};
if (status < 0) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
continue;
ERROR("memcached plugin: Instance \"%s\": Error reading from socket: %s",
- st->name, sstrerror(errno, errbuf, sizeof(errbuf)));
+ st->name, STRERRNO);
shutdown(st->fd, SHUT_RDWR);
close(st->fd);
st->fd = -1;
gauge_t mem_slab_unreclaimable = 0;
if ((fh = fopen("/proc/meminfo", "r")) == NULL) {
- char errbuf[1024];
- WARNING("memory: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("memory: fopen: %s", STRERRNO);
return -1;
}
}
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("memory: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("memory: fclose: %s", STRERRNO);
}
if (mem_total < (mem_free + mem_buffered + mem_cached + mem_slab_total))
size = sizeof(vmtotal);
if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0) {
- char errbuf[1024];
- WARNING("memory plugin: sysctl failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("memory plugin: sysctl failed: %s", STRERRNO);
return -1;
}
perfstat_memory_total_t pmemory = {0};
if (perfstat_memory_total(NULL, &pmemory, sizeof(pmemory), 1) < 0) {
- char errbuf[1024];
- WARNING("memory plugin: perfstat_memory_total failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("memory plugin: perfstat_memory_total failed: %s", STRERRNO);
return -1;
}
status = getaddrinfo(address, /* service = */ NULL, &ai_hints, &ai_list);
if (status != 0) {
- char errbuf[1024];
ERROR("Modbus plugin: getaddrinfo failed: %s",
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return status;
}
status = mosquitto_reconnect(conf->mosq);
if (status != MOSQ_ERR_SUCCESS) {
- char errbuf[1024];
ERROR("mqtt_connect_broker: mosquitto_connect failed: %s",
- (status == MOSQ_ERR_ERRNO) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : mosquitto_strerror(status));
+ (status == MOSQ_ERR_ERRNO) ? STRERRNO : mosquitto_strerror(status));
return -1;
}
status =
mosquitto_username_pw_set(conf->mosq, conf->username, conf->password);
if (status != MOSQ_ERR_SUCCESS) {
- char errbuf[1024];
ERROR("mqtt plugin: mosquitto_username_pw_set failed: %s",
- (status == MOSQ_ERR_ERRNO)
- ? sstrerror(errno, errbuf, sizeof(errbuf))
- : mosquitto_strerror(status));
+ (status == MOSQ_ERR_ERRNO) ? STRERRNO : mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_connect(conf->mosq, conf->host, conf->port, MQTT_KEEPALIVE);
#endif
if (status != MOSQ_ERR_SUCCESS) {
- char errbuf[1024];
ERROR("mqtt plugin: mosquitto_connect failed: %s",
- (status == MOSQ_ERR_ERRNO) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : mosquitto_strerror(status));
+ (status == MOSQ_ERR_ERRNO) ? STRERRNO : mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
#endif
conf->qos, conf->retain);
if (status != MOSQ_ERR_SUCCESS) {
- char errbuf[1024];
c_complain(LOG_ERR, &conf->complaint_cantpublish,
"mqtt plugin: mosquitto_publish failed: %s",
- (status == MOSQ_ERR_ERRNO)
- ? sstrerror(errno, errbuf, sizeof(errbuf))
- : mosquitto_strerror(status));
+ (status == MOSQ_ERR_ERRNO) ? STRERRNO
+ : mosquitto_strerror(status));
/* Mark our connection "down" regardless of the error as a safety
* measure; we will try to reconnect the next time we have to publish a
* message */
/* args = */ subscribers[i],
/* name = */ "mqtt");
if (status != 0) {
- char errbuf[1024];
- ERROR("mqtt plugin: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("mqtt plugin: pthread_create failed: %s", STRERRNO);
continue;
}
}
tcflush(fd, TCIFLUSH);
if (gettimeofday(&time_end, NULL) < 0) {
- char errbuf[1024];
- ERROR("multimeter plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("multimeter plugin: gettimeofday failed: %s", STRERRNO);
return -1;
}
time_end.tv_sec++;
FD_SET(fd, &rfds);
if (gettimeofday(&time_now, NULL) < 0) {
- char errbuf[1024];
ERROR("multimeter plugin: "
"gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
if (timeval_cmp(time_end, time_now, &timeout) < 0)
continue;
} else /* status == -1 */
{
- char errbuf[1024];
ERROR("multimeter plugin: "
"select failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
break;
}
}
continue;
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*stats.stats64)) < 0) {
+ char errbuf[1024];
ERROR("netlink plugin: link_filter_cb: IFLA_STATS64 mnl_attr_validate2 "
- "failed.");
+ "failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
return MNL_CB_ERROR;
}
stats.stats64 = mnl_attr_get_payload(attr);
continue;
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*stats.stats32)) < 0) {
+ char errbuf[1024];
ERROR("netlink plugin: link_filter_cb: IFLA_STATS mnl_attr_validate2 "
- "failed.");
+ "failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
return MNL_CB_ERROR;
}
stats.stats32 = mnl_attr_get_payload(attr);
if (mnl_attr_get_type(attr) == TCA_STATS_BASIC) {
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*q_stats->bs)) < 0) {
+ char errbuf[1024];
ERROR("netlink plugin: qos_attr_cb: TCA_STATS_BASIC mnl_attr_validate2 "
- "failed.");
+ "failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
return MNL_CB_ERROR;
}
q_stats->bs = mnl_attr_get_payload(attr);
continue;
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*ts)) < 0) {
+ char errbuf[1024];
ERROR("netlink plugin: qos_filter_cb: TCA_STATS mnl_attr_validate2 "
- "failed.");
+ "failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
return MNL_CB_ERROR;
}
ts = mnl_attr_get_payload(attr);
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
}
if (ret < 0) {
- ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed.");
- return -1;
+ char errbuf[1024];
+ ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
+ return (-1);
}
/* `link_filter_cb' will update `iflist' which is used here to iterate
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
}
if (ret < 0) {
- ERROR("netlink plugin: ir_read:mnl_socket_recvfrom failed.");
+ char errbuf[1024];
+ ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s",
+ sstrerror(errno, errbuf, sizeof(errbuf)));
continue;
}
-
} /* for (type_index) */
} /* for (if_index) */
if (setsockopt(se->data.client.fd, IPPROTO_IP, optname, &network_config_ttl,
sizeof(network_config_ttl)) != 0) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv4-ttl): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv4-ttl): %s", STRERRNO);
return -1;
}
} else if (ai->ai_family == AF_INET6) {
if (setsockopt(se->data.client.fd, IPPROTO_IPV6, optname,
&network_config_ttl, sizeof(network_config_ttl)) != 0) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt(ipv6-ttl): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt(ipv6-ttl): %s", STRERRNO);
return -1;
}
}
if (setsockopt(se->data.client.fd, IPPROTO_IP, IP_MULTICAST_IF, &mreq,
sizeof(mreq)) != 0) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv4-multicast-if): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv4-multicast-if): %s", STRERRNO);
return -1;
}
if (IN6_IS_ADDR_MULTICAST(&addr->sin6_addr)) {
if (setsockopt(se->data.client.fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
&se->interface, sizeof(se->interface)) != 0) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv6-multicast-if): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv6-multicast-if): %s", STRERRNO);
return -1;
}
if (setsockopt(se->data.client.fd, SOL_SOCKET, SO_BINDTODEVICE,
interface_name, sizeof(interface_name)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (bind-if): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (bind-if): %s", STRERRNO);
return -1;
}
/* #endif HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */
/* allow multiple sockets to use the same PORT number */
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (reuseaddr): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (reuseaddr): %s", STRERRNO);
return -1;
}
DEBUG("fd = %i; calling `bind'", fd);
if (bind(fd, ai->ai_addr, ai->ai_addrlen) == -1) {
- char errbuf[1024];
- ERROR("bind: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("bind: %s", STRERRNO);
return -1;
}
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) ==
-1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (multicast-loop): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (multicast-loop): %s", STRERRNO);
return -1;
}
if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) ==
-1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (add-membership): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (add-membership): %s", STRERRNO);
return -1;
}
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &loop,
sizeof(loop)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv6-multicast-loop): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv6-multicast-loop): %s", STRERRNO);
return -1;
}
if (setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq,
sizeof(mreq)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (ipv6-add-membership): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (ipv6-add-membership): %s", STRERRNO);
return -1;
}
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, interface_name,
sizeof(interface_name)) == -1) {
- char errbuf[1024];
- ERROR("network plugin: setsockopt (bind-if): %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: setsockopt (bind-if): %s", STRERRNO);
return -1;
}
}
client->fd =
socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (client->fd < 0) {
- char errbuf[1024];
- ERROR("network plugin: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: socket(2) failed: %s", STRERRNO);
continue;
}
*tmp = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (*tmp < 0) {
- char errbuf[1024];
- ERROR("network plugin: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: socket(2) failed: %s", STRERRNO);
continue;
}
while (listen_loop == 0) {
status = poll(listen_sockets_pollfd, listen_sockets_num, -1);
if (status <= 0) {
- char errbuf[1024];
if (errno == EINTR)
continue;
- ERROR("network plugin: poll(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: poll(2) failed: %s", STRERRNO);
break;
}
buffer_len = recv(listen_sockets_pollfd[i].fd, buffer, sizeof(buffer),
0 /* no flags */);
if (buffer_len < 0) {
- char errbuf[1024];
status = (errno != 0) ? errno : -1;
- ERROR("network plugin: recv(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network plugin: recv(2) failed: %s", STRERRNO);
break;
}
/* flags = */ 0, (struct sockaddr *)se->data.client.addr,
se->data.client.addrlen);
if (status < 0) {
- char errbuf[1024];
-
if ((errno == EINTR) || (errno == EAGAIN))
continue;
ERROR("network plugin: sendto failed: %s. Closing sending socket.",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
sockent_client_disconnect(se);
return;
}
dispatch_thread, NULL /* no argument */,
"network disp");
if (status != 0) {
- char errbuf[1024];
- ERROR("network: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network: pthread_create failed: %s", STRERRNO);
} else {
dispatch_thread_running = 1;
}
receive_thread, NULL /* no argument */,
"network recv");
if (status != 0) {
- char errbuf[1024];
- ERROR("network: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("network: pthread_create failed: %s", STRERRNO);
} else {
receive_thread_running = 1;
}
fd = open(file, O_WRONLY | O_APPEND);
if (fd < 0) {
- char errbuf[1024];
status = errno;
- ERROR("notify_nagios plugin: Opening \"%s\" failed: %s", file,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("notify_nagios plugin: Opening \"%s\" failed: %s", file, STRERRNO);
return status;
}
status = fcntl(fd, F_GETLK, &lock);
if (status != 0) {
- char errbuf[1024];
status = errno;
ERROR("notify_nagios plugin: Failed to acquire write lock on \"%s\": %s",
- file, sstrerror(status, errbuf, sizeof(errbuf)));
+ file, STRERRNO);
close(fd);
return status;
}
status = (int)lseek(fd, 0, SEEK_END);
if (status == -1) {
- char errbuf[1024];
status = errno;
ERROR("notify_nagios plugin: Seeking to end of \"%s\" failed: %s", file,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ STRERRNO);
close(fd);
return status;
}
status = (int)swrite(fd, buffer, strlen(buffer));
if (status != 0) {
- char errbuf[1024];
status = errno;
- ERROR("notify_nagios plugin: Writing to \"%s\" failed: %s", file,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("notify_nagios plugin: Writing to \"%s\" failed: %s", file, STRERRNO);
close(fd);
return status;
}
.ai_socktype = SOCK_DGRAM};
if ((status = getaddrinfo(host, port, &ai_hints, &ai_list)) != 0) {
- char errbuf[1024];
ERROR("ntpd plugin: getaddrinfo (%s, %s): %s", host, port,
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return -1;
}
*res_data = NULL;
if (gettimeofday(&time_end, NULL) < 0) {
- char errbuf[1024];
- ERROR("ntpd plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ntpd plugin: gettimeofday failed: %s", STRERRNO);
return -1;
}
time_end.tv_sec++; /* wait for a most one second */
struct timeval time_left;
if (gettimeofday(&time_now, NULL) < 0) {
- char errbuf[1024];
- ERROR("ntpd plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ntpd plugin: gettimeofday failed: %s", STRERRNO);
return -1;
}
continue;
if (status < 0) {
- char errbuf[1024];
- ERROR("ntpd plugin: poll failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ntpd plugin: poll failed: %s", STRERRNO);
return -1;
}
continue;
if (status < 0) {
- char errbuf[1024];
- INFO("recv(2) failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ INFO("recv(2) failed: %s", STRERRNO);
DEBUG("Closing socket #%i", sd);
close(sd);
sock_descr = sd = -1;
buffer_size, NULL, 0, /* No port name */
flags);
if (status != 0) {
- char errbuf[1024];
ERROR("ntpd plugin: getnameinfo failed: %s",
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return -1;
}
fh = fopen(path, "r");
if (fh == NULL) {
- char errbuf[1024];
ERROR("numa plugin: Reading node %i failed: open(%s): %s", node, path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
break;
} else /* ((status != 0) && (errno != ENOENT)) */
{
- char errbuf[1024];
- ERROR("numa plugin: stat(%s) failed: %s", path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("numa plugin: stat(%s) failed: %s", path, STRERRNO);
return -1;
}
}
ai_ptr = ai_ptr->ai_next) {
int fd;
int status;
- char errbuf[1024];
fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0) {
- ERROR("olsrd plugin: socket failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("olsrd plugin: socket failed: %s", STRERRNO);
continue;
}
status = connect(fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- ERROR("olsrd plugin: connect failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("olsrd plugin: connect failed: %s", STRERRNO);
close(fd);
continue;
}
char *buffer;
size_t buffer_size;
int status;
- char errbuf[1024];
char file[4096];
char *endptr;
status = OW_get(file, &buffer, &buffer_size);
if (status < 0) {
ERROR("onewire plugin: OW_get (%s/%s) failed. error = %s;", path,
- family_info->features[i].filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ family_info->features[i].filename, STRERRNO);
return -1;
}
DEBUG("Read onewire device %s as %s", file, buffer);
char *buffer;
size_t buffer_size;
int status;
- char errbuf[1024];
char *buffer_ptr;
char *dummy;
status = OW_get(path, &buffer, &buffer_size);
if (status < 0) {
- ERROR("onewire plugin: OW_get (%s) failed. error = %s;", path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("onewire plugin: OW_get (%s) failed. error = %s;", path, STRERRNO);
return -1;
}
DEBUG("onewire plugin: OW_get (%s) returned: %s", path, buffer);
char *buffer;
size_t buffer_size;
int status;
- char errbuf[1024];
char *endptr;
direct_access_element_t *traverse;
status = OW_get(traverse->path, &buffer, &buffer_size);
if (status < 0) {
ERROR("onewire plugin: OW_get (%s) failed. status = %s;", traverse->path,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
DEBUG("onewire plugin: Read onewire device %s as %s", traverse->path,
static int cow_init(void) {
int status;
- char errbuf[1024];
if (device_g == NULL) {
ERROR("onewire plugin: cow_init: No device configured.");
DEBUG("onewire plugin: about to init device <%s>.", device_g);
status = (int)OW_init(device_g);
if (status != 0) {
- ERROR("onewire plugin: OW_init(%s) failed: %s.", device_g,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("onewire plugin: OW_init(%s) failed: %s.", device_g, STRERRNO);
return 1;
}
FILE *fh = fopen(st->file, "r");
if (fh == NULL) {
- char errbuf[1024];
- WARNING("openvpn plugin: fopen(%s) failed: %s", st->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("openvpn plugin: fopen(%s) failed: %s", st->file, STRERRNO);
return -1;
}
char *status_file = strdup(value);
if (status_file == NULL) {
- char errbuf[1024];
- ERROR("openvpn plugin: strdup failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("openvpn plugin: strdup failed: %s", STRERRNO);
return 1;
}
/* create a new vpn element */
vpn_status_t *instance = calloc(1, sizeof(*instance));
if (instance == NULL) {
- char errbuf[1024];
- ERROR("openvpn plugin: malloc failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("openvpn plugin: malloc failed: %s", STRERRNO);
sfree(status_file);
return 1;
}
ovs_events_config_free();
return -1;
}
- strncpy(ovs_events_ctx.config.ovs_db_serv, service,
- sizeof(ovs_events_ctx.config.ovs_db_serv));
+ sstrncpy(ovs_events_ctx.config.ovs_db_serv, service,
+ sizeof(ovs_events_ctx.config.ovs_db_serv));
sfree(service);
} else if (strcasecmp("Socket", child->key) == 0) {
if (cf_util_get_string_buffer(
br = ovs_stats_get_bridge(g_bridge_list_head, YAJL_GET_STRING(br_name));
pthread_mutex_lock(&g_stats_lock);
if (br == NULL) {
- br = (bridge_list_t *)calloc(1, sizeof(bridge_list_t));
+ br = calloc(1, sizeof(*br));
if (!br) {
- ERROR("%s: Error allocating memory for bridge", plugin_name);
+ pthread_mutex_unlock(&g_stats_lock);
+ ERROR("%s: calloc(%zu) failed.", plugin_name, sizeof(*br));
return -1;
}
char *tmp = YAJL_GET_STRING(br_name);
if (br->name == NULL) {
sfree(br);
pthread_mutex_unlock(&g_stats_lock);
+ ERROR("%s: strdup failed.", plugin_name);
return -1;
}
br->next = g_bridge_list_head;
/* Get interface statistic and external_ids */
static int ovs_stats_update_iface(yajl_val iface) {
- yajl_val row;
- port_list_t *port = NULL;
- if (iface && YAJL_IS_OBJECT(iface)) {
- row = ovs_utils_get_value_by_key(iface, "new");
- if (row && YAJL_IS_OBJECT(row)) {
- yajl_val iface_name = ovs_utils_get_value_by_key(row, "name");
- yajl_val iface_stats = ovs_utils_get_value_by_key(row, "statistics");
- yajl_val iface_ext_ids = ovs_utils_get_value_by_key(row, "external_ids");
- yajl_val iface_uuid = ovs_utils_get_value_by_key(row, "_uuid");
- if (iface_name && YAJL_IS_STRING(iface_name)) {
- port = ovs_stats_get_port_by_name(YAJL_GET_STRING(iface_name));
- if (port == NULL)
- return 0;
- }
- /*
- * {
- "statistics": [
- "map",
- [
- [
- "collisions",
- 0
- ],
- . . .
- [
- "tx_packets",
- 0
- ]
- ]
- ]
- }
- Check that statistics is an array with 2 elements
- */
- if (iface_stats && YAJL_IS_ARRAY(iface_stats) &&
- YAJL_GET_ARRAY(iface_stats)->len == 2)
- ovs_stats_update_iface_stats(port,
- YAJL_GET_ARRAY(iface_stats)->values[1]);
- if (iface_ext_ids && YAJL_IS_ARRAY(iface_ext_ids))
- ovs_stats_update_iface_ext_ids(
- port, YAJL_GET_ARRAY(iface_ext_ids)->values[1]);
- if (iface_uuid && YAJL_IS_ARRAY(iface_uuid) &&
- YAJL_GET_ARRAY(iface_uuid)->len == 2)
- sstrncpy(port->iface_uuid,
- YAJL_GET_STRING(YAJL_GET_ARRAY(iface_uuid)->values[1]),
- sizeof(port->iface_uuid));
- }
- } else {
- ERROR("Incorrect JSON Port data");
+ if (!iface || !YAJL_IS_OBJECT(iface)) {
+ ERROR("ovs_stats plugin: incorrect JSON port data");
return -1;
}
+
+ yajl_val row = ovs_utils_get_value_by_key(iface, "new");
+ if (!row || !YAJL_IS_OBJECT(row))
+ return 0;
+
+ yajl_val iface_name = ovs_utils_get_value_by_key(row, "name");
+ if (!iface_name || !YAJL_IS_STRING(iface_name))
+ return 0;
+
+ port_list_t *port = ovs_stats_get_port_by_name(YAJL_GET_STRING(iface_name));
+ if (port == NULL)
+ return 0;
+
+ yajl_val iface_stats = ovs_utils_get_value_by_key(row, "statistics");
+ yajl_val iface_ext_ids = ovs_utils_get_value_by_key(row, "external_ids");
+ yajl_val iface_uuid = ovs_utils_get_value_by_key(row, "_uuid");
+ /*
+ * {
+ "statistics": [
+ "map",
+ [
+ [
+ "collisions",
+ 0
+ ],
+ . . .
+ [
+ "tx_packets",
+ 0
+ ]
+ ]
+ ]
+ }
+ Check that statistics is an array with 2 elements
+ */
+ if (iface_stats && YAJL_IS_ARRAY(iface_stats) &&
+ YAJL_GET_ARRAY(iface_stats)->len == 2)
+ ovs_stats_update_iface_stats(port, YAJL_GET_ARRAY(iface_stats)->values[1]);
+ if (iface_ext_ids && YAJL_IS_ARRAY(iface_ext_ids))
+ ovs_stats_update_iface_ext_ids(port,
+ YAJL_GET_ARRAY(iface_ext_ids)->values[1]);
+ if (iface_uuid && YAJL_IS_ARRAY(iface_uuid) &&
+ YAJL_GET_ARRAY(iface_uuid)->len == 2)
+ sstrncpy(port->iface_uuid,
+ YAJL_GET_STRING(YAJL_GET_ARRAY(iface_uuid)->values[1]),
+ sizeof(port->iface_uuid));
+
return 0;
}
*/
static int ovs_stats_plugin_config(oconfig_item_t *ci) {
bridge_list_t *bridge;
- char *br_name;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
goto cleanup_fail;
}
/* get value */
- if ((br_name = strdup(child->values[j].value.string)) == NULL) {
- ERROR("%s: strdup() copy bridge name fail", plugin_name);
- goto cleanup_fail;
- }
+ char const *br_name = child->values[j].value.string;
if ((bridge = ovs_stats_get_bridge(g_monitored_bridge_list_head,
br_name)) == NULL) {
if ((bridge = calloc(1, sizeof(bridge_list_t))) == NULL) {
ERROR("%s: Error allocating memory for bridge", plugin_name);
goto cleanup_fail;
} else {
+ char *br_name_dup = strdup(br_name);
+ if (br_name_dup == NULL) {
+ ERROR("%s: strdup() copy bridge name fail", plugin_name);
+ goto cleanup_fail;
+ }
+
pthread_mutex_lock(&g_stats_lock);
/* store bridge name */
- bridge->name = br_name;
+ bridge->name = br_name_dup;
bridge->next = g_monitored_bridge_list_head;
g_monitored_bridge_list_head = bridge;
pthread_mutex_unlock(&g_stats_lock);
/* Shutdown OvS Stats plugin */
static int ovs_stats_plugin_shutdown(void) {
- pthread_mutex_lock(&g_stats_lock);
DEBUG("OvS Statistics plugin shutting down");
ovs_db_destroy(g_ovs_db);
+ pthread_mutex_lock(&g_stats_lock);
ovs_stats_free_bridge_list(g_bridge_list_head);
ovs_stats_free_bridge_list(g_monitored_bridge_list_head);
ovs_stats_free_port_list(g_port_list_head);
static int notification_meta2av(pTHX_ notification_meta_t *meta, AV *array) {
int meta_num = 0;
-
- while (meta) {
+ for (notification_meta_t *m = meta; m != NULL; m = m->next) {
++meta_num;
- meta = meta->next;
}
av_extend(array, meta_num);
fd = open(pf_device, O_RDONLY);
if (fd < 0) {
- char errbuf[1024];
- ERROR("pf plugin: Unable to open %s: %s", pf_device,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("pf plugin: Unable to open %s: %s", pf_device, STRERRNO);
return -1;
}
status = ioctl(fd, DIOCGETSTATUS, &state);
if (status != 0) {
- char errbuf[1024];
- ERROR("pf plugin: ioctl(DIOCGETSTATUS) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("pf plugin: ioctl(DIOCGETSTATUS) failed: %s", STRERRNO);
close(fd);
return -1;
}
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (fd < 0) {
- char errbuf[1024];
- ERROR("pinba plugin: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("pinba plugin: socket(2) failed: %s", STRERRNO);
return 0;
}
tmp = 1;
status = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));
if (status != 0) {
- char errbuf[1024];
- WARNING("pinba plugin: setsockopt(SO_REUSEADDR) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("pinba plugin: setsockopt(SO_REUSEADDR) failed: %s", STRERRNO);
}
status = bind(fd, ai->ai_addr, ai->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- ERROR("pinba plugin: bind(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("pinba plugin: bind(2) failed: %s", STRERRNO);
close(fd);
return 0;
}
status = recvfrom(sock, buffer, buffer_size - 1, MSG_DONTWAIT,
/* from = */ NULL, /* from len = */ 0);
if (status < 0) {
- char errbuf[1024];
if ((errno == EINTR)
#ifdef EWOULDBLOCK
continue;
}
- WARNING("pinba plugin: recvfrom(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("pinba plugin: recvfrom(2) failed: %s", STRERRNO);
return -1;
} else if (status == 0) {
DEBUG("pinba plugin: recvfrom(2) returned unexpected status zero.");
{
continue;
} else if (status < 0) {
- char errbuf[1024];
-
if ((errno == EINTR) || (errno == EAGAIN))
continue;
- ERROR("pinba plugin: poll(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("pinba plugin: poll(2) failed: %s", STRERRNO);
pinba_socket_free(s);
return -1;
}
/* attrs = */ NULL, collector_thread,
/* args = */ NULL, "pinba collector");
if (status != 0) {
- char errbuf[1024];
- ERROR("pinba plugin: pthread_create(3) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("pinba plugin: pthread_create(3) failed: %s", STRERRNO);
return -1;
}
collector_thread_running = 1;
status = pthread_join(collector_thread_id, /* retval = */ NULL);
if (status != 0) {
- char errbuf[1024];
- ERROR("pinba plugin: pthread_join(3) failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("pinba plugin: pthread_join(3) failed: %s", STRERROR(status));
}
collector_thread_running = 0;
static double ping_timeout = 0.9;
static int ping_max_missed = -1;
+static pthread_mutex_t ping_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t ping_cond = PTHREAD_COND_INITIALIZER;
static int ping_thread_loop = 0;
static int ping_thread_error = 0;
static pthread_t ping_thread_id;
-static pthread_mutex_t ping_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t ping_cond = PTHREAD_COND_INITIALIZER;
static const char *config_keys[] = {"Host", "SourceAddress",
#ifdef HAVE_OPING_1_3
static void *ping_thread(void *arg) /* {{{ */
{
- pingobj_t *pingobj = NULL;
-
struct timeval tv_begin;
struct timeval tv_end;
struct timespec ts_wait;
c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
- pthread_mutex_lock(&ping_lock);
-
- pingobj = ping_construct();
+ pingobj_t *pingobj = ping_construct();
if (pingobj == NULL) {
ERROR("ping plugin: ping_construct failed.");
+ pthread_mutex_lock(&ping_lock);
ping_thread_error = 1;
pthread_mutex_unlock(&ping_lock);
return (void *)-1;
if (count == 0) {
ERROR("ping plugin: No host could be added to ping object. Giving up.");
+ pthread_mutex_lock(&ping_lock);
ping_thread_error = 1;
pthread_mutex_unlock(&ping_lock);
return (void *)-1;
ts_int.tv_nsec = (long)(temp_nsec * 1000000000L);
}
+ pthread_mutex_lock(&ping_lock);
while (ping_thread_loop > 0) {
- int status;
_Bool send_successful = 0;
if (gettimeofday(&tv_begin, NULL) < 0) {
- char errbuf[1024];
- ERROR("ping plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ping plugin: gettimeofday failed: %s", STRERRNO);
ping_thread_error = 1;
break;
}
pthread_mutex_unlock(&ping_lock);
- status = ping_send(pingobj);
+ int status = ping_send(pingobj);
if (status < 0) {
c_complain(LOG_ERR, &complaint, "ping plugin: ping_send failed: %s",
ping_get_error(pingobj));
(void)ping_dispatch_all(pingobj);
if (gettimeofday(&tv_end, NULL) < 0) {
- char errbuf[1024];
- ERROR("ping plugin: gettimeofday failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ping plugin: gettimeofday failed: %s", STRERRNO);
ping_thread_error = 1;
break;
}
tmp = strdup(value);
if (tmp == NULL) {
- char errbuf[1024];
ERROR("ping plugin: Setting `%s' to `%s' failed: strdup failed: %s", name,
- value, sstrerror(errno, errbuf, sizeof(errbuf)));
+ value, STRERRNO);
return 1;
}
hl = malloc(sizeof(*hl));
if (hl == NULL) {
- char errbuf[1024];
- ERROR("ping plugin: malloc failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ping plugin: malloc failed: %s", STRERRNO);
return 1;
}
host = strdup(value);
if (host == NULL) {
- char errbuf[1024];
sfree(hl);
- ERROR("ping plugin: strdup failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ping plugin: strdup failed: %s", STRERRNO);
return 1;
}
</Query>
<Query queries>
- Statement "SELECT sum(n_tup_ins) AS ins, \
- sum(n_tup_upd) AS upd, \
- sum(n_tup_del) AS del \
+ Statement "SELECT coalesce(sum(n_tup_ins), 0) AS ins, \
+ coalesce(sum(n_tup_upd), 0) AS upd, \
+ coalesce(sum(n_tup_del), 0) AS del \
FROM pg_stat_user_tables;"
<Result>
</Query>
<Query queries>
- Statement "SELECT sum(n_tup_ins) AS ins, \
- sum(n_tup_upd) AS upd, \
- sum(n_tup_del) AS del, \
- sum(n_tup_hot_upd) AS hot_upd \
+ Statement "SELECT coalesce(sum(n_tup_ins), 0) AS ins, \
+ coalesce(sum(n_tup_upd), 0) AS upd, \
+ coalesce(sum(n_tup_del), 0) AS del, \
+ coalesce(sum(n_tup_hot_upd), 0) AS hot_upd \
FROM pg_stat_user_tables;"
<Result>
</Query>
<Query table_states>
- Statement "SELECT sum(n_live_tup) AS live, sum(n_dead_tup) AS dead \
+ Statement "SELECT coalesce(sum(n_live_tup), 0) AS live, \
+ coalesce(sum(n_dead_tup), 0) AS dead \
FROM pg_stat_user_tables;"
<Result>
#endif
#define FUNC_ERROR(func) \
do { \
- char errbuf[1024]; \
- ERROR("powerdns plugin: %s failed: %s", func, \
- sstrerror(errno, errbuf, sizeof(errbuf))); \
+ ERROR("powerdns plugin: %s failed: %s", func, STRERRNO); \
} while (0)
#define SOCK_ERROR(func, sockpath) \
do { \
- char errbuf[1024]; \
ERROR("powerdns plugin: Socket `%s` %s failed: %s", sockpath, func, \
- sstrerror(errno, errbuf, sizeof(errbuf))); \
+ STRERRNO); \
} while (0)
#define SERVER_SOCKET LOCALSTATEDIR "/run/pdns.controlsocket"
plugin_dispatch_values(&vl);
} /* }}} static void submit */
-static int powerdns_get_data_dgram(list_item_t *item, /* {{{ */
- char **ret_buffer, size_t *ret_buffer_size) {
+static int powerdns_get_data_dgram(list_item_t *item, char **ret_buffer) {
+ /* {{{ */
int sd;
int status;
buffer[buffer_size - 1] = 0;
*ret_buffer = buffer;
- *ret_buffer_size = buffer_size;
-
return 0;
} /* }}} int powerdns_get_data_dgram */
-static int powerdns_get_data_stream(list_item_t *item, /* {{{ */
- char **ret_buffer,
- size_t *ret_buffer_size) {
+static int powerdns_get_data_stream(list_item_t *item, char **ret_buffer) {
+ /* {{{ */
int sd;
int status;
if (status < 0) {
SOCK_ERROR("recv", item->sockaddr.sun_path);
break;
- } else if (status == 0)
+ } else if (status == 0) {
break;
+ }
buffer_new = realloc(buffer, buffer_size + status + 1);
if (buffer_new == NULL) {
FUNC_ERROR("realloc");
- status = -1;
+ status = ENOMEM;
break;
}
buffer = buffer_new;
} /* while (42) */
close(sd);
- if (status < 0) {
+ if (status != 0) {
sfree(buffer);
- } else {
- assert(status == 0);
- *ret_buffer = buffer;
- *ret_buffer_size = buffer_size;
+ return status;
}
- return status;
+ *ret_buffer = buffer;
+ return 0;
} /* }}} int powerdns_get_data_stream */
-static int powerdns_get_data(list_item_t *item, char **ret_buffer,
- size_t *ret_buffer_size) {
+static int powerdns_get_data(list_item_t *item, char **ret_buffer) {
if (item->socktype == SOCK_DGRAM)
- return powerdns_get_data_dgram(item, ret_buffer, ret_buffer_size);
+ return powerdns_get_data_dgram(item, ret_buffer);
else if (item->socktype == SOCK_STREAM)
- return powerdns_get_data_stream(item, ret_buffer, ret_buffer_size);
+ return powerdns_get_data_stream(item, ret_buffer);
else {
ERROR("powerdns plugin: Unknown socket type: %i", (int)item->socktype);
return -1;
static int powerdns_read_server(list_item_t *item) /* {{{ */
{
- char *buffer = NULL;
- size_t buffer_size = 0;
- int status;
-
- char *dummy;
- char *saveptr;
-
- char *key;
- char *value;
-
- const char *const *fields;
- int fields_num;
-
if (item->command == NULL)
item->command = strdup(SERVER_COMMAND);
if (item->command == NULL) {
return -1;
}
- status = powerdns_get_data(item, &buffer, &buffer_size);
- if (status != 0)
- return -1;
+ char *buffer = NULL;
+ int status = powerdns_get_data(item, &buffer);
+ if (status != 0) {
+ ERROR("powerdns plugin: powerdns_get_data failed.");
+ return status;
+ }
+ if (buffer == NULL) {
+ return EINVAL;
+ }
+ const char *const *fields = default_server_fields;
+ int fields_num = default_server_fields_num;
if (item->fields_num != 0) {
fields = (const char *const *)item->fields;
fields_num = item->fields_num;
- } else {
- fields = default_server_fields;
- fields_num = default_server_fields_num;
}
assert(fields != NULL);
/* corrupt-packets=0,deferred-cache-inserts=0,deferred-cache-lookup=0,latency=0,packetcache-hit=0,packetcache-miss=0,packetcache-size=0,qsize-q=0,query-cache-hit=0,query-cache-miss=0,recursing-answers=0,recursing-questions=0,servfail-packets=0,tcp-answers=0,tcp-queries=0,timedout-packets=0,udp-answers=0,udp-queries=0,udp4-answers=0,udp4-queries=0,udp6-answers=0,udp6-queries=0,
*/
- dummy = buffer;
- saveptr = NULL;
+ char *dummy = buffer;
+ char *saveptr = NULL;
+ char *key;
while ((key = strtok_r(dummy, ",", &saveptr)) != NULL) {
dummy = NULL;
- value = strchr(key, '=');
+ char *value = strchr(key, '=');
if (value == NULL)
break;
static int powerdns_read_recursor(list_item_t *item) /* {{{ */
{
char *buffer = NULL;
- size_t buffer_size = 0;
int status;
char *dummy;
}
assert(item->command != NULL);
- status = powerdns_get_data(item, &buffer, &buffer_size);
+ status = powerdns_get_data(item, &buffer);
if (status != 0) {
ERROR("powerdns plugin: powerdns_get_data failed.");
return -1;
ps_update_counter(&ps->io_diskw, &pse->io_diskw, entry->io_diskw);
}
- if ((entry->cswitch_vol != -1) && (entry->cswitch_vol != -1)) {
+ if ((entry->cswitch_vol != -1) && (entry->cswitch_invol != -1)) {
ps_update_counter(&ps->cswitch_vol, &pse->cswitch_vol,
entry->cswitch_vol);
ps_update_counter(&ps->cswitch_invol, &pse->cswitch_invol,
} /* while (fgets) */
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("processes: fclose: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes: fclose: %s", STRERRNO);
}
}
closedir(dh);
} /* while (fgets) */
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes: fclose: %s", STRERRNO);
}
ps->vmem_data = data * 1024;
} /* while (fgets) */
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes: fclose: %s", STRERRNO);
}
return 0;
} /* int ps_read_io (...) */
} /* while (fgets) */
if (fclose(fh)) {
- char errbuf[1024];
- WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes: fclose: %s", STRERRNO);
}
return count;
} /* int ps_count_maps (...) */
errno = 0;
fd = open(file, O_RDONLY);
if (fd < 0) {
- char errbuf[4096];
/* ENOENT means the process exited while we were handling it.
* Don't complain about this, it only fills the logs. */
if (errno != ENOENT)
- WARNING("processes plugin: Failed to open `%s': %s.", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("processes plugin: Failed to open `%s': %s.", file, STRERRNO);
return NULL;
}
status = read(fd, (void *)buf_ptr, len);
if (status < 0) {
- char errbuf[1024];
if ((EAGAIN == errno) || (EINTR == errno))
continue;
WARNING("processes plugin: Failed to read from `%s': %s.", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
close(fd);
return NULL;
}
proc_stat = fopen("/proc/stat", "r");
if (proc_stat == NULL) {
- char errbuf[1024];
- ERROR("processes plugin: fopen (/proc/stat) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("processes plugin: fopen (/proc/stat) failed: %s", STRERRNO);
return -1;
}
ps_list_reset();
if ((proc = opendir("/proc")) == NULL) {
- char errbuf[1024];
- ERROR("Cannot open `/proc': %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("Cannot open `/proc': %s", STRERRNO);
return -1;
}
fh = fopen(path, "r");
if (fh == NULL) {
- ERROR("protocols plugin: fopen (%s) failed: %s.", path,
- sstrerror(errno, key_buffer, sizeof(key_buffer)));
+ ERROR("protocols plugin: fopen (%s) failed: %s.", path, STRERRNO);
return -1;
}
rd->connection =
ros_connect(rd->node, rd->service, rd->username, rd->password);
if (rd->connection == NULL) {
- char errbuf[128];
- ERROR("routeros plugin: ros_connect failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("routeros plugin: ros_connect failed: %s", STRERRNO);
return -1;
}
}
status = ros_interface(rd->connection, handle_interface,
/* user data = */ rd);
if (status != 0) {
- char errbuf[128];
- ERROR("routeros plugin: ros_interface failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("routeros plugin: ros_interface failed: %s", STRERROR(status));
ros_disconnect(rd->connection);
rd->connection = NULL;
return -1;
status = ros_registration_table(rd->connection, handle_regtable,
/* user data = */ rd);
if (status != 0) {
- char errbuf[128];
ERROR("routeros plugin: ros_registration_table failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ STRERROR(status));
ros_disconnect(rd->connection);
rd->connection = NULL;
return -1;
status = ros_system_resource(rd->connection, handle_system_resource,
/* user data = */ rd);
if (status != 0) {
- char errbuf[128];
ERROR("routeros plugin: ros_system_resource failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ STRERROR(status));
ros_disconnect(rd->connection);
rd->connection = NULL;
return -1;
status = stat(filename, &statbuf);
if (status != 0) {
if (errno != ENOENT) {
- char errbuf[1024];
- ERROR("rrdcached plugin: stat (%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("rrdcached plugin: stat (%s) failed: %s", filename, STRERRNO);
return -1;
}
{
char **tmp = realloc(keys, (keys_num + 1) * sizeof(char *));
if (tmp == NULL) {
- char errbuf[1024];
- ERROR("rrdtool plugin: "
- "realloc failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("rrdtool plugin: realloc failed: %s", STRERRNO);
c_avl_iterator_destroy(iter);
sfree(keys);
return;
return -1;
}
- c_avl_get(cache, filename, (void *)&rc);
-
- if (rc == NULL) {
+ int status = c_avl_get(cache, filename, (void *)&rc);
+ if ((status != 0) || (rc == NULL)) {
rc = malloc(sizeof(*rc));
if (rc == NULL) {
pthread_mutex_unlock(&cache_lock);
values_new =
realloc((void *)rc->values, (rc->values_num + 1) * sizeof(char *));
if (values_new == NULL) {
- char errbuf[1024];
void *cache_key = NULL;
- sstrerror(errno, errbuf, sizeof(errbuf));
-
c_avl_remove(cache, filename, &cache_key, NULL);
pthread_mutex_unlock(&cache_lock);
- ERROR("rrdtool plugin: realloc failed: %s", errbuf);
+ ERROR("rrdtool plugin: realloc failed: %s", STRERRNO);
sfree(cache_key);
sfree(rc->values);
void *cache_key = strdup(filename);
if (cache_key == NULL) {
- char errbuf[1024];
- sstrerror(errno, errbuf, sizeof(errbuf));
-
pthread_mutex_unlock(&cache_lock);
- ERROR("rrdtool plugin: strdup failed: %s", errbuf);
+ ERROR("rrdtool plugin: strdup failed: %s", STRERRNO);
sfree(rc->values[0]);
sfree(rc->values);
if (value_list_to_filename(filename, sizeof(filename), vl) != 0)
return -1;
- char values[32 * ds->ds_num];
+ char values[32 * (ds->ds_num + 1)];
if (value_list_to_string(values, sizeof(values), ds, vl) != 0)
return -1;
return 0;
}
} else {
- char errbuf[1024];
- ERROR("rrdtool plugin: stat(%s) failed: %s", filename,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("rrdtool plugin: stat(%s) failed: %s", filename, STRERRNO);
return -1;
}
} else if (!S_ISREG(statbuf.st_mode)) {
cache_flush_timeout = 0;
} else if (cache_flush_timeout < cache_timeout) {
INFO("rrdtool plugin: \"CacheFlush %.3f\" is less than \"CacheTimeout "
- "%.3f\". "
- "Ajusting \"CacheFlush\" to %.3f seconds.",
+ "%.3f\". Adjusting \"CacheFlush\" to %.3f seconds.",
CDTIME_T_TO_DOUBLE(cache_flush_timeout),
CDTIME_T_TO_DOUBLE(cache_timeout),
CDTIME_T_TO_DOUBLE(cache_timeout * 10));
if (conffile != NULL) {
fh = fopen(conffile, "r");
if (fh == NULL) {
- char errbuf[1024];
- ERROR("sensors plugin: fopen(%s) failed: %s", conffile,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("sensors plugin: fopen(%s) failed: %s", conffile, STRERRNO);
return -1;
}
}
/* there are a variety of names for the serial device */
if ((fh = fopen("/proc/tty/driver/serial", "r")) == NULL &&
(fh = fopen("/proc/tty/driver/ttyS", "r")) == NULL) {
- char errbuf[1024];
- WARNING("serial: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("serial: fopen: %s", STRERRNO);
return -1;
}
status = plugin_thread_create(&sr_thread, NULL, sigrok_read_thread, NULL,
"sigrok read");
if (status != 0) {
- char errbuf[1024];
- ERROR("sigrok plugin: Failed to create thread: %s.",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("sigrok plugin: Failed to create thread: %s.", STRERRNO);
return -1;
}
sr_thread_running = TRUE;
for (vb = res->variables, i = 0; (vb != NULL);
vb = vb->next_variable, i++) {
/* Calculate value index from todo list */
- while ((i < oid_list_len) && !oid_list_todo[i])
+ while ((i < oid_list_len) && !oid_list_todo[i]) {
i++;
+ }
+ if (i >= oid_list_len) {
+ break;
+ }
/* An instance is configured and the res variable we process is the
* instance value (last index) */
}
}
- llentry_t *entry = llentry_create(td->name, td);
- if (entry == NULL) {
- snmp_agent_free_table(&td);
- return -ENOMEM;
- }
-
td->instance_index =
c_avl_create((int (*)(const void *, const void *))strcmp);
if (td->instance_index == NULL) {
return -ENOMEM;
}
+ llentry_t *entry = llentry_create(td->name, td);
+ if (entry == NULL) {
+ snmp_agent_free_table(&td);
+ return -ENOMEM;
+ }
llist_append(g_agent->tables, entry);
return 0;
status = recv(fd, buffer, sizeof(buffer), /* flags = */ MSG_DONTWAIT);
if (status < 0) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
return;
- ERROR("statsd plugin: recv(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: recv(2) failed: %s", STRERRNO);
return;
}
fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0) {
- char errbuf[1024];
- ERROR("statsd plugin: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: socket(2) failed: %s", STRERRNO);
continue;
}
status = bind(fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- ERROR("statsd plugin: bind(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: bind(2) failed: %s", STRERRNO);
close(fd);
continue;
}
while (!network_thread_shutdown) {
status = poll(fds, (nfds_t)fds_num, /* timeout = */ -1);
if (status < 0) {
- char errbuf[1024];
if ((errno == EINTR) || (errno == EAGAIN))
continue;
- ERROR("statsd plugin: poll(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: poll(2) failed: %s", STRERRNO);
break;
}
/* attr = */ NULL, statsd_network_thread,
/* args = */ NULL);
if (status != 0) {
- char errbuf[1024];
pthread_mutex_unlock(&metrics_lock);
- ERROR("statsd plugin: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("statsd plugin: pthread_create failed: %s", STRERRNO);
return status;
}
}
fh = fopen("/proc/swaps", "r");
if (fh == NULL) {
- char errbuf[1024];
- WARNING("swap plugin: fopen (/proc/swaps) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("swap plugin: fopen (/proc/swaps) failed: %s", STRERRNO);
return -1;
}
fh = fopen("/proc/meminfo", "r");
if (fh == NULL) {
- char errbuf[1024];
- WARNING("swap plugin: fopen (/proc/meminfo) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("swap plugin: fopen (/proc/meminfo) failed: %s", STRERRNO);
return -1;
}
/* /proc/vmstat does not exist in kernels <2.6 */
fh = fopen("/proc/stat", "r");
if (fh == NULL) {
- char errbuf[1024];
- WARNING("swap: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("swap: fopen: %s", STRERRNO);
return -1;
} else
old_kernel = 1;
struct anoninfo ai;
if (swapctl(SC_AINFO, &ai) == -1) {
- char errbuf[1024];
- ERROR("swap plugin: swapctl failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("swap plugin: swapctl failed: %s", STRERRNO);
return -1;
}
status = swapctl(SC_LIST, s);
if (status < 0) {
- char errbuf[1024];
- ERROR("swap plugin: swapctl (SC_LIST) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("swap plugin: swapctl (SC_LIST) failed: %s", STRERRNO);
sfree(s_paths);
sfree(s);
return -1;
status =
perfstat_memory_total(NULL, &pmemory, sizeof(perfstat_memory_total_t), 1);
if (status < 0) {
- char errbuf[1024];
- WARNING("swap plugin: perfstat_memory_total failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("swap plugin: perfstat_memory_total failed: %s", STRERRNO);
return -1;
}
} /* tbl_result_setup */
static void tbl_result_clear(tbl_result_t *res) {
+ if (res == NULL) {
+ return;
+ }
+
sfree(res->type);
sfree(res->instance_prefix);
} /* tbl_setup */
static void tbl_clear(tbl_t *tbl) {
+ if (tbl == NULL) {
+ return;
+ }
+
sfree(tbl->file);
sfree(tbl->sep);
sfree(tbl->plugin_name);
sfree(tbl->instance);
+ /* (tbl->results == NULL) -> (tbl->results_num == 0) */
+ assert((tbl->results != NULL) || (tbl->results_num == 0));
for (size_t i = 0; i < tbl->results_num; ++i)
tbl_result_clear(tbl->results + i);
sfree(tbl->results);
tmp = realloc(*var, ((*len) + num) * sizeof(**var));
if (NULL == tmp) {
- char errbuf[1024];
- log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("realloc failed: %s.", STRERRNO);
return -1;
}
*var = tmp;
} /* tbl_config_append_array_s */
static int tbl_config_result(tbl_t *tbl, oconfig_item_t *ci) {
- tbl_result_t *res;
-
- int status = 0;
-
if (0 != ci->values_num) {
log_err("<Result> does not expect any arguments.");
return 1;
}
- res = realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results));
+ tbl_result_t *res =
+ realloc(tbl->results, (tbl->results_num + 1) * sizeof(*tbl->results));
if (res == NULL) {
- char errbuf[1024];
- log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("realloc failed: %s.", STRERRNO);
return -1;
}
tbl->results = res;
- ++tbl->results_num;
- res = tbl->results + tbl->results_num - 1;
+ res = tbl->results + tbl->results_num;
tbl_result_setup(res);
for (int i = 0; i < ci->children_num; ++i) {
c->key);
}
+ int status = 0;
if (NULL == res->type) {
- log_err("No \"Type\" option specified for <Result> "
- "in table \"%s\".",
+ log_err("No \"Type\" option specified for <Result> in table \"%s\".",
tbl->file);
status = 1;
}
if (NULL == res->values) {
- log_err("No \"ValuesFrom\" option specified for <Result> "
- "in table \"%s\".",
+ log_err("No \"ValuesFrom\" option specified for <Result> in table \"%s\".",
tbl->file);
status = 1;
}
if (0 != status) {
tbl_result_clear(res);
- --tbl->results_num;
return status;
}
+
+ tbl->results_num++;
return 0;
} /* tbl_config_result */
static int tbl_config_table(oconfig_item_t *ci) {
- tbl_t *tbl;
-
- int status = 0;
-
if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
log_err("<Table> expects a single string argument.");
return 1;
}
- tbl = realloc(tables, (tables_num + 1) * sizeof(*tables));
+ tbl_t *tbl = realloc(tables, (tables_num + 1) * sizeof(*tables));
if (NULL == tbl) {
- char errbuf[1024];
- log_err("realloc failed: %s.", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("realloc failed: %s.", STRERRNO);
return -1;
}
tables = tbl;
- ++tables_num;
- tbl = tables + tables_num - 1;
+ tbl = tables + tables_num;
tbl_setup(tbl, ci->values[0].value.string);
for (size_t i = 0; i < ((size_t)ci->children_num); ++i) {
c->key, tbl->file);
}
+ int status = 0;
if (NULL == tbl->sep) {
log_err("Table \"%s\" does not specify any separator.", tbl->file);
status = 1;
}
if (NULL == tbl->results) {
+ assert(tbl->results_num == 0);
log_err("Table \"%s\" does not specify any (valid) results.", tbl->file);
status = 1;
}
if (0 != status) {
tbl_clear(tbl);
- --tables_num;
return status;
}
if (res->values[j] > tbl->max_colnum)
tbl->max_colnum = res->values[j];
}
+
+ tables_num++;
return 0;
} /* tbl_config_table */
fh = fopen(tbl->file, "r");
if (NULL == fh) {
- char errbuf[1024];
- log_err("Failed to open file \"%s\": %s.", tbl->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("Failed to open file \"%s\": %s.", tbl->file, STRERRNO);
return -1;
}
}
if (0 != ferror(fh)) {
- char errbuf[1024];
- log_err("Failed to read from file \"%s\": %s.", tbl->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("Failed to read from file \"%s\": %s.", tbl->file, STRERRNO);
fclose(fh);
return -1;
}
char template[DATA_MAX_NAME_LEN];
char value_str[DATA_MAX_NAME_LEN];
- snprintf(template, sizeof(template), "%%{ds:%s}", ds->ds[i].name);
+ const char *format = "%%{ds:%.*s}";
+ snprintf(template, sizeof(template), format,
+ DATA_MAX_NAME_LEN - strlen(format), ds->ds[i].name);
if (ds->ds[i].type != DS_TYPE_GAUGE) {
if ((rates == NULL) && (rates_failed == 0)) {
if (vl->meta != NULL) {
char **meta_toc = NULL;
- int meta_entries = meta_data_toc(vl->meta, &meta_toc);
- if (meta_entries <= 0)
+ int status = meta_data_toc(vl->meta, &meta_toc);
+ if (status <= 0)
return;
+ size_t meta_entries = (size_t)status;
- for (int i = 0; i < meta_entries; i++) {
+ for (size_t i = 0; i < meta_entries; i++) {
char meta_name[DATA_MAX_NAME_LEN];
char *value_str;
const char *key = meta_toc[i];
if (data->meta != NULL) {
char temp[DATA_MAX_NAME_LEN * 2];
- int meta_entries;
char **meta_toc;
if ((new_meta = meta_data_create()) == NULL) {
return -ENOMEM;
}
- meta_entries = meta_data_toc(data->meta, &meta_toc);
- for (int i = 0; i < meta_entries; i++) {
+ int status = meta_data_toc(data->meta, &meta_toc);
+ if (status < 0) {
+ ERROR("Target `set': meta_data_toc failed with status %d.", status);
+ meta_data_destroy(new_meta);
+ return status;
+ }
+ size_t meta_entries = (size_t)status;
+
+ for (size_t i = 0; i < meta_entries; i++) {
const char *key = meta_toc[i];
char *string;
int status;
if (status) {
ERROR("Target `set': Unable to get replacement metadata value `%s'.",
key);
- strarray_free(meta_toc, (size_t)meta_entries);
+ strarray_free(meta_toc, meta_entries);
meta_data_destroy(new_meta);
return status;
}
status = meta_data_add_string(new_meta, key, temp);
if (status) {
ERROR("Target `set': Unable to set metadata value `%s'.", key);
- strarray_free(meta_toc, (size_t)meta_entries);
+ strarray_free(meta_toc, meta_entries);
meta_data_destroy(new_meta);
return status;
}
}
- strarray_free(meta_toc, (size_t)meta_entries);
+ strarray_free(meta_toc, meta_entries);
}
#define SUBST_FIELD(f) \
if (fd < 0) {
ERROR("tcpconns plugin: conn_read_netlink: socket(AF_NETLINK, SOCK_RAW, "
"NETLINK_INET_DIAG) failed: %s",
- sstrerror(errno, buf, sizeof(buf)));
+ STRERRNO);
return -1;
}
if (sendmsg(fd, &msg, 0) < 0) {
ERROR("tcpconns plugin: conn_read_netlink: sendmsg(2) failed: %s",
- sstrerror(errno, buf, sizeof(buf)));
+ STRERRNO);
close(fd);
return -1;
}
continue;
ERROR("tcpconns plugin: conn_read_netlink: recvmsg(2) failed: %s",
- sstrerror(errno, buf, sizeof(buf)));
+ STRERRNO);
close(fd);
return -1;
} else if (status == 0) {
/* Create socket */
sd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (sd < 0) {
- char errbuf[1024];
- WARNING("teamspeak2 plugin: socket failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("teamspeak2 plugin: socket failed: %s", STRERRNO);
continue;
}
/* Try to connect */
status = connect(sd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- WARNING("teamspeak2 plugin: connect failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("teamspeak2 plugin: connect failed: %s", STRERRNO);
close(sd);
sd = -1;
continue;
/* Create file objects from sockets */
global_read_fh = fdopen(sd, "r");
if (global_read_fh == NULL) {
- char errbuf[1024];
- ERROR("teamspeak2 plugin: fdopen failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("teamspeak2 plugin: fdopen failed: %s", STRERRNO);
close(sd);
return -1;
}
global_write_fh = fdopen(sd, "w");
if (global_write_fh == NULL) {
- char errbuf[1024];
- ERROR("teamspeak2 plugin: fdopen failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("teamspeak2 plugin: fdopen failed: %s", STRERRNO);
tss2_close_socket();
return -1;
}
*/
temp = fgets(buffer, buffer_size, fh);
if (temp == NULL) {
- char errbuf[1024];
- ERROR("teamspeak2 plugin: fgets failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("teamspeak2 plugin: fgets failed: %s", STRERRNO);
tss2_close_socket();
return -1;
}
/* Some signal or something. Start over.. */
continue;
} else if (status < 0) {
- char errbuf[1024];
- ERROR("ted plugin: select failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ted plugin: select failed: %s", STRERRNO);
return -1;
}
receive_buffer_length = read(fd, receive_buffer, sizeof(receive_buffer));
if (receive_buffer_length < 0) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EINTR))
continue;
- ERROR("ted plugin: read(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("ted plugin: read(2) failed: %s", STRERRNO);
return -1;
} else if (receive_buffer_length == 0) {
/* Should we close the FD in this case? */
sock_fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (sock_fd < 0) {
- char errbuf[1024];
- ERROR("unixsock plugin: socket failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: socket failed: %s", STRERRNO);
return -1;
}
errno = 0;
status = unlink(sa.sun_path);
if ((status != 0) && (errno != ENOENT)) {
- char errbuf[1024];
WARNING("unixsock plugin: Deleting socket file \"%s\" failed: %s",
- sa.sun_path, sstrerror(errno, errbuf, sizeof(errbuf)));
+ sa.sun_path, STRERRNO);
} else if (status == 0) {
INFO("unixsock plugin: Successfully deleted socket file \"%s\".",
sa.sun_path);
status = bind(sock_fd, (struct sockaddr *)&sa, sizeof(sa));
if (status != 0) {
- char errbuf[1024];
- sstrerror(errno, errbuf, sizeof(errbuf));
- ERROR("unixsock plugin: bind failed: %s", errbuf);
+ ERROR("unixsock plugin: bind failed: %s", STRERRNO);
close(sock_fd);
sock_fd = -1;
return -1;
status = chmod(sa.sun_path, sock_perms);
if (status == -1) {
- char errbuf[1024];
- ERROR("unixsock plugin: chmod failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: chmod failed: %s", STRERRNO);
close(sock_fd);
sock_fd = -1;
return -1;
status = listen(sock_fd, 8);
if (status != 0) {
- char errbuf[1024];
- ERROR("unixsock plugin: listen failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: listen failed: %s", STRERRNO);
close(sock_fd);
sock_fd = -1;
return -1;
status = getgrnam_r(grpname, &sg, grbuf, sizeof(grbuf), &g);
if (status != 0) {
- char errbuf[1024];
WARNING("unixsock plugin: getgrnam_r (%s) failed: %s", grpname,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ STRERROR(status));
break;
}
if (g == NULL) {
if (chown((sock_file != NULL) ? sock_file : US_DEFAULT_PATH, (uid_t)-1,
g->gr_gid) != 0) {
- char errbuf[1024];
WARNING("unixsock plugin: chown (%s, -1, %i) failed: %s",
(sock_file != NULL) ? sock_file : US_DEFAULT_PATH, (int)g->gr_gid,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
}
} while (0);
fdout = dup(fdin);
if (fdout < 0) {
- char errbuf[1024];
- ERROR("unixsock plugin: dup failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: dup failed: %s", STRERRNO);
close(fdin);
pthread_exit((void *)1);
}
fhin = fdopen(fdin, "r");
if (fhin == NULL) {
- char errbuf[1024];
- ERROR("unixsock plugin: fdopen failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: fdopen failed: %s", STRERRNO);
close(fdin);
close(fdout);
pthread_exit((void *)1);
fhout = fdopen(fdout, "w");
if (fhout == NULL) {
- char errbuf[1024];
- ERROR("unixsock plugin: fdopen failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: fdopen failed: %s", STRERRNO);
fclose(fhin); /* this closes fdin as well */
close(fdout);
pthread_exit((void *)1);
/* change output buffer to line buffered mode */
if (setvbuf(fhout, NULL, _IOLBF, 0) != 0) {
- char errbuf[1024];
- ERROR("unixsock plugin: setvbuf failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: setvbuf failed: %s", STRERRNO);
fclose(fhin);
fclose(fhout);
pthread_exit((void *)1);
continue;
if (errno != 0) {
- char errbuf[1024];
WARNING("unixsock plugin: failed to read from socket #%i: %s",
- fileno(fhin), sstrerror(errno, errbuf, sizeof(errbuf)));
+ fileno(fhin), STRERRNO);
}
break;
}
cmd_handle_flush(fhout, buffer);
} else {
if (fprintf(fhout, "-1 Unknown command: %s\n", fields[0]) < 0) {
- char errbuf[1024];
WARNING("unixsock plugin: failed to write to socket #%i: %s",
- fileno(fhout), sstrerror(errno, errbuf, sizeof(errbuf)));
+ fileno(fhout), STRERRNO);
break;
}
}
DEBUG("unixsock plugin: Calling accept..");
status = accept(sock_fd, NULL, NULL);
if (status < 0) {
- char errbuf[1024];
if (errno == EINTR)
continue;
- ERROR("unixsock plugin: accept failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: accept failed: %s", STRERRNO);
close(sock_fd);
sock_fd = -1;
pthread_attr_destroy(&th_attr);
remote_fd = malloc(sizeof(*remote_fd));
if (remote_fd == NULL) {
- char errbuf[1024];
- WARNING("unixsock plugin: malloc failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("unixsock plugin: malloc failed: %s", STRERRNO);
close(status);
continue;
}
status = plugin_thread_create(&th, &th_attr, us_handle_client,
(void *)remote_fd, "unixsock conn");
if (status != 0) {
- char errbuf[1024];
- WARNING("unixsock plugin: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("unixsock plugin: pthread_create failed: %s", STRERRNO);
close(*remote_fd);
free(remote_fd);
continue;
status = unlink((sock_file != NULL) ? sock_file : US_DEFAULT_PATH);
if (status != 0) {
- char errbuf[1024];
NOTICE("unixsock plugin: unlink (%s) failed: %s",
- (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, STRERRNO);
}
return (void *)0;
status = plugin_thread_create(&listen_thread, NULL, us_server_thread, NULL,
"unixsock listen");
if (status != 0) {
- char errbuf[1024];
- ERROR("unixsock plugin: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("unixsock plugin: pthread_create failed: %s", STRERRNO);
return -1;
}
status = sysinfo(&info);
if (status != 0) {
- char errbuf[1024];
- ERROR("uptime plugin: Error calling sysinfo: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("uptime plugin: Error calling sysinfo: %s", STRERRNO);
return -1;
}
status = sysctl(mib, STATIC_ARRAY_SIZE(mib), &boottv, &boottv_len,
/* new_value = */ NULL, /* new_length = */ 0);
if (status != 0) {
- char errbuf[1024];
- ERROR("uptime plugin: No value read from sysctl interface: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("uptime plugin: No value read from sysctl interface: %s", STRERRNO);
return -1;
}
status = perfstat_cpu_total(NULL, &cputotal, sizeof(perfstat_cpu_total_t), 1);
if (status < 0) {
- char errbuf[1024];
- ERROR("uptime plugin: perfstat_cpu_total: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("uptime plugin: perfstat_cpu_total: %s", STRERRNO);
return -1;
}
#define print_to_socket(fh, ...) \
if (fprintf(fh, __VA_ARGS__) < 0) { \
- char errbuf[1024]; \
WARNING("handle_getthreshold: failed to write to socket #%i: %s", \
- fileno(fh), sstrerror(errno, errbuf, sizeof(errbuf))); \
+ fileno(fh), STRERRNO); \
return -1; \
}
#define print_to_socket(fh, ...) \
do { \
if (fprintf(fh, __VA_ARGS__) < 0) { \
- char errbuf[1024]; \
WARNING("cmd_handle_getval: failed to write to socket #%i: %s", \
- fileno(fh), sstrerror(errno, errbuf, sizeof(errbuf))); \
+ fileno(fh), STRERRNO); \
return -1; \
} \
fflush(fh); \
#define print_to_socket(fh, ...) \
do { \
if (fprintf(fh, __VA_ARGS__) < 0) { \
- char errbuf[1024]; \
WARNING("handle_listval: failed to write to socket #%i: %s", fileno(fh), \
- sstrerror(errno, errbuf, sizeof(errbuf))); \
+ STRERRNO); \
free_everything_and_return(CMD_ERROR); \
} \
fflush(fh); \
#define print_to_socket(fh, ...) \
do { \
if (fprintf(fh, __VA_ARGS__) < 0) { \
- char errbuf[1024]; \
WARNING("handle_putnotif: failed to write to socket #%i: %s", \
- fileno(fh), sstrerror(errno, errbuf, sizeof(errbuf))); \
+ fileno(fh), STRERRNO); \
return -1; \
} \
fflush(fh); \
* Sebastian 'tokkee' Harl <sh at tokkee.org>
**/
-#include "utils_cmds.h"
#include "daemon/common.h"
#include "utils_cmd_flush.h"
#include "utils_cmd_getval.h"
#include "utils_cmd_listval.h"
#include "utils_cmd_putval.h"
+#include "utils_cmds.h"
#include "utils_parse_option.h"
#include <stdbool.h>
vsnprintf(buf, sizeof(buf), format, ap);
buf[sizeof(buf) - 1] = '\0';
if (fprintf(fh, "%i %s\n", code, buf) < 0) {
- char errbuf[1024];
WARNING("utils_cmds: failed to write to file-handle #%i: %s", fileno(fh),
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return;
}
static int dpdk_shm_init(const char *name, size_t size, void **map) {
DPDK_HELPER_TRACE(name);
- char errbuf[ERR_BUF_SIZE];
-
int fd = shm_open(name, O_CREAT | O_TRUNC | O_RDWR, 0666);
if (fd < 0) {
- WARNING("dpdk_shm_init: Failed to open %s as SHM:%s", name,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("dpdk_shm_init: Failed to open %s as SHM:%s", name, STRERRNO);
*map = NULL;
return -1;
}
int ret = ftruncate(fd, size);
if (ret != 0) {
- WARNING("dpdk_shm_init: Failed to resize SHM:%s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("dpdk_shm_init: Failed to resize SHM:%s", STRERRNO);
close(fd);
*map = NULL;
dpdk_shm_cleanup(name, size, NULL);
*map = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (*map == MAP_FAILED) {
- WARNING("dpdk_shm_init:Failed to mmap SHM:%s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("dpdk_shm_init:Failed to mmap SHM:%s", STRERRNO);
close(fd);
*map = NULL;
dpdk_shm_cleanup(name, size, NULL);
static void dpdk_shm_cleanup(const char *name, size_t size, void *map) {
DPDK_HELPER_TRACE(name);
- char errbuf[ERR_BUF_SIZE];
/*
* Call shm_unlink first, as 'name' might be no longer accessible after munmap
*/
if (shm_unlink(name))
- ERROR("shm_unlink failure %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("shm_unlink failure %s", STRERRNO);
if (map != NULL) {
if (munmap(map, size))
- ERROR("munmap failure %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("munmap failure %s", STRERRNO);
}
}
dpdk_helper_ctx_t **pphc) {
dpdk_helper_ctx_t *phc = NULL;
size_t shm_size = sizeof(dpdk_helper_ctx_t) + data_size;
- char errbuf[ERR_BUF_SIZE];
if (pphc == NULL) {
ERROR("%s:Invalid argument(pphc)", __FUNCTION__);
err = sem_init(&phc->sema_cmd_start, 1, 0);
if (err != 0) {
- ERROR("sema_cmd_start semaphore init failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("sema_cmd_start semaphore init failed: %s", STRERRNO);
int errno_m = errno;
dpdk_shm_cleanup(name, shm_size, (void *)phc);
return -errno_m;
err = sem_init(&phc->sema_cmd_complete, 1, 0);
if (err != 0) {
- ERROR("sema_cmd_complete semaphore init failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("sema_cmd_complete semaphore init failed: %s", STRERRNO);
sem_destroy(&phc->sema_cmd_start);
int errno_m = errno;
dpdk_shm_cleanup(name, shm_size, (void *)phc);
}
static int dpdk_helper_spawn(dpdk_helper_ctx_t *phc) {
- char errbuf[ERR_BUF_SIZE];
if (phc == NULL) {
ERROR("Invalid argument(phc)");
return -EINVAL;
}
if (pipe(phc->pipes) != 0) {
- DEBUG("dpdk_helper_spawn: Could not create helper pipe: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ DEBUG("dpdk_helper_spawn: Could not create helper pipe: %s", STRERRNO);
return -1;
}
int pipe0_flags = fcntl(phc->pipes[0], F_GETFL, 0);
int pipe1_flags = fcntl(phc->pipes[1], F_GETFL, 0);
if (pipe0_flags == -1 || pipe1_flags == -1) {
- WARNING("dpdk_helper_spawn: error setting up pipe flags: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("dpdk_helper_spawn: error setting up pipe flags: %s", STRERRNO);
}
int pipe0_err = fcntl(phc->pipes[0], F_SETFL, pipe1_flags | O_NONBLOCK);
int pipe1_err = fcntl(phc->pipes[1], F_SETFL, pipe0_flags | O_NONBLOCK);
if (pipe0_err == -1 || pipe1_err == -1) {
- WARNING("dpdk_helper_spawn: error setting up pipes: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("dpdk_helper_spawn: error setting up pipes: %s", STRERRNO);
}
pid_t pid = fork();
dpdk_helper_worker(phc);
exit(0);
} else {
- ERROR("dpdk_helper_start: Failed to fork helper process: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("dpdk_helper_start: Failed to fork helper process: %s", STRERRNO);
return -1;
}
static int dpdk_helper_exit_command(dpdk_helper_ctx_t *phc,
enum DPDK_HELPER_STATUS status) {
- char errbuf[ERR_BUF_SIZE];
DPDK_HELPER_TRACE(phc->shm_name);
close(phc->pipes[1]);
int err = kill(phc->pid, SIGKILL);
if (err) {
- ERROR("%s error sending kill to helper: %s", __FUNCTION__,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("%s error sending kill to helper: %s", __FUNCTION__, STRERRNO);
}
}
} else {
int err = kill(phc->pid, SIGKILL);
if (err) {
- ERROR("%s error sending kill to helper: %s", __FUNCTION__,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("%s error sending kill to helper: %s", __FUNCTION__, STRERRNO);
}
}
DPDK_CHILD_LOG("%s:%s:%d post sema_cmd_complete (pid=%lu)\n", phc->shm_name,
__FUNCTION__, __LINE__, (long)getpid());
if (err) {
- char errbuf[ERR_BUF_SIZE];
DPDK_CHILD_LOG("dpdk_helper_worker: error posting sema_cmd_complete "
"semaphore (%s)\n",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
}
#if COLLECT_DEBUG
static int dpdk_helper_status_check(dpdk_helper_ctx_t *phc) {
DEBUG("%s:%s:%d pid=%u %s", phc->shm_name, __FUNCTION__, __LINE__, getpid(),
dpdk_helper_status_str(phc->status));
- char errbuf[ERR_BUF_SIZE];
if (phc->status == DPDK_HELPER_GRACEFUL_QUIT) {
return 0;
__LINE__);
int err = dpdk_helper_spawn(phc);
if (err) {
- ERROR("dpdkstat: error spawning helper %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("dpdkstat: error spawning helper %s", STRERRNO);
}
return -1;
}
__LINE__);
int err = dpdk_helper_spawn(phc);
if (err) {
- ERROR("dpdkstat: error spawning helper %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("dpdkstat: error spawning helper %s", STRERRNO);
}
return -1;
}
data_avail);
if (data_avail < 0) {
if (errno != EINTR || errno != EAGAIN) {
- char errbuf[ERR_BUF_SIZE];
- ERROR("%s: poll(2) failed: %s", phc->shm_name,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("%s: poll(2) failed: %s", phc->shm_name, STRERRNO);
}
}
while (data_avail) {
/* kick helper to process command */
int err = sem_post(&phc->sema_cmd_start);
if (err) {
- char errbuf[ERR_BUF_SIZE];
ERROR("dpdk_helper_worker: error posting sema_cmd_start semaphore (%s)",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
}
#if COLLECT_DEBUG
} \
} while (0)
+#define CHECK_SUCCESS(cmd) \
+ do { \
+ yajl_gen_status s = (cmd); \
+ if (s != yajl_gen_status_ok) { \
+ return (int)s; \
+ } \
+ } while (0)
+
static int format_json_meta(yajl_gen g, notification_meta_t *meta) /* {{{ */
{
if (meta == NULL)
default:
ERROR("format_json_meta: unknown meta data type %d (name \"%s\")",
meta->type, meta->name);
- yajl_gen_null(g);
+ CHECK_SUCCESS(yajl_gen_null(g));
}
return format_json_meta(g, meta->next);
static int format_alert(yajl_gen g, notification_t const *n) /* {{{ */
{
- yajl_gen_array_open(g);
- yajl_gen_map_open(g); /* BEGIN alert */
+ CHECK_SUCCESS(yajl_gen_array_open(g)); /* BEGIN array */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN alert */
/*
* labels
*/
JSON_ADD(g, "labels");
- yajl_gen_map_open(g); /* BEGIN labels */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN labels */
JSON_ADD(g, "alertname");
if (strncmp(n->plugin, n->type, strlen(n->plugin)) == 0)
JSON_ADD(g, "service");
JSON_ADD(g, "collectd");
- yajl_gen_map_close(g); /* END labels */
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END labels */
/*
* annotations
*/
JSON_ADD(g, "annotations");
- yajl_gen_map_open(g); /* BEGIN annotations */
+ CHECK_SUCCESS(yajl_gen_map_open(g)); /* BEGIN annotations */
JSON_ADD(g, "summary");
JSON_ADD(g, n->message);
- if (format_json_meta(g, n->meta) != 0)
+ if (format_json_meta(g, n->meta) != 0) {
return -1;
+ }
- yajl_gen_map_close(g); /* END annotations */
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END annotations */
JSON_ADD(g, "startsAt");
- format_time(g, n->time);
+ if (format_time(g, n->time) != 0) {
+ return -1;
+ }
- yajl_gen_map_close(g); /* END alert */
- yajl_gen_array_close(g);
+ CHECK_SUCCESS(yajl_gen_map_close(g)); /* END alert */
+ CHECK_SUCCESS(yajl_gen_array_close(g)); /* END array */
return 0;
} /* }}} format_alert */
}
/* copy to output buffer */
- yajl_gen_get_buf(g, &out, &unused_out_len);
+ if (yajl_gen_get_buf(g, &out, &unused_out_len) != yajl_gen_status_ok) {
+ yajl_gen_clear(g);
+ yajl_gen_free(g);
+ return -1;
+ }
sstrncpy(buffer, (void *)out, buffer_size);
yajl_gen_clear(g);
struct tabmntent *mntlist;
if (listmntent(&mntlist, COLLECTD_MNTTAB, NULL, NULL) < 0) {
#if COLLECT_DEBUG
- char errbuf[1024];
- DEBUG("utils_mount: calling listmntent() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ DEBUG("utils_mount: calling listmntent() failed: %s", STRERRNO);
#endif /* COLLECT_DEBUG */
}
/* Get the number of mounted file systems */
if ((bufsize = CMD_STATFS(NULL, 0, FLAGS_STATFS)) < 1) {
#if COLLECT_DEBUG
- char errbuf[1024];
- DEBUG("utils_mount: getv?fsstat failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ DEBUG("utils_mount: getv?fsstat failed: %s", STRERRNO);
#endif /* COLLECT_DEBUG */
return NULL;
}
if ((num = CMD_STATFS(buf, bufsize * sizeof(STRUCT_STATFS), FLAGS_STATFS)) <
1) {
#if COLLECT_DEBUG
- char errbuf[1024];
- DEBUG("utils_mount: getv?fsstat failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ DEBUG("utils_mount: getv?fsstat failed: %s", STRERRNO);
#endif /* COLLECT_DEBUG */
free(buf);
return NULL;
DEBUG("utils_mount: (void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
if ((fp = fopen(COLLECTD_MNTTAB, "r")) == NULL) {
- char errbuf[1024];
- ERROR("fopen (%s): %s", COLLECTD_MNTTAB,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("fopen (%s): %s", COLLECTD_MNTTAB, STRERRNO);
return NULL;
}
return first;
} /* static cu_mount_t *cu_mount_gen_getmntent (void) */
- /* #endif HAVE_TWO_GETMNTENT || HAVE_GEN_GETMNTENT || HAVE_SUN_GETMNTENT */
#elif HAVE_SEQ_GETMNTENT
#warn "This version of `getmntent' hat not yet been implemented!"
DEBUG("utils_mount: (void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
if ((fp = setmntent(COLLECTD_MNTTAB, "r")) == NULL) {
- char errbuf[1024];
- ERROR("setmntent (%s): %s", COLLECTD_MNTTAB,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("setmntent (%s): %s", COLLECTD_MNTTAB, STRERRNO);
return NULL;
}
DEBUG("utils_mount: (void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
if ((fp = setmntent(COLLECTD_MNTTAB, "r")) == NULL) {
- char errbuf[1024];
- ERROR("setmntent (%s): %s", COLLECTD_MNTTAB,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("setmntent (%s): %s", COLLECTD_MNTTAB, STRERRNO);
return NULL;
}
#define OVS_DB_POLL_READ_BLOCK_SIZE 512 /* read block size (bytes) */
#define OVS_DB_DEFAULT_DB_NAME "Open_vSwitch"
+#define OVS_DB_EVENT_NONE 0
#define OVS_DB_EVENT_TIMEOUT 5 /* event thread timeout (sec) */
#define OVS_DB_EVENT_TERMINATE 1
#define OVS_DB_EVENT_CONN_ESTABLISHED 2
/* Remove all callbacks form OVS DB object */
static void ovs_db_callback_remove_all(ovs_db_t *pdb) {
pthread_mutex_lock(&pdb->mutex);
- for (ovs_callback_t *del_cb = pdb->remote_cb; pdb->remote_cb;
- del_cb = pdb->remote_cb) {
+ while (pdb->remote_cb != NULL) {
+ ovs_callback_t *del_cb = pdb->remote_cb;
pdb->remote_cb = del_cb->next;
- free(del_cb);
+ sfree(del_cb);
}
- pdb->remote_cb = NULL;
pthread_mutex_unlock(&pdb->mutex);
}
}
/* try to connect to the server */
for (struct addrinfo *rp = result; rp != NULL; rp = rp->ai_next) {
- char errbuff[OVS_ERROR_BUFF_SIZE];
int sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sock < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_DEBUG("socket(): %s", errbuff);
+ OVS_DEBUG("socket(): %s", STRERRNO);
continue;
}
if (connect(sock, rp->ai_addr, rp->ai_addrlen) < 0) {
close(sock);
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_DEBUG("connect(): %s [family=%d]", errbuff, rp->ai_family);
+ OVS_DEBUG("connect(): %s [family=%d]", STRERRNO, rp->ai_family);
} else {
/* send notification to event thread */
- ovs_db_event_post(pdb, OVS_DB_EVENT_CONN_ESTABLISHED);
pdb->sock = sock;
+ ovs_db_event_post(pdb, OVS_DB_EVENT_CONN_ESTABLISHED);
break;
}
}
/* poll data */
while (ovs_db_poll_is_running(pdb)) {
- char errbuff[OVS_ERROR_BUFF_SIZE];
poll_fd.fd = pdb->sock;
int poll_ret = poll(&poll_fd, 1, /* ms */ OVS_DB_POLL_TIMEOUT * 1000);
if (poll_ret < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_ERROR("poll(): %s", errbuff);
+ OVS_ERROR("poll(): %s", STRERRNO);
break;
} else if (poll_ret == 0) {
OVS_DEBUG("poll(): timeout");
char buff[OVS_DB_POLL_READ_BLOCK_SIZE];
ssize_t nbytes = recv(poll_fd.fd, buff, sizeof(buff), 0);
if (nbytes < 0) {
- sstrerror(errno, errbuff, sizeof(errbuff));
- OVS_ERROR("recv(): %s", errbuff);
+ OVS_ERROR("recv(): %s", STRERRNO);
/* read error? Try to reconnect */
close(poll_fd.fd);
continue;
ts.tv_sec += (OVS_DB_EVENT_TIMEOUT);
int ret = pthread_cond_timedwait(&pdb->event_thread.cond,
&pdb->event_thread.mutex, &ts);
- if (!ret) {
+ if (!ret || ret == ETIMEDOUT) {
/* handle the event */
OVS_DEBUG("handle event %d", pdb->event_thread.value);
switch (pdb->event_thread.value) {
case OVS_DB_EVENT_CONN_ESTABLISHED:
if (pdb->cb.post_conn_init)
pdb->cb.post_conn_init(pdb);
+ /* reset event */
+ pdb->event_thread.value = OVS_DB_EVENT_NONE;
break;
case OVS_DB_EVENT_CONN_TERMINATED:
if (pdb->cb.post_conn_terminate)
pdb->cb.post_conn_terminate();
+ /* reset event */
+ pdb->event_thread.value = OVS_DB_EVENT_NONE;
+ break;
+ case OVS_DB_EVENT_NONE:
+ /* wait timeout */
+ OVS_DEBUG("no event received (timeout)");
break;
default:
OVS_DEBUG("unknown event received");
break;
}
- } else if (ret == ETIMEDOUT) {
- /* wait timeout */
- OVS_DEBUG("no event received (timeout)");
- continue;
} else {
/* unexpected error */
OVS_ERROR("pthread_cond_timedwait() failed");
/* Initialize EVENT thread */
static int ovs_db_event_thread_init(ovs_db_t *pdb) {
- pdb->event_thread.tid = (pthread_t)-1;
+ pdb->event_thread.tid = (pthread_t){0};
/* init event thread condition variable */
if (pthread_cond_init(&pdb->event_thread.cond, NULL)) {
return -1;
return 0;
}
-/* Destroy EVENT thread */
-static int ovs_db_event_thread_destroy(ovs_db_t *pdb) {
- if (pdb->event_thread.tid == (pthread_t)-1)
- /* already destroyed */
+/* Terminate EVENT thread */
+static int ovs_db_event_thread_terminate(ovs_db_t *pdb) {
+ if (pthread_equal(pdb->event_thread.tid, (pthread_t){0})) {
+ /* already terminated */
return 0;
+ }
ovs_db_event_post(pdb, OVS_DB_EVENT_TERMINATE);
if (pthread_join(pdb->event_thread.tid, NULL) != 0)
return -1;
* performs some task (handles event) and releases it when
* while sleeping. Thus, if event thread exits, the mutex
* remains locked */
+ pdb->event_thread.tid = (pthread_t){0};
pthread_mutex_unlock(&pdb->event_thread.mutex);
+ return 0;
+}
+
+/* Destroy EVENT thread private data */
+static void ovs_db_event_thread_data_destroy(ovs_db_t *pdb) {
+ /* destroy mutex */
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
- pdb->event_thread.tid = (pthread_t)-1;
- return 0;
}
/* Initialize POLL thread */
static int ovs_db_poll_thread_init(ovs_db_t *pdb) {
- pdb->poll_thread.tid = (pthread_t)-1;
+ pdb->poll_thread.tid = (pthread_t){0};
/* init event thread mutex */
if (pthread_mutex_init(&pdb->poll_thread.mutex, NULL)) {
return -1;
}
/* Destroy POLL thread */
+/* XXX: Must hold pdb->mutex when calling! */
static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
- if (pdb->poll_thread.tid == (pthread_t)-1)
+ if (pthread_equal(pdb->poll_thread.tid, (pthread_t){0})) {
/* already destroyed */
return 0;
+ }
/* change thread state */
pthread_mutex_lock(&pdb->poll_thread.mutex);
pdb->poll_thread.state = OVS_DB_POLL_STATE_EXITING;
if (pthread_join(pdb->poll_thread.tid, NULL) != 0)
return -1;
pthread_mutex_destroy(&pdb->poll_thread.mutex);
- pdb->poll_thread.tid = (pthread_t)-1;
+ pdb->poll_thread.tid = (pthread_t){0};
return 0;
}
return NULL;
/* allocate db data & fill it */
- ovs_db_t *pdb = pdb = calloc(1, sizeof(*pdb));
+ ovs_db_t *pdb = calloc(1, sizeof(*pdb));
if (pdb == NULL)
return NULL;
+ pdb->sock = -1;
/* store the OVS DB address */
sstrncpy(pdb->node, node, sizeof(pdb->node));
}
/* init polling thread */
- pdb->sock = -1;
if (ovs_db_poll_thread_init(pdb) < 0) {
ovs_db_destroy(pdb);
return NULL;
if (pdb == NULL)
return -1;
+ /* stop event thread */
+ if (ovs_db_event_thread_terminate(pdb) < 0) {
+ OVS_ERROR("stop event thread failed");
+ ovs_db_ret = -1;
+ }
+
/* try to lock the structure before releasing */
if ((ret = pthread_mutex_lock(&pdb->mutex))) {
OVS_ERROR("pthread_mutex_lock() DB mutex lock failed (%d)", ret);
return -1;
}
- /* stop poll thread */
- if (ovs_db_event_thread_destroy(pdb) < 0) {
+ /* stop poll thread and destroy thread's private data */
+ if (ovs_db_poll_thread_destroy(pdb) < 0) {
OVS_ERROR("destroy poll thread failed");
- ovs_db_ret = (-1);
+ ovs_db_ret = -1;
}
- /* stop event thread */
- if (ovs_db_poll_thread_destroy(pdb) < 0) {
- OVS_ERROR("stop event thread failed");
- ovs_db_ret = (-1);
- }
+ /* destroy event thread private data */
+ ovs_db_event_thread_data_destroy(pdb);
+
+ pthread_mutex_unlock(&pdb->mutex);
/* unsubscribe callbacks */
ovs_db_callback_remove_all(pdb);
close(pdb->sock);
/* release DB handler */
- pthread_mutex_unlock(&pdb->mutex);
pthread_mutex_destroy(&pdb->mutex);
sfree(pdb);
return ovs_db_ret;
ds_def = calloc(ds->ds_num, sizeof(*ds_def));
if (ds_def == NULL) {
- char errbuf[1024];
- ERROR("rrdtool plugin: calloc failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("rrdtool plugin: calloc failed: %s", STRERRNO);
return -1;
}
status = rename(tmpfile, args->filename);
if (status != 0) {
- char errbuf[1024];
ERROR("srrd_create_thread: rename (\"%s\", \"%s\") failed: %s", tmpfile,
- args->filename, sstrerror(errno, errbuf, sizeof(errbuf)));
+ args->filename, STRERRNO);
unlink(tmpfile);
unlock_file(args->filename);
srrd_create_args_destroy(args);
status = pthread_create(&thread, &attr, srrd_create_thread, args);
if (status != 0) {
- char errbuf[1024];
- ERROR("srrd_create_async: pthread_create failed: %s",
- sstrerror(status, errbuf, sizeof(errbuf)));
+ ERROR("srrd_create_async: pthread_create failed: %s", STRERROR(status));
pthread_attr_destroy(&attr);
srrd_create_args_destroy(args);
return status;
argc = ds_num + rra_num;
if ((argv = malloc(sizeof(*argv) * (argc + 1))) == NULL) {
- char errbuf[1024];
- ERROR("cu_rrd_create_file failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("cu_rrd_create_file failed: %s", STRERRNO);
rra_free(rra_num, rra_def);
ds_free(ds_num, ds_def);
return -1;
status = stat(obj->file, &stat_buf);
if (status != 0) {
- char errbuf[1024];
- ERROR("utils_tail: stat (%s) failed: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("utils_tail: stat (%s) failed: %s", obj->file, STRERRNO);
return -1;
}
INFO("utils_tail: File `%s' was truncated.", obj->file);
status = fseek(obj->fh, 0, SEEK_SET);
if (status != 0) {
- char errbuf[1024];
- ERROR("utils_tail: fseek (%s) failed: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO);
fclose(obj->fh);
obj->fh = NULL;
return -1;
fh = fopen(obj->file, "r");
if (fh == NULL) {
- char errbuf[1024];
- ERROR("utils_tail: fopen (%s) failed: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("utils_tail: fopen (%s) failed: %s", obj->file, STRERRNO);
return -1;
}
if (seek_end != 0) {
status = fseek(fh, 0, SEEK_END);
if (status != 0) {
- char errbuf[1024];
- ERROR("utils_tail: fseek (%s) failed: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO);
fclose(fh);
return -1;
}
}
if (ferror(obj->fh) != 0) {
- char errbuf[1024];
WARNING("utils_tail: fgets (%s) returned an error: %s", obj->file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
fclose(obj->fh);
obj->fh = NULL;
return -1;
sstrncpy(vl.type, data->type, sizeof(vl.type));
for (size_t i = 0; i < data->latency_config.percentile_num; i++) {
if (strlen(data->type_instance) != 0)
- snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%.0f",
+ snprintf(vl.type_instance, sizeof(vl.type_instance), "%.117s-%.2f",
data->type_instance, data->latency_config.percentile[i]);
else
snprintf(vl.type_instance, sizeof(vl.type_instance), "%.0f",
bucket.upper_bound ? CDTIME_T_TO_DOUBLE(bucket.upper_bound) : INFINITY;
if (strlen(data->type_instance) != 0)
- snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g",
- data->type, data->type_instance, lower_bound, upper_bound);
+ snprintf(vl.type_instance, sizeof(vl.type_instance),
+ "%.54s-%.54s-%.2g_%.2g", data->type, data->type_instance,
+ lower_bound, upper_bound);
else
- snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g",
+ snprintf(vl.type_instance, sizeof(vl.type_instance), "%.107s-%.2g_%.2g",
data->type, lower_bound, upper_bound);
vl.values = &(value_t){
#include "common.h"
#include "plugin.h"
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
#include <vapi/vsc.h>
#include <vapi/vsm.h>
typedef struct VSC_C_main c_varnish_stats_t;
#if HAVE_VARNISH_V2
_Bool collect_sm;
#endif
-#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
_Bool collect_sma;
#endif
_Bool collect_struct;
_Bool collect_totals;
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
_Bool collect_uptime;
#endif
_Bool collect_vcl;
_Bool collect_workers;
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
_Bool collect_vsm;
_Bool collect_lck;
_Bool collect_mempool;
});
} /* }}} int varnish_submit_derive */
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
static int varnish_monitor(void *priv,
const struct VSC_point *const pt) /* {{{ */
{
uint64_t val;
const user_config_t *conf;
- const char *class;
const char *name;
if (pt == NULL)
conf = priv;
-#if HAVE_VARNISH_V4
- class = pt->section->fantom->type;
- name = pt->desc->name;
+#if HAVE_VARNISH_V5
+ char namebuff[DATA_MAX_NAME_LEN];
+
+ char const *c = strrchr(pt->name, '.');
+ if (c == NULL) {
+ return EINVAL;
+ }
+ sstrncpy(namebuff, c + 1, sizeof(namebuff));
+ name = namebuff;
- if (strcmp(class, "MAIN") != 0)
+#elif HAVE_VARNISH_V4
+ if (strcmp(pt->section->fantom->type, "MAIN") != 0)
return 0;
+ name = pt->desc->name;
#elif HAVE_VARNISH_V3
- class = pt->class;
- name = pt->name;
-
- if (strcmp(class, "") != 0)
+ if (strcmp(pt->class, "") != 0)
return 0;
+
+ name = pt->name;
#endif
val = *(const volatile uint64_t *)pt->ptr;
else if (strcmp(name, "client_req") == 0)
return varnish_submit_derive(conf->instance, "connections", "connections",
"received", val);
-#ifdef HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
else if (strcmp(name, "client_req_400") == 0)
return varnish_submit_derive(conf->instance, "connections", "connections",
"error_400", val);
else if (strcmp(name, "fetch_304") == 0)
return varnish_submit_derive(conf->instance, "fetch", "http_requests",
"no_body_304", val);
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
else if (strcmp(name, "fetch_no_thread") == 0)
return varnish_submit_derive(conf->instance, "fetch", "http_requests",
"no_thread", val);
else if (strcmp(name, "n_objoverflow") == 0)
return varnish_submit_derive(conf->instance, "objects", "total_objects",
"workspace_overflow", val);
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
else if (strcmp(name, "exp_mailed") == 0)
return varnish_submit_gauge(conf->instance, "struct", "objects",
"exp_mailed", val);
"duplicate", val);
}
#endif
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
if (conf->collect_ban) {
if (strcmp(name, "bans") == 0)
return varnish_submit_derive(conf->instance, "ban", "total_operations",
else if (strcmp(name, "bans_tests_tested") == 0)
return varnish_submit_derive(conf->instance, "ban", "total_operations",
"tests_tested", val);
-
}
#endif
else if (strcmp(name, "sess_herd") == 0)
return varnish_submit_derive(conf->instance, "session",
"total_operations", "herd", val);
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
else if (strcmp(name, "sess_closed_err") == 0)
return varnish_submit_derive(conf->instance, "session",
"total_operations", "closed_err", val);
else if (strcmp(name, "sess_dropped") == 0)
return varnish_submit_derive(conf->instance, "session",
- "total_operations", "dropped_for_thread", val);
+ "total_operations", "dropped_for_thread",
+ val);
#endif
}
"dropped", val);
else if (strcmp(name, "thread_queue_len") == 0)
return varnish_submit_gauge(conf->instance, "workers", "queue_length",
- "threads", val);
+ "threads", val);
else if (strcmp(name, "n_wrk") == 0)
return varnish_submit_gauge(conf->instance, "workers", "threads",
"worker", val);
else if (strcmp(name, "n_wrk_lqueue") == 0)
return varnish_submit_derive(conf->instance, "workers", "total_requests",
"queue_length", val);
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
else if (strcmp(name, "pools") == 0)
- return varnish_submit_gauge(conf->instance, "workers", "pools",
- "pools", val);
+ return varnish_submit_gauge(conf->instance, "workers", "pools", "pools",
+ val);
else if (strcmp(name, "busy_killed") == 0)
return varnish_submit_derive(conf->instance, "workers", "http_requests",
"busy_killed", val);
#endif
}
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
if (conf->collect_vsm) {
if (strcmp(name, "vsm_free") == 0)
return varnish_submit_gauge(conf->instance, "vsm", "bytes", "free", val);
"bitmap", "happy_hprobes", val);
*/
if (strcmp(name, "bereq_hdrbytes") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "bereq_hdrbytes", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "bereq_hdrbytes", val);
else if (strcmp(name, "bereq_bodybytes") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "bereq_bodybytes", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "bereq_bodybytes", val);
else if (strcmp(name, "bereq_protobytes") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "bereq_protobytes", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "bereq_protobytes", val);
else if (strcmp(name, "beresp_hdrbytes") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "beresp_hdrbytes", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "beresp_hdrbytes", val);
else if (strcmp(name, "beresp_bodybytes") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "beresp_bodybytes", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "beresp_bodybytes", val);
else if (strcmp(name, "beresp_protobytes") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "beresp_protobytes", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "beresp_protobytes", val);
else if (strcmp(name, "pipe_hdrbytes") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "pipe_hdrbytes", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "pipe_hdrbytes", val);
else if (strcmp(name, "pipe_out") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "pipe_out", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "pipe_out", val);
else if (strcmp(name, "pipe_in") == 0)
- return varnish_submit_derive(conf->instance, "vbe",
- "total_bytes", "pipe_in", val);
+ return varnish_submit_derive(conf->instance, "vbe", "total_bytes",
+ "pipe_in", val);
else if (strcmp(name, "conn") == 0)
return varnish_submit_derive(conf->instance, "vbe", "connections",
- "c_conns", val);
+ "c_conns", val);
else if (strcmp(name, "req") == 0)
return varnish_submit_derive(conf->instance, "vbe", "http_requests",
- "b_reqs", val);
+ "b_reqs", val);
}
/* All Stevedores support these counters */
strncpy(category, "mse", 4);
if (strcmp(name, "c_req") == 0)
- return varnish_submit_derive(conf->instance, category,
- "total_operations", "alloc_req", val);
+ return varnish_submit_derive(conf->instance, category, "total_operations",
+ "alloc_req", val);
else if (strcmp(name, "c_fail") == 0)
- return varnish_submit_derive(conf->instance, category,
- "total_operations", "alloc_fail", val);
+ return varnish_submit_derive(conf->instance, category, "total_operations",
+ "alloc_fail", val);
else if (strcmp(name, "c_bytes") == 0)
- return varnish_submit_derive(conf->instance, category,
- "total_bytes", "bytes_allocated", val);
+ return varnish_submit_derive(conf->instance, category, "total_bytes",
+ "bytes_allocated", val);
else if (strcmp(name, "c_freed") == 0)
- return varnish_submit_derive(conf->instance, category,
- "total_bytes", "bytes_freed", val);
+ return varnish_submit_derive(conf->instance, category, "total_bytes",
+ "bytes_freed", val);
else if (strcmp(name, "g_alloc") == 0)
- return varnish_submit_derive(conf->instance, category,
- "total_operations", "alloc_outstanding", val);
+ return varnish_submit_derive(conf->instance, category, "total_operations",
+ "alloc_outstanding", val);
else if (strcmp(name, "g_bytes") == 0)
return varnish_submit_gauge(conf->instance, category, "bytes",
"bytes_outstanding", val);
if (conf->collect_smf) {
if (strcmp(name, "g_smf") == 0)
- return varnish_submit_gauge(conf->instance, "smf", "objects",
- "n_struct_smf", val);
- else if (strcmp(name, "g_smf_frag") == 0)
- return varnish_submit_gauge(conf->instance, "smf", "objects",
- "n_small_free_smf", val);
- else if (strcmp(name, "g_smf_large") == 0)
- return varnish_submit_gauge(conf->instance, "smf", "objects",
- "n_large_free_smf", val);
+ return varnish_submit_gauge(conf->instance, "smf", "objects",
+ "n_struct_smf", val);
+ else if (strcmp(name, "g_smf_frag") == 0)
+ return varnish_submit_gauge(conf->instance, "smf", "objects",
+ "n_small_free_smf", val);
+ else if (strcmp(name, "g_smf_large") == 0)
+ return varnish_submit_gauge(conf->instance, "smf", "objects",
+ "n_large_free_smf", val);
}
if (conf->collect_mgt) {
return varnish_submit_gauge(conf->instance, "mgt", "uptime",
"mgt_proc_uptime", val);
else if (strcmp(name, "child_start") == 0)
- return varnish_submit_derive(conf->instance, "mgt",
- "total_operations", "child_start", val);
+ return varnish_submit_derive(conf->instance, "mgt", "total_operations",
+ "child_start", val);
else if (strcmp(name, "child_exit") == 0)
- return varnish_submit_derive(conf->instance, "mgt",
- "total_operations", "child_exit", val);
+ return varnish_submit_derive(conf->instance, "mgt", "total_operations",
+ "child_exit", val);
else if (strcmp(name, "child_stop") == 0)
- return varnish_submit_derive(conf->instance, "mgt",
- "total_operations", "child_stop", val);
+ return varnish_submit_derive(conf->instance, "mgt", "total_operations",
+ "child_stop", val);
else if (strcmp(name, "child_died") == 0)
- return varnish_submit_derive(conf->instance, "mgt",
- "total_operations", "child_died", val);
+ return varnish_submit_derive(conf->instance, "mgt", "total_operations",
+ "child_died", val);
else if (strcmp(name, "child_dump") == 0)
- return varnish_submit_derive(conf->instance, "mgt",
- "total_operations", "child_dump", val);
+ return varnish_submit_derive(conf->instance, "mgt", "total_operations",
+ "child_dump", val);
else if (strcmp(name, "child_panic") == 0)
- return varnish_submit_derive(conf->instance, "mgt",
- "total_operations", "child_panic", val);
+ return varnish_submit_derive(conf->instance, "mgt", "total_operations",
+ "child_panic", val);
}
if (conf->collect_lck) {
if (strcmp(name, "creat") == 0)
- return varnish_submit_gauge(conf->instance, "lck", "objects",
- "created", val);
+ return varnish_submit_gauge(conf->instance, "lck", "objects", "created",
+ val);
else if (strcmp(name, "destroy") == 0)
- return varnish_submit_gauge(conf->instance, "lck", "objects",
- "destroyed", val);
+ return varnish_submit_gauge(conf->instance, "lck", "objects", "destroyed",
+ val);
else if (strcmp(name, "locks") == 0)
return varnish_submit_derive(conf->instance, "lck", "total_operations",
- "lock_ops", val);
+ "lock_ops", val);
}
if (conf->collect_mempool) {
return varnish_submit_derive(conf->instance, "mempool",
"total_operations", "frees", val);
else if (strcmp(name, "recycle") == 0)
- return varnish_submit_gauge(conf->instance, "mempool",
- "objects", "recycled", val);
+ return varnish_submit_gauge(conf->instance, "mempool", "objects",
+ "recycled", val);
else if (strcmp(name, "timeout") == 0)
- return varnish_submit_gauge(conf->instance, "mempool",
- "objects", "timed_out", val);
+ return varnish_submit_gauge(conf->instance, "mempool", "objects",
+ "timed_out", val);
else if (strcmp(name, "toosmall") == 0)
- return varnish_submit_gauge(conf->instance, "mempool",
- "objects", "too_small", val);
+ return varnish_submit_gauge(conf->instance, "mempool", "objects",
+ "too_small", val);
else if (strcmp(name, "surplus") == 0)
- return varnish_submit_gauge(conf->instance, "mempool",
- "objects", "surplus", val);
+ return varnish_submit_gauge(conf->instance, "mempool", "objects",
+ "surplus", val);
else if (strcmp(name, "randry") == 0)
- return varnish_submit_gauge(conf->instance, "mempool",
- "objects", "ran_dry", val);
+ return varnish_submit_gauge(conf->instance, "mempool", "objects",
+ "ran_dry", val);
}
if (conf->collect_mse) {
if (strcmp(name, "c_full") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_operations", "full_allocs", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_operations",
+ "full_allocs", val);
else if (strcmp(name, "c_truncated") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_operations", "truncated_allocs", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_operations",
+ "truncated_allocs", val);
else if (strcmp(name, "c_expanded") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_operations", "expanded_allocs", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_operations",
+ "expanded_allocs", val);
else if (strcmp(name, "c_failed") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_operations", "failed_allocs", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_operations",
+ "failed_allocs", val);
else if (strcmp(name, "c_bytes") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_bytes", "bytes_allocated", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_bytes",
+ "bytes_allocated", val);
else if (strcmp(name, "c_freed") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_bytes", "bytes_freed", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_bytes",
+ "bytes_freed", val);
else if (strcmp(name, "g_fo_alloc") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_operations", "fo_allocs_outstanding", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_operations",
+ "fo_allocs_outstanding", val);
else if (strcmp(name, "g_fo_bytes") == 0)
- return varnish_submit_gauge(conf->instance, "mse",
- "bytes", "fo_bytes_outstanding", val);
+ return varnish_submit_gauge(conf->instance, "mse", "bytes",
+ "fo_bytes_outstanding", val);
else if (strcmp(name, "g_membuf_alloc") == 0)
- return varnish_submit_gauge(conf->instance, "mse",
- "objects", "membufs_allocated", val);
+ return varnish_submit_gauge(conf->instance, "mse", "objects",
+ "membufs_allocated", val);
else if (strcmp(name, "g_membuf_inuse") == 0)
- return varnish_submit_gauge(conf->instance, "mse",
- "objects", "membufs_inuse", val);
+ return varnish_submit_gauge(conf->instance, "mse", "objects",
+ "membufs_inuse", val);
else if (strcmp(name, "g_bans_bytes") == 0)
- return varnish_submit_gauge(conf->instance, "mse",
- "bytes", "persisted_banspace_used", val);
+ return varnish_submit_gauge(conf->instance, "mse", "bytes",
+ "persisted_banspace_used", val);
else if (strcmp(name, "g_bans_space") == 0)
- return varnish_submit_gauge(conf->instance, "mse",
- "bytes", "persisted_banspace_available", val);
+ return varnish_submit_gauge(conf->instance, "mse", "bytes",
+ "persisted_banspace_available", val);
else if (strcmp(name, "g_bans_persisted") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_operations", "bans_persisted", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_operations",
+ "bans_persisted", val);
else if (strcmp(name, "g_bans_lost") == 0)
- return varnish_submit_derive(conf->instance, "mse",
- "total_operations", "bans_lost", val);
+ return varnish_submit_derive(conf->instance, "mse", "total_operations",
+ "bans_lost", val);
- /* mse seg */
+ /* mse seg */
else if (strcmp(name, "g_journal_bytes") == 0)
- return varnish_submit_gauge(conf->instance, "mse_reg",
- "bytes", "journal_bytes_used", val);
+ return varnish_submit_gauge(conf->instance, "mse_reg", "bytes",
+ "journal_bytes_used", val);
else if (strcmp(name, "g_journal_space") == 0)
- return varnish_submit_gauge(conf->instance, "mse_reg",
- "bytes", "journal_bytes_free", val);
+ return varnish_submit_gauge(conf->instance, "mse_reg", "bytes",
+ "journal_bytes_free", val);
/* mse segagg */
else if (strcmp(name, "g_bigspace") == 0)
- return varnish_submit_gauge(conf->instance, "mse_segagg",
- "bytes", "big_extents_bytes_available", val);
+ return varnish_submit_gauge(conf->instance, "mse_segagg", "bytes",
+ "big_extents_bytes_available", val);
else if (strcmp(name, "g_extfree") == 0)
- return varnish_submit_gauge(conf->instance, "mse_segagg",
- "objects", "free_extents", val);
+ return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
+ "free_extents", val);
else if (strcmp(name, "g_sparenode") == 0)
- return varnish_submit_gauge(conf->instance, "mse_segagg",
- "objects", "spare_nodes_available", val);
+ return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
+ "spare_nodes_available", val);
else if (strcmp(name, "g_objnode") == 0)
- return varnish_submit_gauge(conf->instance, "mse_segagg",
- "objects", "object_nodes_in_use", val);
+ return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
+ "object_nodes_in_use", val);
else if (strcmp(name, "g_extnode") == 0)
- return varnish_submit_gauge(conf->instance, "mse_segagg",
- "objects", "extent_nodes_in_use", val);
+ return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
+ "extent_nodes_in_use", val);
else if (strcmp(name, "g_bigextfree") == 0)
- return varnish_submit_gauge(conf->instance, "mse_segagg",
- "objects", "free_big_extents", val);
+ return varnish_submit_gauge(conf->instance, "mse_segagg", "objects",
+ "free_big_extents", val);
else if (strcmp(name, "c_pruneloop") == 0)
return varnish_submit_derive(conf->instance, "mse_segagg",
- "total_operations", "prune_loops", val);
+ "total_operations", "prune_loops", val);
else if (strcmp(name, "c_pruned") == 0)
return varnish_submit_derive(conf->instance, "mse_segagg",
- "total_objects", "pruned_objects", val);
+ "total_objects", "pruned_objects", val);
else if (strcmp(name, "c_spared") == 0)
return varnish_submit_derive(conf->instance, "mse_segagg",
- "total_operations", "spared_objects", val);
+ "total_operations", "spared_objects", val);
else if (strcmp(name, "c_skipped") == 0)
return varnish_submit_derive(conf->instance, "mse_segagg",
- "total_operations", "missed_objects", val);
+ "total_operations", "missed_objects", val);
else if (strcmp(name, "c_nuked") == 0)
return varnish_submit_derive(conf->instance, "mse_segagg",
- "total_operations", "nuked_objects", val);
+ "total_operations", "nuked_objects", val);
else if (strcmp(name, "c_sniped") == 0)
return varnish_submit_derive(conf->instance, "mse_segagg",
- "total_operations", "sniped_objects", val);
-
+ "total_operations", "sniped_objects", val);
}
#endif
} /* }}} void varnish_monitor */
#endif
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
static int varnish_read(user_data_t *ud) /* {{{ */
{
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
struct VSM_data *vd;
- const c_varnish_stats_t *stats;
_Bool ok;
+ const c_varnish_stats_t *stats;
+#elif HAVE_VARNISH_V5
+ struct vsm *vd;
+ struct vsc *vsc;
+ int vsm_status;
+#endif
user_config_t *conf;
conf = ud->data;
vd = VSM_New();
+
+#if HAVE_VARNISH_V5
+ vsc = VSC_New();
+#endif
+
#if HAVE_VARNISH_V3
VSC_Setup(vd);
#endif
if (conf->instance != NULL) {
int status;
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
status = VSM_n_Arg(vd, conf->instance);
+#elif HAVE_VARNISH_V5
+ status = VSM_Arg(vd, 'n', conf->instance);
+#endif
+
if (status < 0) {
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
VSM_Delete(vd);
- ERROR("varnish plugin: VSM_n_Arg (\"%s\") failed "
+#elif HAVE_VARNISH_V5
+ VSC_Destroy(&vsc, vd);
+ VSM_Destroy(&vd);
+#endif
+ ERROR("varnish plugin: VSM_Arg (\"%s\") failed "
"with status %i.",
conf->instance, status);
return -1;
#if HAVE_VARNISH_V3
ok = (VSC_Open(vd, /* diag = */ 1) == 0);
-#else /* if HAVE_VARNISH_V4 */
+#elif HAVE_VARNISH_V4
ok = (VSM_Open(vd) == 0);
#endif
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
if (!ok) {
VSM_Delete(vd);
ERROR("varnish plugin: Unable to open connection.");
-
return -1;
}
+#endif
#if HAVE_VARNISH_V3
stats = VSC_Main(vd);
-#else /* if HAVE_VARNISH_V4 */
+#elif HAVE_VARNISH_V4
stats = VSC_Main(vd, NULL);
#endif
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
if (!stats) {
VSM_Delete(vd);
ERROR("varnish plugin: Unable to get statistics.");
+ return -1;
+ }
+#endif
+
+#if HAVE_VARNISH_V5
+ if (VSM_Attach(vd, STDERR_FILENO)) {
+ ERROR("varnish plugin: Cannot attach to varnish. %s", VSM_Error(vd));
+ VSC_Destroy(&vsc, vd);
+ VSM_Destroy(&vd);
+ return -1;
+ }
+ vsm_status = VSM_Status(vd);
+ if (vsm_status & ~(VSM_MGT_RUNNING | VSM_WRK_RUNNING)) {
+ ERROR("varnish plugin: Unable to get statistics.");
+ VSC_Destroy(&vsc, vd);
+ VSM_Destroy(&vd);
return -1;
}
+#endif
#if HAVE_VARNISH_V3
VSC_Iter(vd, varnish_monitor, conf);
-#else /* if HAVE_VARNISH_V4 */
+#elif HAVE_VARNISH_V4
VSC_Iter(vd, NULL, varnish_monitor, conf);
+#elif HAVE_VARNISH_V5
+ VSC_Iter(vsc, vd, varnish_monitor, conf);
#endif
+
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
VSM_Delete(vd);
+#elif HAVE_VARNISH_V5
+ VSC_Destroy(&vsc, vd);
+ VSM_Destroy(&vd);
+#endif
return 0;
} /* }}} */
#if HAVE_VARNISH_V2
conf->collect_sm = 0;
#endif
-#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
conf->collect_sma = 0;
#endif
conf->collect_sms = 0;
conf->collect_struct = 0;
conf->collect_totals = 0;
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
conf->collect_uptime = 0;
#endif
conf->collect_vcl = 0;
conf->collect_workers = 0;
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
conf->collect_vsm = 0;
conf->collect_lck = 0;
conf->collect_mempool = 0;
else if (strcasecmp("CollectSMS", child->key) == 0)
cf_util_get_boolean(child, &conf->collect_sms);
else if (strcasecmp("CollectSMA", child->key) == 0)
-#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_sma);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
else if (strcasecmp("CollectTotals", child->key) == 0)
cf_util_get_boolean(child, &conf->collect_totals);
else if (strcasecmp("CollectUptime", child->key) == 0)
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_uptime);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
else if (strcasecmp("CollectWorkers", child->key) == 0)
cf_util_get_boolean(child, &conf->collect_workers);
else if (strcasecmp("CollectVSM", child->key) == 0)
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_vsm);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
child->key, "v4");
#endif
else if (strcasecmp("CollectLock", child->key) == 0)
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_lck);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
child->key, "v4");
#endif
else if (strcasecmp("CollectMempool", child->key) == 0)
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_mempool);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
child->key, "v4");
#endif
else if (strcasecmp("CollectManagement", child->key) == 0)
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_mgt);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
child->key, "v4");
#endif
else if (strcasecmp("CollectSMF", child->key) == 0)
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_smf);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
child->key, "v4");
#endif
else if (strcasecmp("CollectSMF", child->key) == 0)
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_smf);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
child->key, "v4");
#endif
else if (strcasecmp("CollectVBE", child->key) == 0)
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_vbe);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
child->key, "v4");
#endif
else if (strcasecmp("CollectMSE", child->key) == 0)
-#if HAVE_VARNISH_V4
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
cf_util_get_boolean(child, &conf->collect_mse);
#else
WARNING("Varnish plugin: \"%s\" is available for Varnish %s only.",
#if HAVE_VARNISH_V2
&& !conf->collect_sm
#endif
-#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V2 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
&& !conf->collect_sma
#endif
&& !conf->collect_struct && !conf->collect_totals
-#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
+#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 || HAVE_VARNISH_V5
&& !conf->collect_uptime
#endif
&& !conf->collect_vcl && !conf->collect_workers
-#if HAVE_VARNISH_V4
- && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf
- && !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool
- && !conf->collect_mse
+#if HAVE_VARNISH_V4 || HAVE_VARNISH_V5
+ && !conf->collect_vsm && !conf->collect_vbe && !conf->collect_smf &&
+ !conf->collect_mgt && !conf->collect_lck && !conf->collect_mempool &&
+ !conf->collect_mse
#endif
) {
WARNING("Varnish plugin: No metric has been configured for "
#ifdef HAVE_BLOCK_STATS_FLAGS
#define GET_BLOCK_INFO_VALUE(NAME, FIELD) \
- do { \
- if (!strcmp(param[i].field, NAME)) { \
- binfo->FIELD = param[i].value.l; \
- continue; \
- } \
- } while (0)
+ if (!strcmp(param[i].field, NAME)) { \
+ binfo->FIELD = param[i].value.l; \
+ continue; \
+ }
static int get_block_info(struct lv_block_info *binfo,
virTypedParameterPtr param, int nparams) {
fh = fopen("/proc/vmstat", "r");
if (fh == NULL) {
- char errbuf[1024];
- ERROR("vmem plugin: fopen (/proc/vmstat) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("vmem plugin: fopen (/proc/vmstat) failed: %s", STRERRNO);
return -1;
}
errno = 0;
proc = opendir(PROCDIR);
if (proc == NULL) {
- char errbuf[1024];
- ERROR("vserver plugin: fopen (%s): %s", PROCDIR,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("vserver plugin: fopen (%s): %s", PROCDIR, STRERRNO);
return -1;
}
errno = 0;
dent = readdir(proc);
if (dent == NULL) {
- char errbuf[4096];
-
if (errno == 0) /* end of directory */
break;
ERROR("vserver plugin: failed to read directory %s: %s", PROCDIR,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
closedir(proc);
return -1;
}
status = stat(file, &statbuf);
if (status != 0) {
- char errbuf[4096];
- WARNING("vserver plugin: stat (%s) failed: %s", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("vserver plugin: stat (%s) failed: %s", file, STRERRNO);
continue;
}
continue;
if (NULL == (fh = fopen(file, "r"))) {
- char errbuf[1024];
- ERROR("Cannot open '%s': %s", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("Cannot open '%s': %s", file, STRERRNO);
}
while ((fh != NULL) && (NULL != fgets(buffer, BUFSIZE, fh))) {
continue;
if (NULL == (fh = fopen(file, "r"))) {
- char errbuf[1024];
- ERROR("Cannot open '%s': %s", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("Cannot open '%s': %s", file, STRERRNO);
}
while ((fh != NULL) && (NULL != fgets(buffer, BUFSIZE, fh))) {
continue;
if (NULL == (fh = fopen(file, "r"))) {
- char errbuf[1024];
- ERROR("Cannot open '%s': %s", file,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("Cannot open '%s': %s", file, STRERRNO);
}
while ((fh != NULL) && (NULL != fgets(buffer, BUFSIZE, fh))) {
/* there are a variety of names for the wireless device */
if ((fh = fopen(WIRELESS_PROC_FILE, "r")) == NULL) {
- char errbuf[1024];
- WARNING("wireless: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("wireless: fopen: %s", STRERRNO);
return -1;
}
status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf));
if (status != 0) {
if (cb->log_send_errors) {
- char errbuf[1024];
ERROR("write_graphite plugin: send to %s:%s (%s) failed with status %zi "
"(%s)",
- cb->node, cb->service, cb->protocol, status,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ cb->node, cb->service, cb->protocol, status, STRERRNO);
}
close(cb->sock_fd);
cb->sock_fd =
socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (cb->sock_fd < 0) {
- char errbuf[1024];
- snprintf(connerr, sizeof(connerr), "failed to open socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ snprintf(connerr, sizeof(connerr), "failed to open socket: %s", STRERRNO);
continue;
}
status = connect(cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- snprintf(connerr, sizeof(connerr), "failed to connect to remote "
- "host: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ snprintf(connerr, sizeof(connerr), "failed to connect to remote host: %s",
+ STRERRNO);
close(cb->sock_fd);
cb->sock_fd = -1;
continue;
freeaddrinfo(ai_list);
if (cb->sock_fd < 0) {
- if (connerr[0] == '\0')
- /* this should not happen but try to get a message anyway */
- sstrerror(errno, connerr, sizeof(connerr));
c_complain(LOG_ERR, &cb->init_complaint,
"write_graphite plugin: Connecting to %s:%s via %s failed. "
"The last error was: %s",
sfree(cb->prefix);
sfree(cb->postfix);
+ pthread_mutex_unlock(&cb->send_lock);
pthread_mutex_destroy(&cb->send_lock);
sfree(cb);
wrr_disconnect(host);
+ pthread_mutex_lock(&host->lock);
pthread_mutex_destroy(&host->lock);
sfree(host);
} /* }}} void wrr_free */
sensu_close_socket(host);
if (status != 0) {
- char errbuf[1024];
ERROR("write_sensu plugin: Sending to Sensu at %s:%s failed: %s",
(host->node != NULL) ? host->node : SENSU_HOST,
- (host->service != NULL) ? host->service : SENSU_PORT,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ (host->service != NULL) ? host->service : SENSU_PORT, STRERRNO);
return -1;
}
sfree(host->separator);
free_str_list(&(host->metric_handlers));
free_str_list(&(host->notification_handlers));
+
+ pthread_mutex_unlock(&host->lock);
pthread_mutex_destroy(&host->lock);
+
sfree(host);
} /* }}} void sensu_free */
status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf));
if (status != 0) {
- char errbuf[1024];
ERROR("write_tsdb plugin: send failed with status %zi (%s)", status,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
close(cb->sock_fd);
cb->sock_fd = -1;
}
if (cb->sock_fd < 0) {
- char errbuf[1024];
ERROR("write_tsdb plugin: Connecting to %s:%s failed. "
"The last error was: %s",
- node, service, sstrerror(errno, errbuf, sizeof(errbuf)));
+ node, service, STRERRNO);
return -1;
}
sfree(cb->service);
sfree(cb->host_tags);
+ pthread_mutex_unlock(&cb->send_lock);
pthread_mutex_destroy(&cb->send_lock);
sfree(cb);
fh = fopen(ZOL_ARCSTATS_FILE, "r");
if (fh == NULL) {
- char errbuf[1024];
ERROR("zfs_arc plugin: Opening \"%s\" failed: %s", ZOL_ARCSTATS_FILE,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return -1;
}
- ksp = llist_create();
- if (ksp == NULL) {
- ERROR("zfs_arc plugin: `llist_create' failed.");
- fclose(fh);
- return -1;
- }
-
- // Ignore the first two lines because they contain information about
- // the rest of the file.
- // See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel
- // module.
- if (fgets(buffer, sizeof(buffer), fh) == NULL) {
- ERROR("zfs_arc plugin: \"%s\" does not contain a single line.",
+ /* Ignore the first two lines because they contain information about the rest
+ * of the file.
+ * See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel module.
+ */
+ if ((fgets(buffer, sizeof(buffer), fh) == NULL) ||
+ (fgets(buffer, sizeof(buffer), fh) == NULL)) {
+ ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.",
ZOL_ARCSTATS_FILE);
fclose(fh);
return -1;
}
- if (fgets(buffer, sizeof(buffer), fh) == NULL) {
- ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.",
- ZOL_ARCSTATS_FILE);
+
+ ksp = llist_create();
+ if (ksp == NULL) {
+ ERROR("zfs_arc plugin: `llist_create' failed.");
fclose(fh);
return -1;
}
}
if (sread(fd, buf, bufsize) != 0) {
- char errbuf[1024];
- ERROR("zone plugin: Reading \"%s\" failed: %s", procfile,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("zone plugin: Reading \"%s\" failed: %s", procfile, STRERRNO);
close(fd);
return 1;
}
status = getaddrinfo(host, port, &ai_hints, &ai_list);
if (status != 0) {
- char errbuf[1024];
INFO("getaddrinfo failed: %s",
- (status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(status));
+ (status == EAI_SYSTEM) ? STRERRNO : gai_strerror(status));
return -1;
}
for (struct addrinfo *ai = ai_list; ai != NULL; ai = ai->ai_next) {
sk = socket(ai->ai_family, SOCK_STREAM, 0);
if (sk < 0) {
- char errbuf[1024];
- WARNING("zookeeper: socket(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("zookeeper: socket(2) failed: %s", STRERRNO);
continue;
}
status = (int)connect(sk, ai->ai_addr, ai->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
close(sk);
sk = -1;
- WARNING("zookeeper: connect(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("zookeeper: connect(2) failed: %s", STRERRNO);
continue;
}
status = (int)swrite(sk, "mntr\r\n", strlen("mntr\r\n"));
if (status != 0) {
- char errbuf[1024];
- ERROR("zookeeper: write(2) failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("zookeeper: write(2) failed: %s", STRERRNO);
close(sk);
return -1;
}
buffer_size - buffer_fill, /* flags = */ 0)) !=
0) {
if (status < 0) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EINTR))
continue;
- ERROR("zookeeper: Error reading from socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("zookeeper: Error reading from socket: %s", STRERRNO);
close(sk);
return -1;
}
#!/bin/sh
-DEFAULT_VERSION="5.7.2.git"
+DEFAULT_VERSION="5.8.0.git"
if [ -d .git ]; then
VERSION="`git describe --dirty=+ --abbrev=7 2> /dev/null | grep collectd | sed -e 's/^collectd-//' -e 's/-/./g'`"