/******************************************************************************* * ALMA - Atacama Large Millimiter Array * Copyright (c) European Southern Observatory, 2013 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * who when what * -------- -------- ---------------------------------------------- * almadev 2013-05-22 created */ #include #include #include #include "acsDaemonUtils.h" #include "acsutilTimeStamp.h" AcsDaemonUtils::AcsDaemonUtils(): m_logDirectory("~/.acs/commandcenter/") { int ret=initLogDirectory(); // In case of error ret is not 0 if (ret!=0) { std::cout<<"ERROR initializing the folder to write logs: "; switch (ret) { case 1: { std::cout<<"ACSDATA does not exist or can't write in ACSDATA"<"<"< from HOST env. var. std::string hostFolder = logDirectory; char * host = ACE_OS::getenv("HOST"); if(host != NULL) { hostFolder = logDirectory + std::string(host) + std::string("/"); } else { return 4; // HOST env. var. not set } // Check if ACSDATA/logs/ exists if (ACE_OS::access(hostFolder.c_str(),F_OK)!=0) { // try to create the folder if (!makeFolder(hostFolder.c_str())!=0) { return 5; } } // Check if ACSDATA/logs/ is writable if (ACE_OS::access(hostFolder.c_str(),W_OK)!=0) { return 6; } // Everything went well: use ACSDATA/logs/ as a base for logging m_logDirectory=hostFolder; return 0; } std::string AcsDaemonUtils::getLogDirectoryForContainer(std::string containerName) { if (containerName.rfind('/')==std::string::npos) { // Non hierarchical container: the logs go in the standard log folder return getLogDirectory(); } // For hierarchical container like CONTROL/ACC/testContainer the logs go in // $ACSDATA/logs//CONTROL/ACC so we have to remove the container name // from the passed parameter containerName std::string name=containerName; if (containerName[containerName.length()-1]=='/') { // Remove the trailing '/' name=containerName.substr(0,containerName.length()-1); } std::string contName=name.substr(0,name.rfind('/')+1); // Does the folder already exist? // If it is the case then the method returns immediately std::string temp(getLogDirectory()+contName); if (ACE_OS::access(temp.c_str(),F_OK)==0) { return temp; } // containerName can be hierarchical i.e. with multiple "/" // In that case, we must create all the intermediate folders, one for each "/" // in containerName temp=getLogDirectory(); for (unsigned int i=0; i