|
|
|
|
@ -17,6 +17,8 @@
|
|
|
|
|
#include <libdaemon/dexec.h>
|
|
|
|
|
#include "ev.h"
|
|
|
|
|
|
|
|
|
|
#include "curl/curl.h"
|
|
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@ -135,6 +137,77 @@ DH *get_dh2048()
|
|
|
|
|
return(dh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct MemoryStruct {
|
|
|
|
|
char *memory;
|
|
|
|
|
size_t size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
|
|
|
|
|
size_t realsize = size * nmemb;
|
|
|
|
|
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
|
|
|
|
|
mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
|
|
|
|
|
assert(mem->memory);
|
|
|
|
|
memcpy(&(mem->memory[mem->size]), contents, realsize);
|
|
|
|
|
mem->size += realsize;
|
|
|
|
|
mem->memory[mem->size] = 0;
|
|
|
|
|
return realsize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char * main_check_latest_version() {
|
|
|
|
|
CURL *curl_handle;
|
|
|
|
|
CURLcode res;
|
|
|
|
|
struct MemoryStruct chunk;
|
|
|
|
|
chunk.memory = (char *)malloc(1);
|
|
|
|
|
chunk.size = 0;
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
curl_handle = curl_easy_init();
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_URL, "https://www.proxysql.com/latest");
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
|
|
|
|
|
|
|
string s = "proxysql-agent/";
|
|
|
|
|
s += PROXYSQL_VERSION;
|
|
|
|
|
if (binary_sha1) {
|
|
|
|
|
s += " (" ;
|
|
|
|
|
s+= binary_sha1;
|
|
|
|
|
s += ")" ;
|
|
|
|
|
}
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, s.c_str());
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 10);
|
|
|
|
|
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 10);
|
|
|
|
|
|
|
|
|
|
res = curl_easy_perform(curl_handle);
|
|
|
|
|
|
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
|
switch (res) {
|
|
|
|
|
case CURLE_COULDNT_RESOLVE_HOST:
|
|
|
|
|
case CURLE_COULDNT_CONNECT:
|
|
|
|
|
case CURLE_OPERATION_TIMEDOUT:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
proxy_error("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
free(chunk.memory);
|
|
|
|
|
chunk.memory = NULL;
|
|
|
|
|
}
|
|
|
|
|
curl_easy_cleanup(curl_handle);
|
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
return chunk.memory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void * main_check_latest_version_thread(void *arg) {
|
|
|
|
|
char * latest_version = main_check_latest_version();
|
|
|
|
|
if (latest_version) {
|
|
|
|
|
proxy_info("Latest ProxySQL version available: %s\n", latest_version);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1607,6 +1680,17 @@ __start_label:
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if (GloVars.check_for_new_version) {
|
|
|
|
|
if (0) {
|
|
|
|
|
pthread_attr_t attr;
|
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
|
pthread_t thr;
|
|
|
|
|
if (pthread_create(&thr, &attr, main_check_latest_version_thread, NULL) !=0 ) {
|
|
|
|
|
perror("Thread creation");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
unsigned int missed_heartbeats = 0;
|
|
|
|
|
unsigned long long previous_time = monotonic_time();
|
|
|
|
|
|