Skip to content
Snippets Groups Projects
Commit bb894cdd authored by Lais Frigerio's avatar Lais Frigerio
Browse files

Issue#12: Create and install agent zip file in a temporary directory - /tmp

parent cea55745
No related branches found
No related tags found
2 merge requests!51Merge development to master,!38Issue#12: Create and install agent zip file in a temporary directory - /tmp
Pipeline #
......@@ -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);
......@@ -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;
}
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment