X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbind.c;h=6b13df8eb89ea990ae9d228101e4ae86b770a8fa;hb=5a011cfd81d5ef3876d4ecb43b6bbffd151f1b03;hp=9bb662fc2ff731fa1941ec892f80fa12a0eda9da;hpb=11c8a760c2d354b2f4637bdb297efb253bfaa519;p=collectd.git diff --git a/src/bind.c b/src/bind.c index 9bb662fc..6b13df8e 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 @@ -429,7 +437,28 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ return (-1); } - *ret_value = mktime(&tm); +#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);