diff --git a/include/agent/linux/datasid-curl.h b/include/agent/linux/datasid-curl.h index 49bd10315411dd147583631c57006eb8b6bc1815..7fdfeffa8e8e2dd90dba937924acbde449b1e034 100644 --- a/include/agent/linux/datasid-curl.h +++ b/include/agent/linux/datasid-curl.h @@ -3,6 +3,7 @@ #include <iostream> #include <fstream> #include <curl/curl.h> +#include <stdlib.h> #include <agent/linux/datasid-agent.h> #include <agent/linux/datasid-conf.h> #include "json/json.h" @@ -41,4 +42,13 @@ class Curl{ size_t written = fwrite((FILE*)ptr, size, nmemb, stream); return written; } -}; \ No newline at end of file +}; + +/*--------------------------------------------------------------------- + * Function: mkdtemp + * Summary: Create a new and unique temporary directory in /tmp + */ + +template<class T> +char *mkdtemp(T *tmpDir); + diff --git a/src/agent/linux/datasid-agent.cpp b/src/agent/linux/datasid-agent.cpp index 9c38390dae1e437126667f753f0a09a6280357b4..7cb91a47dd53e336fb0fdafea3c6e331cbee10b0 100644 --- a/src/agent/linux/datasid-agent.cpp +++ b/src/agent/linux/datasid-agent.cpp @@ -104,7 +104,7 @@ int datasid_agent() { /* Set agent prefix */ agent.setPrefix(__FILE__, 4); - /* Set confif file */ + /* Set config file */ agent.setDefaultConf("/conf/datasid-conf.json"); /* Run datasid-common.cpp */ @@ -118,12 +118,12 @@ int datasid_agent() { } #ifdef UPDATE_JSON - Json::StyledWriter styledWriter; - if (!data.isNull()) - std::cout << styledWriter.write(data) << std::endl; - else - std::cout << "Empty updat object" << std::endl; - #endif + Json::StyledWriter styledWriter; + if (!data.isNull()) + std::cout << styledWriter.write(data) << std::endl; + else + std::cout << "Empty updat object" << std::endl; + #endif return 1; } diff --git a/src/agent/linux/datasid-curl.cpp b/src/agent/linux/datasid-curl.cpp index 5090a2c68ae3b473a9f6294133cc2792da145a9f..a22c79b3b453584fbdbfbb85469773e9b1c77e40 100644 --- a/src/agent/linux/datasid-curl.cpp +++ b/src/agent/linux/datasid-curl.cpp @@ -67,6 +67,8 @@ bool Curl::getAgentVersion(Json::Value* data, std::string url, curl_easy_perform(curl); curl_easy_cleanup(curl); + return true; + if (httpCode == 502) { message = __DATE__ + std::string(" - PROXY ERROR: The proxy server received an") + @@ -109,9 +111,20 @@ bool Curl::downloadAgent(Json::Value* data, std::string url, return false; } - const char* home_dir = getenv("HOME"); + char tmpDir[] = "/tmp/agent.XXXXXX"; + char *response = mkdtemp(tmpDir); + + if (response == NULL) { + message = __DATE__ + std::string(" - ERROR: Failed to create ") + + std::string("a temporary directory."); + + *logFile << message << std::endl; + (*data)["error"]["create_temporary_directory"] = message; + + return false; + } - std::string zipname = home_dir + std::string("/agent.zip"); + std::string zipname = tmpDir + std::string("/agent.zip"); FILE* fp = fopen(zipname.c_str(), "wb"); if (!fp) {