Commit feeda5c6 authored by Steven Murray's avatar Steven Murray Committed by Victor Kotlyar
Browse files

Simply replaced CASTOR's Exception class with that of CTA

parent 879c4268
......@@ -26,9 +26,9 @@
#include "castor/Constants.hpp"
#include "castor/Services.hpp"
#include "castor/BaseObject.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/server/Mutex.hpp"
#include "castor/server/MutexLocker.hpp"
#include "common/exception/Exception.hpp"
//------------------------------------------------------------------------------
// static values initialization
......@@ -82,7 +82,7 @@ castor::Services* castor::BaseObject::services()
const int rc = pthread_setspecific(s_servicesKey, services);
if(0 != rc) {
delete services;
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Error caught in call to pthread_setspecific";
throw e;
}
......@@ -102,7 +102,7 @@ void castor::BaseObject::resetServices()
delete services();
const int rc = pthread_setspecific(s_servicesKey, NULL);
if(0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Failed to reset the thread's servicesKey to NULL after delete";
throw e;
}
......
......@@ -25,7 +25,7 @@
#pragma once
// Include Files
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
#include <pthread.h>
namespace castor {
......@@ -89,7 +89,7 @@ namespace castor {
pthreadKey() {
int rc = pthread_key_create(&m_key, NULL);
if (rc != 0) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Error caught in call to pthread_key_create (from castor::BaseObject::pthreadKey::pthreadKey";
throw e;
}
......
......@@ -27,7 +27,7 @@
// Include Files
#include "castor/IService.hpp"
#include "castor/Constants.hpp"
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
#include <vector>
namespace castor {
......
......@@ -31,7 +31,7 @@
#include "IAddress.hpp"
#include "IObject.hpp"
#include "ICnvSvc.hpp"
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
//-----------------------------------------------------------------------------
// Constructor
......@@ -65,7 +65,7 @@ castor::IService* castor::Services::service(const std::string name,
const ISvcFactory* fac = castor::Factories::instance()->factory(id);
// if no factory is available, complain
if (0 == fac) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "No factory found for object type " << id;
throw e;
}
......@@ -73,7 +73,7 @@ castor::IService* castor::Services::service(const std::string name,
IService* svc = fac->instantiate(name);
// if the service was not instantiated, complain
if (0 == svc) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "No service found for service " << name;
throw e;
} else {
......@@ -160,7 +160,7 @@ castor::Services::cnvSvcFromAddress(castor::IAddress* address)
{
// check address
if (0 == address) {
castor::exception::Exception ex;
cta::exception::Exception ex;
ex.getMessage() << "No appropriate converter for a null address !";
throw ex;
}
......@@ -168,7 +168,7 @@ castor::Services::cnvSvcFromAddress(castor::IAddress* address)
castor::ICnvSvc *cnvSvc =
cnvService(address->cnvSvcName(), address->cnvSvcType());
if (0 == cnvSvc) {
castor::exception::Exception ex;
cta::exception::Exception ex;
ex.getMessage() << "No conversion service with name "
<< address->cnvSvcName() << " and type "
<< address->cnvSvcType();
......
......@@ -27,7 +27,7 @@
//Include Files
#include <vector>
#include <map>
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
namespace castor {
......
......@@ -60,7 +60,7 @@ std::string castor::System::getHostName()
if (EINVAL != errno &&
ENAMETOOLONG != errno) {
free(hostname);
castor::exception::Exception e(errno);
cta::exception::Exception e;
e.getMessage() << "gethostname error";
throw e;
}
......@@ -70,7 +70,7 @@ std::string castor::System::getHostName()
char *hostnameLonger = (char*) realloc(hostname, len);
if (0 == hostnameLonger) {
free(hostname);
castor::exception::Exception e(ENOMEM);
cta::exception::Exception e;
e.getMessage() << "Could not allocate memory for hostname";
throw e;
......@@ -83,7 +83,7 @@ std::string castor::System::getHostName()
if (EINVAL != errno &&
ENAMETOOLONG != errno) {
free(hostname);
castor::exception::Exception e(errno);
cta::exception::Exception e;
e.getMessage() << "Could not get hostname"
<< strerror(errno);
throw e;
......@@ -105,12 +105,12 @@ int castor::System::porttoi(char* str)
errno = 0;
int iport = strtoul(str, &dp, 0);
if (*dp != 0) {
castor::exception::Exception e(errno);
cta::exception::Exception e;
e.getMessage() << "Bad port value." << std::endl;
throw e;
}
if ((iport > 65535) || (iport < 0)) {
castor::exception::Exception e(errno);
cta::exception::Exception e;
e.getMessage()
<< "Invalid port value : " << iport
<< ". Must be < 65535 and > 0." << std::endl;
......@@ -138,27 +138,27 @@ void castor::System::switchToCastorSuperuser()
// Get information on generic stage account from password file
if ((stage_passwd = getpwnam(STAGERSUPERUSER)) == NULL) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "Castor super user " << STAGERSUPERUSER
<< " not found in password file";
throw e;
}
// verify existence of its primary group id
if (getgrgid(stage_passwd->pw_gid) == NULL) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "Castor super user group does not exist";
throw e;
}
// Get information on generic stage account from group file
if ((stage_group = getgrnam(STAGERSUPERGROUP)) == NULL) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "Castor super user group " << STAGERSUPERGROUP
<< " not found in group file";
throw e;
}
// Verify consistency
if (stage_group->gr_gid != stage_passwd->pw_gid) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "Inconsistent password file. The group of the "
<< "castor superuser " << STAGERSUPERUSER
<< " should be " << stage_group->gr_gid
......@@ -168,25 +168,25 @@ void castor::System::switchToCastorSuperuser()
}
// Undo group privilege
if (setregid (egid, rgid) < 0) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "Unable to undo group privilege";
throw e;
}
// Undo user privilege
if (setreuid (euid, ruid) < 0) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "Unable to undo user privilege";
throw e;
}
// set the effective privileges to superuser
if (setegid(stage_passwd->pw_gid) < 0) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "Unable to set group privileges of Castor Superuser. "
<< "You may want to check that the suid bit is set properly";
throw e;
}
if (seteuid(stage_passwd->pw_uid) < 0) {
castor::exception::Exception e;
cta::exception::Exception e;
e.getMessage() << "Unable to set privileges of Castor Superuser.";
throw e;
}
......
......@@ -26,7 +26,7 @@
// Include Files
#include <string>
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
namespace castor {
......
......@@ -44,7 +44,7 @@ castor::common::CastorConfiguration::getConfig(std::string fileName)
// lock
int rc = pthread_mutex_lock(&s_globalConfigLock);
if (0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Failed to get CASTOR configuration:"
" Failed to take a lock on s_globalConfigLock";
throw e;
......@@ -77,7 +77,7 @@ castor::common::CastorConfiguration::CastorConfiguration(std::string fileName)
// create internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "CastorConfiguration constructor Failed"
": Failed to create internal r/w lock";
throw e;
......@@ -94,7 +94,7 @@ castor::common::CastorConfiguration::CastorConfiguration(
// create a new internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "CastorConfiguration copy constructor failed"
": Failed to create a new internal r/w lock";
throw e;
......@@ -122,7 +122,7 @@ castor::common::CastorConfiguration &
// create a new internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Assignment operator of CastorConfiguration object failed"
": Failed to create a new internal r/w lock";
throw e;
......@@ -143,7 +143,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString(
// get read lock
int rc = pthread_rwlock_rdlock(&m_lock);
if (0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Failed to get configuration entry " << category << ":"
<< key << ": Failed to get read lock";
throw e;
......@@ -178,7 +178,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString(
}
// Unlock and return default
pthread_rwlock_unlock(&m_lock);
} catch (castor::exception::Exception ex) {
} catch (cta::exception::Exception ex) {
// exception caught : Unlock and return default
pthread_rwlock_unlock(&m_lock);
// log the exception
......@@ -210,7 +210,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString(
// get read lock
int rc = pthread_rwlock_rdlock(&m_lock);
if (0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Failed to get configuration entry " << category << ":"
<< key << ": Failed to get read lock";
throw e;
......@@ -261,7 +261,7 @@ bool castor::common::CastorConfiguration::isStale()
// get read lock
int rc = pthread_rwlock_rdlock(&m_lock);
if (0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Failed to determine if CASTOR configuration is stale"
": Failed to get read lock";
throw e;
......@@ -288,7 +288,7 @@ void castor::common::CastorConfiguration::tryToRenewConfig()
// we should probably renew. First take the write lock.
int rc = pthread_rwlock_wrlock(&m_lock);
if (0 != rc) {
castor::exception::Exception e(rc);
cta::exception::Exception e;
e.getMessage() << "Failed to renew configuration cache"
": Failed to take write lock";
throw e;
......@@ -343,7 +343,7 @@ void castor::common::CastorConfiguration::renewConfigNolock()
// failure
std::ifstream file(m_fileName.c_str());
if(file.fail()) {
castor::exception::Exception ex(EIO);
cta::exception::Exception ex;
ex.getMessage() << __FUNCTION__ << " failed"
": Failed to open file"
": m_fileName=" << m_fileName;
......
......@@ -23,10 +23,10 @@
#pragma once
#include "castor/exception/Exception.hpp"
#include "castor/exception/NoEntry.hpp"
#include "castor/log/Logger.hpp"
#include "castor/utils/utils.hpp"
#include "common/exception/Exception.hpp"
#include <string>
#include <map>
......@@ -141,7 +141,7 @@ namespace castor {
std::string strValue;
try {
strValue = getConfEntString(category, key);
} catch(castor::exception::Exception &ex) {
} catch(cta::exception::Exception &ex) {
if(NULL != log) {
std::list<log::Param> params = {
log::Param("category", category),
......
......@@ -29,7 +29,7 @@
// -----------------------------------------------------------------------------
castor::exception::AcceptConnectionInterrupted::AcceptConnectionInterrupted(
const time_t remainingTime) throw() :
castor::exception::Exception(666),
cta::exception::Exception(),
m_remainingTime(remainingTime) {
// Do nothing
......
......@@ -23,7 +23,7 @@
#pragma once
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
#include <sys/types.h>
......@@ -33,7 +33,7 @@ namespace exception {
/**
* castor::io::acceptConnection() was interrupted.
*/
class AcceptConnectionInterrupted : public castor::exception::Exception {
class AcceptConnectionInterrupted : public cta::exception::Exception {
public:
......
......@@ -28,5 +28,5 @@
// Constructor
// -----------------------------------------------------------------------------
castor::exception::BadAlloc::BadAlloc():
castor::exception::Exception(666) {
cta::exception::Exception() {
}
......@@ -23,14 +23,14 @@
#pragma once
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
namespace castor { namespace exception {
/**
* BadAlloc.
*/
class BadAlloc : public castor::exception::Exception {
class BadAlloc : public cta::exception::Exception {
public:
......
......@@ -28,5 +28,5 @@
// Constructor
// -----------------------------------------------------------------------------
castor::exception::CommandLineNotParsed::CommandLineNotParsed():
castor::exception::Exception(666) {
cta::exception::Exception() {
}
......@@ -23,14 +23,14 @@
#pragma once
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
namespace castor { namespace exception {
/**
* CommandLineNotParsed.
*/
class CommandLineNotParsed : public castor::exception::Exception {
class CommandLineNotParsed : public cta::exception::Exception {
public:
......
......@@ -23,14 +23,14 @@
#pragma once
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
namespace castor { namespace exception {
/**
* Failed to dismount volume.
*/
class DismountFailed : public castor::exception::Exception {
class DismountFailed : public cta::exception::Exception {
public:
......
......@@ -23,16 +23,16 @@
#pragma once
#include "castor/exception/Exception.hpp"
#include "common/exception/Exception.hpp"
#include <string>
namespace castor {
namespace exception {
class EndOfFile: public castor::exception::Exception {
class EndOfFile: public cta::exception::Exception {
public:
EndOfFile(const std::string & w): castor::exception::Exception(w) {}
EndOfFile(const std::string & w): cta::exception::Exception(w) {}
virtual ~EndOfFile() throw() {}
};
}}
\ No newline at end of file
}}
......@@ -24,11 +24,11 @@
#pragma once
#include "Exception.hpp"
#include "common/exception/Exception.hpp"
namespace castor {
namespace exception {
class Errnum: public castor::exception::Exception {
class Errnum: public cta::exception::Exception {
public:
Errnum(std::string what = "");
Errnum (int err, std::string what = "");
......
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#define _XOPEN_SOURCE 600
#include "castor/exception/Exception.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::exception::Exception::Exception(int se, std::string context, bool embedBacktrace) :
m_message(context), m_serrno(se), m_backtrace(!embedBacktrace) {}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::exception::Exception::Exception(std::string context, bool embedBacktrace) :
m_message(context), m_serrno(666), m_backtrace(!embedBacktrace) {}
//------------------------------------------------------------------------------
// copy constructor
//------------------------------------------------------------------------------
castor::exception::Exception::Exception(
const castor::exception::Exception& rhs):
std::exception() {
m_serrno = rhs.m_serrno;
m_message << rhs.m_message.str();
m_backtrace = rhs.m_backtrace;
}
//------------------------------------------------------------------------------
// assignment operator
//------------------------------------------------------------------------------
castor::exception::Exception& castor::exception::Exception::operator=(
const castor::exception::Exception &rhs) {
m_serrno = rhs.m_serrno;
m_message << rhs.m_message.str();
return *this;
}
//------------------------------------------------------------------------------
// what operator
//------------------------------------------------------------------------------
const char * castor::exception::Exception::what() const throw () {
m_what = getMessageValue();
m_what += "\n";
m_what += (std::string) m_backtrace;
return m_what.c_str();
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::exception::Exception::~Exception() throw() {}
//------------------------------------------------------------------------------
// setWhat
//------------------------------------------------------------------------------
void castor::exception::Exception::setWhat(const std::string& what) {
getMessage() << what;
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "tapeserver/castor/exception/Backtrace.hpp"
#include <exception>
#include <sstream>
namespace castor {
namespace exception {
/**
* class Exception
* A simple exception used for error handling in castor
*/
class Exception: public std::exception {
public:
/**
* Empty Constructor
* @param serrno the serrno code of the corresponding C error
* @param context optional context string added to the message
* at initialisation time.
* @param embedBacktrace whether to embed a backtrace of where the
* exception was throw in the message
*/
Exception(int se, std::string context="", bool embedBacktrace=true);
/**
* Empty Constructor with implicit serrno = SEINERNAL;
* @param context optional context string added to the message
* at initialisation time.
* @param embedBacktrace whether to embed a backtrace of where the
* exception was throw in the message