X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbind.c;h=853b9c26a352d912d851eee8a6803f8fda42677b;hb=fd01cdd0546ccbbda7f4cf5db2d0ae28e1e770cd;hp=597b90d332a4e26aef4cde068616960460d5d768;hpb=938d6380a94cd898a28c5ad1a37c19e7bd47db4c;p=collectd.git diff --git a/src/bind.c b/src/bind.c index 597b90d3..853b9c26 100644 --- a/src/bind.c +++ b/src/bind.c @@ -35,11 +35,19 @@ #endif #endif /* STRPTIME_NEEDS_STANDARDS */ +#if TIMEGM_NEEDS_BSD +#ifndef _BSD_SOURCE +#define _BSD_SOURCE 1 +#endif +#endif /* TIMEGM_NEEDS_BSD */ + #include "collectd.h" #include "common.h" #include "plugin.h" +#include + /* Some versions of libcurl don't include this themselves and then don't have * fd_set available. */ #if HAVE_SYS_SELECT_H @@ -433,8 +441,28 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ return (-1); } - tzset(); - *ret_value = mktime(&tm) - timezone; /* fix strptime() misinterpretation */ +#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))); + 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))); + return (-1); + } + /* mktime assumes that tm is local time. Luckily, it also sets timezone to + * the offset used for the conversion, and we undo the conversion to convert + * back to UTC. */ + *ret_value = t - timezone; +#endif xmlXPathFreeObject(xpathObj); return (0); @@ -498,8 +526,10 @@ static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */ status = bind_xml_read_gauge(doc, counter, &value.gauge); else status = bind_xml_read_derive(doc, counter, &value.derive); - if (status != 0) + if (status != 0) { + xmlFree(name); continue; + } status = (*list_callback)(name, value, current_time, user_data); if (status == 0) @@ -631,12 +661,16 @@ static int bind_parse_generic_name_attr_value_list( status = bind_xml_read_gauge(doc, child, &value.gauge); else status = bind_xml_read_derive(doc, child, &value.derive); - if (status != 0) + if (status != 0) { + xmlFree(attr_name); continue; + } status = (*list_callback)(attr_name, value, current_time, user_data); if (status == 0) num_entries++; + + xmlFree(attr_name); } }