aboutsummaryrefslogtreecommitdiff
path: root/tools/gator/daemon/ConfigurationXML.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gator/daemon/ConfigurationXML.cpp')
-rw-r--r--tools/gator/daemon/ConfigurationXML.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/tools/gator/daemon/ConfigurationXML.cpp b/tools/gator/daemon/ConfigurationXML.cpp
index fb00202f6569..2a5252a5bb04 100644
--- a/tools/gator/daemon/ConfigurationXML.cpp
+++ b/tools/gator/daemon/ConfigurationXML.cpp
@@ -27,14 +27,7 @@ ConfigurationXML::ConfigurationXML() {
char path[PATH_MAX];
- if (gSessionData->mConfigurationXMLPath) {
- strncpy(path, gSessionData->mConfigurationXMLPath, PATH_MAX);
- } else {
- if (util->getApplicationFullPath(path, PATH_MAX) != 0) {
- logg->logMessage("Unable to determine the full path of gatord, the cwd will be used");
- }
- strncat(path, "configuration.xml", PATH_MAX - strlen(path) - 1);
- }
+ getPath(path);
mConfigurationXML = util->readFromDisk(path);
for (int retryCount = 0; retryCount < 2; ++retryCount) {
@@ -48,12 +41,7 @@ ConfigurationXML::ConfigurationXML() {
int ret = parse(mConfigurationXML);
if (ret == 1) {
- // remove configuration.xml on disk to use the default
- if (remove(path) != 0) {
- logg->logError(__FILE__, __LINE__, "Invalid configuration.xml file detected and unable to delete it. To resolve, delete configuration.xml on disk");
- handleException();
- }
- logg->logMessage("Invalid configuration.xml file detected and removed");
+ remove();
// Free the current configuration and reload
free((void*)mConfigurationXML);
@@ -197,3 +185,25 @@ void ConfigurationXML::getDefaultConfigurationXml(const char * & xml, unsigned i
xml = (const char *)configuration_xml;
len = configuration_xml_len;
}
+
+void ConfigurationXML::getPath(char* path) {
+ if (gSessionData->mConfigurationXMLPath) {
+ strncpy(path, gSessionData->mConfigurationXMLPath, PATH_MAX);
+ } else {
+ if (util->getApplicationFullPath(path, PATH_MAX) != 0) {
+ logg->logMessage("Unable to determine the full path of gatord, the cwd will be used");
+ }
+ strncat(path, "configuration.xml", PATH_MAX - strlen(path) - 1);
+ }
+}
+
+void ConfigurationXML::remove() {
+ char path[PATH_MAX];
+ getPath(path);
+
+ if (::remove(path) != 0) {
+ logg->logError(__FILE__, __LINE__, "Invalid configuration.xml file detected and unable to delete it. To resolve, delete configuration.xml on disk");
+ handleException();
+ }
+ logg->logMessage("Invalid configuration.xml file detected and removed");
+}