From: Marc Fournier Date: Wed, 8 Apr 2015 20:58:22 +0000 (+0200) Subject: curl-based plugins: disable Timeout option if libcurl < 7.16.2 X-Git-Tag: collectd-5.5.0~55 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8a2c605b07917885438eb80f1d5097cb58e6193b;p=collectd.git curl-based plugins: disable Timeout option if libcurl < 7.16.2 This could be done better, but as it's a non-essential feature and 7.16.2 is 8 years old, I favor not over-complicating things. --- diff --git a/configure.ac b/configure.ac index c83805e3..025bfa6f 100644 --- a/configure.ac +++ b/configure.ac @@ -1700,6 +1700,10 @@ then [have_curlopt_username="yes"], [have_curlopt_username="no"], [[#include ]]) + AC_CHECK_DECL(CURLOPT_TIMEOUT_MS, + [have_curlopt_timeout="yes"], + [have_curlopt_timeout="no"], + [[#include ]]) fi fi if test "x$with_libcurl" = "xyes" @@ -1713,6 +1717,11 @@ then then AC_DEFINE(HAVE_CURLOPT_USERNAME, 1, [Define if libcurl supports CURLOPT_USERNAME option.]) fi + + if test "x$have_curlopt_timeout" = "xyes" + then + AC_DEFINE(HAVE_CURLOPT_TIMEOUT_MS, 1, [Define if libcurl supports CURLOPT_TIMEOUT_MS option.]) + fi fi AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes") # }}} diff --git a/src/apache.c b/src/apache.c index 0d915b07..086a39c8 100644 --- a/src/apache.c +++ b/src/apache.c @@ -372,11 +372,13 @@ static int init_host (apache_t *st) /* {{{ */ if (st->cacert != NULL) curl_easy_setopt (st->curl, CURLOPT_CAINFO, st->cacert); +#ifdef HAVE_CURLOPT_TIMEOUT_MS 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())); +#endif return (0); } /* }}} int init_host */ diff --git a/src/ascent.c b/src/ascent.c index 501f294f..11175af5 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -590,11 +590,13 @@ static int ascent_init (void) /* {{{ */ if (cacert != NULL) curl_easy_setopt (curl, CURLOPT_CAINFO, cacert); +#ifdef HAVE_CURLOPT_TIMEOUT_MS 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())); +#endif return (0); } /* }}} int ascent_init */ diff --git a/src/bind.c b/src/bind.c index 1108a3a6..ec84df46 100644 --- a/src/bind.c +++ b/src/bind.c @@ -1757,8 +1757,10 @@ static int bind_init (void) /* {{{ */ curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL); curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L); 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())); +#endif return (0); diff --git a/src/curl.c b/src/curl.c index 1bbeddc7..11da3858 100644 --- a/src/curl.c +++ b/src/curl.c @@ -411,11 +411,13 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */ if (wp->post_body != NULL) curl_easy_setopt (wp->curl, CURLOPT_POSTFIELDS, wp->post_body); +#ifdef HAVE_CURLOPT_TIMEOUT_MS 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())); +#endif return (0); } /* }}} int cc_page_init_curl */ diff --git a/src/curl_json.c b/src/curl_json.c index 5128c874..3a5a3ab8 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -651,6 +651,7 @@ static int cj_init_curl (cj_t *db) /* {{{ */ if (db->post_body != NULL) curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body); +#ifdef HAVE_CURLOPT_TIMEOUT_MS if (db->timeout >= 0) curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) db->timeout); else if (db->interval > 0) @@ -659,6 +660,7 @@ static int cj_init_curl (cj_t *db) /* {{{ */ else curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, CDTIME_T_TO_MS(plugin_get_interval())); +#endif return (0); } /* }}} int cj_init_curl */ diff --git a/src/curl_xml.c b/src/curl_xml.c index 32a48c51..9049d990 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -885,11 +885,13 @@ static int cx_init_curl (cx_t *db) /* {{{ */ if (db->post_body != NULL) curl_easy_setopt (db->curl, CURLOPT_POSTFIELDS, db->post_body); +#ifdef HAVE_CURLOPT_TIMEOUT_MS 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())); +#endif return (0); } /* }}} int cx_init_curl */ diff --git a/src/nginx.c b/src/nginx.c index 1c537a85..4e4ce3bb 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -181,6 +181,7 @@ static int init (void) curl_easy_setopt (curl, CURLOPT_CAINFO, cacert); } +#ifdef HAVE_CURLOPT_TIMEOUT_MS if (timeout != NULL) { curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, atol(timeout)); @@ -190,6 +191,7 @@ static int init (void) curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, CDTIME_T_TO_MS(plugin_get_interval())); } +#endif return (0); } /* void init */ diff --git a/src/write_http.c b/src/write_http.c index 3b594be4..ed596bbf 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -132,8 +132,10 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */ (long) cb->low_speed_time); } +#ifdef HAVE_CURLOPT_TIMEOUT_MS if (cb->timeout > 0) curl_easy_setopt (cb->curl, CURLOPT_TIMEOUT_MS, (long) cb->timeout); +#endif curl_easy_setopt (cb->curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);