summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: db1391a)
raw | patch | inline | side by side (parent: db1391a)
author | Florian Forster <octo@collectd.org> | |
Fri, 21 Aug 2015 09:56:57 +0000 (11:56 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 21 Aug 2015 09:56:57 +0000 (11:56 +0200) |
The assumed type was "long", because that is what struct timespec is
using. However, struct timespec only stores the fraction of a second in
the approrpiate field and therefore only cares about values up to 10^9.
We, on the other hand, assume a UNIX epoch in ns precision, so we
require the entire 64bits.
This patch changes the [MUN]S_TO_CDTIME_T() macros to assume a uint64_t
input and moves the casting to the appropriate data type for struct
time{val,spec} to the CDTIME_T_TO_TIME{VAL,SPEC}() macros. Appropriate
casts are added to the cURL based plugins which need to pass a "long" to
cURL when specifying timeouts.
It also fixes the unit test, which assigned large (> 32 bit) literals to
a "long" field, which breaks on 32 bit architectures.
using. However, struct timespec only stores the fraction of a second in
the approrpiate field and therefore only cares about values up to 10^9.
We, on the other hand, assume a UNIX epoch in ns precision, so we
require the entire 64bits.
This patch changes the [MUN]S_TO_CDTIME_T() macros to assume a uint64_t
input and moves the casting to the appropriate data type for struct
time{val,spec} to the CDTIME_T_TO_TIME{VAL,SPEC}() macros. Appropriate
casts are added to the cURL based plugins which need to pass a "long" to
cURL when specifying timeouts.
It also fixes the unit test, which assigned large (> 32 bit) literals to
a "long" field, which breaks on 32 bit architectures.
src/apache.c | patch | blob | history | |
src/ascent.c | patch | blob | history | |
src/bind.c | patch | blob | history | |
src/curl.c | patch | blob | history | |
src/curl_json.c | patch | blob | history | |
src/curl_xml.c | patch | blob | history | |
src/daemon/utils_time.h | patch | blob | history | |
src/daemon/utils_time_test.c | patch | blob | history | |
src/nginx.c | patch | blob | history |
diff --git a/src/apache.c b/src/apache.c
index e384d800acdf0758579015c5643d7d50c0920e7a..41b807af7541fb748634d2b5c3660198659dc43a 100644 (file)
--- a/src/apache.c
+++ b/src/apache.c
if (st->timeout >= 0)
curl_easy_setopt (st->curl, CURLOPT_TIMEOUT_MS, (long) st->timeout);
else
- curl_easy_setopt (st->curl, CURLOPT_TIMEOUT_MS,
- CDTIME_T_TO_MS(plugin_get_interval()));
+ curl_easy_setopt (st->curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval()));
#endif
return (0);
diff --git a/src/ascent.c b/src/ascent.c
index 11175af5e6104afa7b39291fd77fd45441a0cb64..2ba3c772d5f9f8116f4100b6f3484756cfbb8ef7 100644 (file)
--- a/src/ascent.c
+++ b/src/ascent.c
if (timeout != NULL)
curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, atol(timeout));
else
- curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS,
- CDTIME_T_TO_MS(plugin_get_interval()));
+ curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval()));
#endif
return (0);
diff --git a/src/bind.c b/src/bind.c
index 32b0f16e21f50311d530f934f72964076dfee0ee..06b4ace00393e2321fc7bef9762f4b320c582aa5 100644 (file)
--- a/src/bind.c
+++ b/src/bind.c
curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
#ifdef HAVE_CURLOPT_TIMEOUT_MS
curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
- (long) timeout : CDTIME_T_TO_MS(plugin_get_interval()));
+ (long) timeout : (long) CDTIME_T_TO_MS(plugin_get_interval()));
#endif
diff --git a/src/curl.c b/src/curl.c
index ac4cc512c63fd51dcdd9190814aca5e0eaf1cc7d..16ae3ababc1d48c421c85c814b2eb0499edd699e 100644 (file)
--- a/src/curl.c
+++ b/src/curl.c
if (wp->timeout >= 0)
curl_easy_setopt (wp->curl, CURLOPT_TIMEOUT_MS, (long) wp->timeout);
else
- curl_easy_setopt (wp->curl, CURLOPT_TIMEOUT_MS,
- CDTIME_T_TO_MS(plugin_get_interval()));
+ curl_easy_setopt (wp->curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval()));
#endif
return (0);
diff --git a/src/curl_json.c b/src/curl_json.c
index 80632424785ae697b8a809588cac5f1b2e61ba15..510d9b621d0b9a32b235337856f455c82eef2b3e 100644 (file)
--- a/src/curl_json.c
+++ b/src/curl_json.c
if (db->timeout >= 0)
curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) db->timeout);
else if (db->interval > 0)
- curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS,
- CDTIME_T_TO_MS(db->timeout));
+ curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(db->timeout));
else
- curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS,
- CDTIME_T_TO_MS(plugin_get_interval()));
+ curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval()));
#endif
return (0);
diff --git a/src/curl_xml.c b/src/curl_xml.c
index 8a466bae6f98ff383979e60a2c586ae8e274e6cd..5a1f2baba232e7c56d5ed2ade5b8912e0f13ddd9 100644 (file)
--- a/src/curl_xml.c
+++ b/src/curl_xml.c
if (db->timeout >= 0)
curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) db->timeout);
else
- curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS,
- CDTIME_T_TO_MS(plugin_get_interval()));
+ curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval()));
#endif
return (0);
index f2d474a089871867150bb534df024cc9afde7447..6476780ad4f4e9cde02eeaf3044e39d7548de4cc 100644 (file)
--- a/src/daemon/utils_time.h
+++ b/src/daemon/utils_time.h
((((((cdtime_t) (ns)) % 1000000000) << 30) + 500000000) / 1000000000))
#define CDTIME_T_TO_TIME_T(t) ((((time_t) (t)) + (1 << 29)) >> 30)
-#define CDTIME_T_TO_MS(t) (((((long) (t)) >> 30) * 1000L) + \
- (((((long) (t)) & 0x3fffffff) * 1000L + (1 << 29)) >> 30))
-#define CDTIME_T_TO_US(t) (((((suseconds_t) (t)) >> 30) * 1000000L) + \
- (((((suseconds_t) (t)) & 0x3fffffff) * 1000000L + (1 << 29)) >> 30))
-#define CDTIME_T_TO_NS(t) (((((long) (t)) >> 30) * 1000000000L) + \
- (((((long) (t)) & 0x3fffffff) * 1000000000L + (1 << 29)) >> 30))
+#define CDTIME_T_TO_MS(t) (((((uint64_t) (t)) >> 30) * 1000L) + \
+ (((((uint64_t) (t)) & 0x3fffffff) * 1000L + (1 << 29)) >> 30))
+#define CDTIME_T_TO_US(t) (((((uint64_t) (t)) >> 30) * 1000000L) + \
+ (((((uint64_t) (t)) & 0x3fffffff) * 1000000L + (1 << 29)) >> 30))
+#define CDTIME_T_TO_NS(t) (((((uint64_t) (t)) >> 30) * 1000000000L) + \
+ (((((uint64_t) (t)) & 0x3fffffff) * 1000000000L + (1 << 29)) >> 30))
#define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0)
#define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0))
#define CDTIME_T_TO_TIMEVAL(cdt,tvp) do { \
(tvp)->tv_sec = CDTIME_T_TO_TIME_T (cdt); \
- (tvp)->tv_usec = CDTIME_T_TO_US ((cdt) & 0x3fffffff); \
+ (tvp)->tv_usec = (suseconds_t) CDTIME_T_TO_US ((cdt) & 0x3fffffff); \
} while (0)
#define TIMEVAL_TO_CDTIME_T(tv) US_TO_CDTIME_T(1000000 * (tv)->tv_sec + (tv)->tv_usec)
#define CDTIME_T_TO_TIMESPEC(cdt,tsp) do { \
(tsp)->tv_sec = CDTIME_T_TO_TIME_T (cdt); \
- (tsp)->tv_nsec = CDTIME_T_TO_NS ((cdt) & 0x3fffffff); \
+ (tsp)->tv_nsec = (long) CDTIME_T_TO_NS ((cdt) & 0x3fffffff); \
} while (0)
#define TIMESPEC_TO_CDTIME_T(ts) NS_TO_CDTIME_T(1000000000 * (ts)->tv_sec + (ts)->tv_nsec)
index 1f13556990df096ee051c9b68dc914d5d8852ffa..0c527290602369910495da5e7d418e0b7be890e7 100644 (file)
DEF_TEST(ns_to_cdtime)
{
struct {
- long ns;
+ uint64_t ns;
cdtime_t want;
} cases[] = {
// 1439981652801860766 * 2^30 / 10^9 = 1546168526406004689.4
diff --git a/src/nginx.c b/src/nginx.c
index 4e4ce3bbc6115572873668a76507f80ccd82b316..69ec06dc996edc9452ea565776c9d9d70c241e68 100644 (file)
--- a/src/nginx.c
+++ b/src/nginx.c
}
else
{
- curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS,
- CDTIME_T_TO_MS(plugin_get_interval()));
+ curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval()));
}
#endif