Commit d34a5f88 authored by Eric Cano's avatar Eric Cano
Browse files

Catching up with master branch

parents 77b34059 ae8c182e
......@@ -27,6 +27,15 @@ cmake_minimum_required (VERSION 2.6)
project(castor)
# Explicitly setting the C and C++ compiler flags for the RelWithDebInfo build
# in order to prevent the -O2 flag from being used.
#
# The CASTOR executables are not running short of CPU cycles. The extra
# effort required to debug released binaries compiled with the -O2 option is
# therefore not justified.
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")
IF(NOT CMAKE_BUILD_TYPE STREQUAL "")
# If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition and dump it in the cache
message(STATUS "Setting build type to ${CMAKE_BUILD_TYPE} as requested.")
......
/******************************************************************************
* CastorConfiguration.hpp
* castor/common/CastorConfiguration.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
......@@ -22,12 +22,11 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
// includes
#include <fstream>
#include <algorithm>
#include "castor/common/CastorConfiguration.hpp"
#include "castor/exception/NoEntry.hpp"
#include <algorithm>
#include <fstream>
#include <errno.h>
// Global configurations, indexed by original file name
......@@ -42,10 +41,13 @@ static pthread_mutex_t s_globalConfigLock = PTHREAD_MUTEX_INITIALIZER;
castor::common::CastorConfiguration&
castor::common::CastorConfiguration::getConfig(std::string fileName)
throw (castor::exception::Exception) {
// This method is non thread safe, and is protected by the s_globlaConfigLock lock
// This method is non thread safe, and is protected by the s_globalConfigLock
// lock
int rc = pthread_mutex_lock(&s_globalConfigLock);
if (0 != rc) {
castor::exception::Exception e(rc);
e.getMessage() << "Failed to get CASTOR configuration:"
" Failed to take a lock on s_globalConfigLock";
throw e;
}
// take care to catch all exceptions so that the lock is not leaked
......@@ -53,7 +55,8 @@ castor::common::CastorConfiguration::getConfig(std::string fileName)
// do we have this configuration already in cache ?
if (s_castorConfigs.end() == s_castorConfigs.find(fileName)) {
// no such configuration. Create it
s_castorConfigs.insert(std::make_pair(fileName, CastorConfiguration(fileName)));
s_castorConfigs.insert(std::make_pair(fileName,
CastorConfiguration(fileName)));
}
// we can now release the lock. Concurrent read only access is ok.
pthread_mutex_unlock(&s_globalConfigLock);
......@@ -70,11 +73,14 @@ castor::common::CastorConfiguration::getConfig(std::string fileName)
// constructor
//------------------------------------------------------------------------------
castor::common::CastorConfiguration::CastorConfiguration(std::string fileName)
throw (castor::exception::Exception) : m_fileName(fileName), m_lastUpdateTime(0) {
// create internal read write lock
throw (castor::exception::Exception) : m_fileName(fileName),
m_lastUpdateTime(0) {
// create internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) {
castor::exception::Exception e(rc);
e.getMessage() << "CastorConfiguration constructor Failed"
": Failed to create internal r/w lock";
throw e;
}
}
......@@ -82,13 +88,16 @@ castor::common::CastorConfiguration::CastorConfiguration(std::string fileName)
//------------------------------------------------------------------------------
// copy constructor
//------------------------------------------------------------------------------
castor::common::CastorConfiguration::CastorConfiguration(const CastorConfiguration & other)
throw (castor::exception::Exception): m_fileName(other.m_fileName),
m_lastUpdateTime(other.m_lastUpdateTime), m_config(other.m_config) {
castor::common::CastorConfiguration::CastorConfiguration(
const CastorConfiguration & other) throw (castor::exception::Exception):
m_fileName(other.m_fileName), m_lastUpdateTime(other.m_lastUpdateTime),
m_config(other.m_config) {
// create a new internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) {
castor::exception::Exception e(rc);
e.getMessage() << "CastorConfiguration copy constructor failed"
": Failed to create a new internal r/w lock";
throw e;
}
}
......@@ -104,7 +113,9 @@ castor::common::CastorConfiguration::~CastorConfiguration() {
//------------------------------------------------------------------------------
// assignment operator
//------------------------------------------------------------------------------
castor::common::CastorConfiguration & castor::common::CastorConfiguration::operator=(const castor::common::CastorConfiguration & other)
castor::common::CastorConfiguration &
castor::common::CastorConfiguration::operator=(
const castor::common::CastorConfiguration & other)
throw (castor::exception::Exception) {
m_fileName = other.m_fileName;
m_lastUpdateTime = other.m_lastUpdateTime;
......@@ -113,6 +124,8 @@ castor::common::CastorConfiguration & castor::common::CastorConfiguration::opera
int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) {
castor::exception::Exception e(rc);
e.getMessage() << "Assignment operator of CastorConfiguration object failed"
": Failed to create a new internal r/w lock";
throw e;
}
return *this;
......@@ -133,19 +146,26 @@ castor::common::CastorConfiguration::getConfEnt(const std::string &category,
int rc = pthread_rwlock_rdlock(&m_lock);
if (0 != rc) {
castor::exception::Exception e(rc);
e.getMessage() << "Failed to get configuration entry " << category << ":"
<< key << ": Failed to get read lock";
throw e;
}
// get the entry
try {
std::map<std::string, ConfCategory>::const_iterator catIt = m_config.find(category);
std::map<std::string, ConfCategory>::const_iterator catIt =
m_config.find(category);
if (m_config.end() == catIt) {
castor::exception::NoEntry e;
e.getMessage() << "Failed to get configuration entry " << category << ":"
<< key << ": Failed to find " << category << " category";
throw e;
}
// get the entry
ConfCategory::const_iterator entIt = catIt->second.find(key);
if (catIt->second.end() == entIt) {
castor::exception::NoEntry e;
e.getMessage() << "Failed to get configuration entry " << category << ":"
<< key << ": Failed to find " << key << " key";
throw e;
}
// release the lock
......@@ -167,6 +187,8 @@ bool castor::common::CastorConfiguration::isStale()
int rc = pthread_rwlock_rdlock(&m_lock);
if (0 != rc) {
castor::exception::Exception e(rc);
e.getMessage() << "Failed to determine if CASTOR configuration is stale"
": Failed to get read lock";
throw e;
}
try {
......@@ -192,6 +214,8 @@ void castor::common::CastorConfiguration::tryToRenewConfig()
int rc = pthread_rwlock_wrlock(&m_lock);
if (0 != rc) {
castor::exception::Exception e(rc);
e.getMessage() << "Failed to renew configuration cache"
": Failed to take write lock";
throw e;
}
// now check that we should really renew, because someone may have done it
......@@ -219,7 +243,8 @@ int castor::common::CastorConfiguration::getTimeoutNolock()
// start with the default (300s = 5mn)
int timeout = 300;
// get value from config
std::map<std::string, ConfCategory>::const_iterator catIt = m_config.find("Config");
std::map<std::string, ConfCategory>::const_iterator catIt =
m_config.find("Config");
if (m_config.end() != catIt) {
ConfCategory::const_iterator entIt = catIt->second.find("ExpirationDelay");
if (catIt->second.end() != entIt) {
......
......@@ -22,8 +22,8 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#ifndef H_CASTOR_COMMON_HPP
#define H_CASTOR_COMMON_HPP 1
#ifndef H_CASTOR_COMMON_CASTORCONFIGURATION_HPP
#define H_CASTOR_COMMON_CASTORCONFIGURATION_HPP 1
// Include Files
#include <string>
......@@ -152,4 +152,4 @@ namespace castor {
} // namespace common
} // namespace castor
#endif /* H_CASTOR_COMMON_HPP */
#endif /* H_CASTOR_COMMON_CASTORCONFIGURATION_HPP */
......@@ -22,7 +22,9 @@
*
* @author castor dev team
*****************************************************************************/
#include "Errnum.hpp"
#include "castor/exception/Errnum.hpp"
#include "h/serrno.h"
#include <errno.h>
#include <string.h>
......@@ -39,17 +41,18 @@ Errnum::Errnum(int err, std::string what):Exception("") {
}
void Errnum::ErrnumConstructorBottomHalf(const std::string & what) {
char s[1000];
/* _XOPEN_SOURCE seems not to work. */
char * errorStr = ::strerror_r(m_errnum, s, sizeof(s));
if (!errorStr) {
int new_errno = errno;
char buf[100];
if(sstrerror_r(m_errnum, buf, sizeof(buf))) {
// sstrerror_r() failed
const int new_errno = errno;
std::stringstream w;
w << "Errno=" << m_errnum << ". In addition, failed to read the corresponding error string (strerror gave errno="
w << "Errno=" << m_errnum << ". In addition, failed to read the corresponding error string (sstrerror_r gave errno="
<< new_errno << ")";
m_strerror = w.str();
} else {
m_strerror = errorStr;
// sstrerror_r() succeeded
m_strerror = buf;
}
std::stringstream w2;
if (what.size())
......
......@@ -22,8 +22,10 @@
*
* @author castor dev team
*****************************************************************************/
#include "SErrnum.hpp"
#include <serrno.h>
#include "castor/exception/SErrnum.hpp"
#include "h/serrno.h"
#include <errno.h>
#include <string.h>
......@@ -40,17 +42,18 @@ SErrnum::SErrnum(int err, std::string what):Exception("") {
}
void SErrnum::SErrnumConstructorBottomHalf(const std::string & what) {
char s[1000];
/* _XOPEN_SOURCE seems not to work. */
char * errorStr = ::sstrerror_r(m_serrnum, s, sizeof(s));
if (!errorStr) {
int new_errno = errno;
char buf[100];
if(sstrerror_r(m_serrnum, buf, sizeof(buf))) {
// sstrerror_r() failed
const int new_errno = errno;
std::stringstream w;
w << "SErrno=" << m_serrnum << ". In addition, failed to read the corresponding error string (sstrerror gave errno="
w << "SErrno=" << m_serrnum << ". In addition, failed to read the corresponding error string (sstrerror_r gave errno="
<< new_errno << ")";
m_sstrerror = w.str();
} else {
m_sstrerror = errorStr;
// sstrerror_r() succeeded
m_sstrerror = buf;
}
std::stringstream w2;
if (what.size())
......
......@@ -226,7 +226,7 @@ void castor::log::LoggerImplementation::openLog() throw() {
// MAC has has no MSG_NOSIGNAL
// but >= 10.2 comes with SO_NOSIGPIPE
int set = 1;
if(0 != setsockopt(s_logFile, SOL_SOCKET, SO_NOSIGPIPE, &set,
if(0 != setsockopt(m_logFile, SOL_SOCKET, SO_NOSIGPIPE, &set,
sizeof(int))) {
close(m_logFile);
m_logFile = -1;
......
......@@ -33,6 +33,12 @@
#include <syslog.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef __APPLE__
#include <mach/mach.h>
#endif
namespace castor {
namespace log {
......
......@@ -266,12 +266,6 @@ void castor::log::StringLogger::reducedSyslog(std::string msg)
msg[msg.length() - 1] = '\n';
}
int send_flags = 0;
#ifndef __APPLE__
// MAC has has no MSG_NOSIGNAL
// but >= 10.2 comes with SO_NOSIGPIPE
send_flags = MSG_NOSIGNAL;
#endif
// enter critical section
const int mutex_lock_rc = pthread_mutex_lock(&m_mutex);
// Do nothing if we failed to enter the critical section
......
......@@ -33,6 +33,12 @@
#include <syslog.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef __APPLE__
#include <mach/mach.h>
#endif
namespace castor {
namespace log {
......
......@@ -27,10 +27,21 @@ cmake_minimum_required (VERSION 2.6)
################################################################################
set (TAPE_LEGACYMSG_LIB_SRC_FILES
CommonMarshal.cpp
GiveOutpMsgBody.cpp
MessageHeader.cpp
RtcpDumpTapeRqstMsgBody.cpp
RtcpErrorAppendix.cpp
RtcpFileRqst.cpp
RtcpJobRqstMsgBody.cpp
RtcpMarshal.cpp
RtcpSegmentAttributes.cpp
RtcpTapeRqstMsgBody.cpp
TapeBridgeMarshal.cpp
VdqmDrvRqstMsgBody.cpp
VmgrMarshal.cpp)
VdqmMarshal.cpp
VmgrMarshal.cpp
VmgrTapeInfoMsgBody.cpp
VmgrTapeInfoRqstMsgBody.cpp)
add_library (castortapelegacymsg SHARED ${TAPE_LEGACYMSG_LIB_SRC_FILES})
CastorSetLibraryVersions (castortapelegacymsg)
target_link_libraries (castortapelegacymsg castorclient castorcommon
......
/******************************************************************************
* castor/tape/legacymsg/GiveOutpMsgBody.cpp
*
* 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 Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/legacymsg/GiveOutpMsgBody.hpp"
#include <string.h>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::legacymsg::GiveOutpMsgBody::GiveOutpMsgBody() throw() {
memset(message, '\0', sizeof(message));
}
......@@ -22,33 +22,36 @@
* @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch
*****************************************************************************/
#ifndef CASTOR_TAPE_LEGACYMSG_GIVEOUTPMSGBODY
#define CASTOR_TAPE_LEGACYMSG_GIVEOUTPMSGBODY
#ifndef CASTOR_TAPE_LEGACYMSG_GIVEOUTPMSGBODY_HPP
#define CASTOR_TAPE_LEGACYMSG_GIVEOUTPMSGBODY_HPP 1
#include "h/Castor_limits.h"
#include "h/Cuuid.h"
#include <stdint.h>
namespace castor {
namespace tape {
namespace castor {
namespace tape {
namespace legacymsg {
/**
* The message body of a dump tape information message.
*/
struct GiveOutpMsgBody {
/**
* The message body of a dump tape information message.
* The dump tape message string.
*/
struct GiveOutpMsgBody {
char message[CA_MAXLINELEN+1];
/**
* The dump tape message string.
*/
char message[CA_MAXLINELEN+1];
/**
* Constructor.
*
* Sets the string member variable to the empty string.
*/
GiveOutpMsgBody() throw();
}; // struct GiveOutpMsgBody
}; // struct GiveOutpMsgBody
} // namespace legacymsg
} // namespace tape
} // namespace castor
#endif // CASTOR_TAPE_LEGACYMSG_GIVEOUTPMSGBODY
#endif // CASTOR_TAPE_LEGACYMSG_GIVEOUTPMSGBODY_HPP
/******************************************************************************
* castor/tape/legacymsg/MessageHeader.cpp
*
* 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 Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/legacymsg/MessageHeader.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::legacymsg::MessageHeader::MessageHeader() throw():
magic(0),
reqType(0),
lenOrStatus(0) {
}
/******************************************************************************
* castor/tape/legacymsg/MessageHeader.hpp
* castor/tape/legacymsg/MessageHeader.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
......@@ -22,44 +22,47 @@
* @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch
*****************************************************************************/
#ifndef CASTOR_TAPE_LEGACYMSG_MESSAGEHEADER
#define CASTOR_TAPE_LEGACYMSG_MESSAGEHEADER
#include "h/Castor_limits.h"
#ifndef CASTOR_TAPE_LEGACYMSG_MESSAGEHEADER_HPP
#define CASTOR_TAPE_LEGACYMSG_MESSAGEHEADER_HPP 1
#include <stdint.h>
#include <string>
namespace castor {
namespace tape {
namespace castor {
namespace tape {
namespace legacymsg {
/**
* A message header
*/
struct MessageHeader {
/**
* A message header
* The magic number of the message.
*/
struct MessageHeader {
/**
* The magic number of the message.
*/
uint32_t magic;
uint32_t magic;
/**
* The request type of the message.
*/
uint32_t reqType;
/**
* The request type of the message.
*/
uint32_t reqType;
/**
* The length of the message body in bytes if this is the header of any
* message other than an acknowledge message. If this is the header of
* an acknowledge message then there is no message body and this field is
* used to pass the status of the acknowledge.
*/
uint32_t lenOrStatus;
};
/**
* The length of the message body in bytes if this is the header of any
* message other than an acknowledge message. If this is the header of
* an acknowledge message then there is no message body and this field is
* used to pass the status of the acknowledge.
*/
uint32_t lenOrStatus;
/**
* Constructor.
*
* Sets all integer member-variables to 0.
*/
MessageHeader() throw();
}; // struct MessageHeader
} // namespace legacymsg
} // namespace tape
} // namespace castor
#endif // CASTOR_TAPE_LEGACYMSG_MESSAGEHEADER
#endif // CASTOR_TAPE_LEGACYMSG_MESSAGEHEADER_HPP
/******************************************************************************
* castor/tape/legacymsg/RtcpDumpTapeRqstMsgBody.cpp
*
* 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 Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/legacymsg/RtcpDumpTapeRqstMsgBody.hpp"
castor::tape::legacymsg::RtcpDumpTapeRqstMsgBody::RtcpDumpTapeRqstMsgBody()
throw():
maxBytes(0),
blockSize(0),
convert_noLongerUsed(0),
tapeErrAction(0),
startFile(0),
maxFiles(0),
fromBlock(0),
toBlock(0) {
}
/******************************************************************************
* castor/tape/legacymsg/RtcpDumpTapeRqstMsgBody.hpp
* castor/tape/legacymsg/RtcpDumpTapeRqstMsgBody.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
......@@ -22,31 +22,38 @@
* @author Nicola.Bessone@cern.ch Steven.Murray@cern.ch
*****************************************************************************/
#ifndef CASTOR_TAPE_LEGACYMSG_RTCPDUMPTAPERQSTMSGBODY
#define CASTOR_TAPE_LEGACYMSG_RTCPDUMPTAPERQSTMSGBODY
#ifndef CASTOR_TAPE_LEGACYMSG_RTCPDUMPTAPERQSTMSGBODY_HPP
#define CASTOR_TAPE_LEGACYMSG_RTCPDUMPTAPERQSTMSGBODY_HPP 1
#include <stdint.h>
namespace castor {
namespace tape {
namespace castor {
namespace tape {
namespace legacymsg {
/**
* An RTCP dump tape request message.
*/
struct RtcpDumpTapeRqstMsgBody {
int32_t maxBytes;
int32_t blockSize;
int32_t convert_noLongerUsed;
int32_t tapeErrAction;