diff --git a/src/apcupsd.cc b/src/apcupsd.cc index 84ccb52f..ba9991d5 100644 --- a/src/apcupsd.cc +++ b/src/apcupsd.cc @@ -258,7 +258,7 @@ int apcupsd_scan_arg(const char *arg) if (sscanf(arg, "%63s %d", host, &port) != 2) return 1; - apcupsd.port = htons(port); + apcupsd.port = port; strncpy(apcupsd.host, host, sizeof(apcupsd.host)); return 0; } diff --git a/src/ccurl_thread.cc b/src/ccurl_thread.cc index 1ecd2b0f..343aee71 100644 --- a/src/ccurl_thread.cc +++ b/src/ccurl_thread.cc @@ -105,34 +105,31 @@ void ccurl_fetch_data(thread_handle &handle, const ccurl_location_ptr &curloc) chunk.memory = NULL; chunk.size = 0; - if (curl_global_init(CURL_GLOBAL_ALL) == 0) { - curl = curl_easy_init(); - if (curl) { - DBGP("reading curl data from '%s'", curloc->uri); - curl_easy_setopt(curl, CURLOPT_URL, curloc->uri); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &chunk); - curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-curl/1.0"); + curl = curl_easy_init(); + if (curl) { + DBGP("reading curl data from '%s'", curloc->uri); + curl_easy_setopt(curl, CURLOPT_URL, curloc->uri); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &chunk); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-curl/1.0"); - res = curl_easy_perform(curl); - if (res == CURLE_OK && chunk.size) { - long http_status_code; + res = curl_easy_perform(curl); + if (res == CURLE_OK && chunk.size) { + long http_status_code; - if(curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK && http_status_code == 200) { - std::lock_guard lock(handle.mutex()); - curloc->process_function(curloc->result, chunk.memory); - } else { - NORM_ERR("curl: no data from server"); - } - free(chunk.memory); + if(curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK && http_status_code == 200) { + std::lock_guard lock(handle.mutex()); + curloc->process_function(curloc->result, chunk.memory); } else { NORM_ERR("curl: no data from server"); } - - curl_easy_cleanup(curl); + free(chunk.memory); + } else { + NORM_ERR("curl: no data from server"); } - curl_global_cleanup(); + + curl_easy_cleanup(curl); } } diff --git a/src/conky.cc b/src/conky.cc index 8a135247..c98a211d 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -71,6 +71,9 @@ #if defined BUILD_WEATHER_XOAP || defined BUILD_RSS #include #endif +#ifdef BUILD_CURL +#include +#endif /* local headers */ #include "core.h" @@ -3190,6 +3193,11 @@ int main(int argc, char **argv) g_signal_pending = 0; clear_net_stats(); +#ifdef BUILD_CURL + if(curl_global_init(CURL_GLOBAL_ALL)) + NORM_ERR("curl_global_init() failed, you may not be able to use curl variables"); +#endif + /* handle command line parameters that don't change configs */ #ifdef BUILD_X11 if (!setlocale(LC_CTYPE, "")) { @@ -3337,6 +3345,10 @@ int main(int argc, char **argv) main_loop(); +#ifdef BUILD_CURL + curl_global_cleanup(); +#endif + #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) kvm_close(kd); #endif diff --git a/src/mail.cc b/src/mail.cc index 48e09f5d..491ca6a1 100644 --- a/src/mail.cc +++ b/src/mail.cc @@ -698,6 +698,12 @@ static void imap_thread(thread_handle &handle, struct mail_s *mail) int res; fd_set fdset; + if (fail > 0) { + NORM_ERR("Trying IMAP connection again for %s@%s (try %u/%u)", + mail->user, mail->host, fail + 1, mail->retries); + resolved_host = 0; /* force us to resolve the hostname again */ + sleep(fail); /* sleep more for the more failures we have */ + } if (!resolved_host) { memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; @@ -714,10 +720,6 @@ static void imap_thread(thread_handle &handle, struct mail_s *mail) } resolved_host = 1; } - if (fail > 0) { - NORM_ERR("Trying IMAP connection again for %s@%s (try %u/%u)", - mail->user, mail->host, fail + 1, mail->retries); - } do { for (rp = ai; rp != NULL; rp = rp->ai_next) { sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); @@ -1041,6 +1043,13 @@ static void pop3_thread(thread_handle &handle, struct mail_s *mail) struct timeval fetchtimeout; int res; fd_set fdset; + + if (fail > 0) { + NORM_ERR("Trying POP3 connection again for %s@%s (try %u/%u)", + mail->user, mail->host, fail + 1, mail->retries); + resolved_host = 0; /* force us to resolve the hostname again */ + sleep(fail); /* sleep more for the more failures we have */ + } if (!resolved_host) { memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; @@ -1055,11 +1064,7 @@ static void pop3_thread(thread_handle &handle, struct mail_s *mail) fail++; break; } - resolved_host = 1; -} - if (fail > 0) { - NORM_ERR("Trying POP3 connection again for %s@%s (try %u/%u)", - mail->user, mail->host, fail + 1, mail->retries); + resolved_host = 1; } do { for (rp = ai; rp != NULL; rp = rp->ai_next) {