Commit 5809f4e3 authored by Eric Cano's avatar Eric Cano
Browse files

Removing dependancies on externally compiled CASTOR packages from CTA:

Removed linking information for external libraries from CASTOR.
Started to re-import necessary files from CASTOR.
Edited files from CASTOR to replace usage of the old Cxxx compatibility layer (this was for multi-system
compatibility at the time.
parent af3658cb
......@@ -42,21 +42,6 @@ ELSE(DEFINED PackageOnly)
message (STATUS "Already set: COMPILE_PACKAGING=${COMPILE_PACKAGING}")
endif (NOT DEFINED COMPILE_PACKAGING)
# With the exception of shared-library plugins, the CASTOR rpms only install the
# /usr/lib64/libcastor*.so symbolic links for libraries used by end-user
# developers. Therefore the locations of the internal CASTOR libraries required
# by tapeserved and not by end-user developers need to be imported into cmake.
add_library(castorlegacymsg SHARED IMPORTED)
set_target_properties(castorlegacymsg PROPERTIES
IMPORTED_LOCATION /usr/lib64/libcastorlegacymsg.so.2.1)
add_library(castorserver SHARED IMPORTED)
set_target_properties(castorserver PROPERTIES
IMPORTED_LOCATION /usr/lib64/libcastorserver.so.2.1)
add_library(castortapegatewayprotocol SHARED IMPORTED)
set_target_properties(castortapegatewayprotocol PROPERTIES
IMPORTED_LOCATION /usr/lib64/libcastortapegatewayprotocol.so.2.1)
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.")
......@@ -119,10 +104,5 @@ configure_file(tests/valgrind.suppr tests/valgrind.suppr COPYONLY)
add_custom_target(test tests/unittests
#
COMMAND valgrind --track-fds=yes --leak-check=full --demangle=yes --gen-suppressions=all --show-reachable=yes --error-exitcode=1 --suppressions=tests/valgrind.suppr tests/unittests
#COMMAND test/castorThreadedUnitTests
#COMMAND valgrind --track-fds=yes --leak-check=full --show-reachable=yes --error-exitcode=1 test/castorThreadedUnitTests
#COMMAND valgrind --tool=helgrind -v --demangle=no --conflict-cache-size=30000000 --error-exitcode=1 test/castorThreadedUnitTests
#COMMAND test/castorMultiprocessUnitTests
#COMMAND valgrind --tool=helgrind --error-exitcode=1 test/castorMultiprocessUnitTests
DEPENDS tests/unittests #test/castorThreadedUnitTests test/castorMultiprocessUnitTests test/castorThreadedUnitTests.supp
DEPENDS tests/unittests tests/valgrind.suppr
COMMENT "Running unit tests" VERBATIM)
......@@ -9,7 +9,7 @@ target_link_libraries (cta ${XROOTD_XRDCL_LIB} ctacommon cryptopp)
include_directories (${CMAKE_SOURCE_DIR}/tapeserver/)
add_executable (ctaAddAdminUser CTAAddAdminUser.cpp )
target_link_libraries (ctaAddAdminUser ctacommon castorserver ctalog
target_link_libraries (ctaAddAdminUser ctacommon ctalog
castorcommon ctautils protobuf ctascheduler ctanameserver)
install (TARGETS cta ctaAddAdminUser DESTINATION usr/bin)
......
......@@ -3,7 +3,12 @@ cmake_minimum_required (VERSION 2.6)
include_directories(${PROJECT_SOURCE_DIR}/tapeserver)
include_directories(${PROJECT_SOURCE_DIR}/tapeserver/h)
add_library (ctaio
io.cpp
IpAndPort.cpp
StreamAddress.cpp)
add_library (ctaiounittests SHARED
IoTest.cpp)
target_link_libraries (ctaiounittests
castorclient)
ctaio)
/******************************************************************************
*
* 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
*****************************************************************************/
// Include Files
#include "StreamAddress.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::io::StreamAddress::StreamAddress(castor::io::biniostream& stream,
const std::string cnvSvcName,
const unsigned int cnvSvcType) :
BaseAddress(), m_stream(stream) {
setCnvSvcName(cnvSvcName);
setCnvSvcType(cnvSvcType);
}
/******************************************************************************
*
* 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 Files
#include "castor/io/biniostream.h"
#include "castor/BaseAddress.hpp"
#include "castor/Constants.hpp"
namespace castor {
namespace io {
/**
* An address containing a reference to a binary stream
*/
class StreamAddress : public BaseAddress {
public:
/**
* constructor
* @param stream the stream where to put the data
* @param cnvSvcName the conversion service able to deal with this address
* In this later case, the type will be deduced from the id.
*/
StreamAddress(biniostream& stream,
const std::string cnvSvcName,
const unsigned int cnvSvcType);
/*
* destructor
*/
virtual ~StreamAddress() throw() {}
/**
* gets the id of this address
*/
virtual biniostream& stream() const { return m_stream; }
private:
/**
* the id of this address
*/
biniostream& m_stream;
};
} // end of namespace io
} // end of namespace castor
/******************************************************************************
*
* 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 <sstream>
#include "osdep.h"
#include "castor/exception/OutOfMemory.hpp"
#include <string.h>
#include <stdlib.h>
#ifdef __APPLE__
#define __bswap_16(x) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
#define __bswap_32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#else
#include <byteswap.h>
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
/* The host byte order is the same as the "inverted network byte order",
which is the reference used by Castor production setup,
so these functions are all just identity. */
#define intohl(x) (x)
#define intohs(x) (x)
#define htoinl(x) (x)
#define htoins(x) (x)
#else
#if __BYTE_ORDER == __BIG_ENDIAN
#define intohl(x) __bswap_32 (x)
#define intohs(x) __bswap_16 (x)
#define htoinl(x) __bswap_32 (x)
#define htoins(x) __bswap_16 (x)
#endif
#endif
namespace castor {
namespace io {
/**
* A binary stream based on stringstream
*/
class biniostream : public std::stringstream {
public:
biniostream(std::string& s) : std::stringstream(s) {}
biniostream() : std::stringstream() {}
biniostream& operator<< (char c) {
write((char*)&c, sizeof(char));
return *this;
}
biniostream& operator<< (unsigned char c) {
write((char*)&c, sizeof(unsigned char));
return *this;
}
biniostream& operator<< (signed char c) {
write((char*)&c, sizeof(signed char));
return *this;
}
biniostream& operator<< (int i) {
i = htoinl((unsigned int)i);
write((char*)&i, sizeof(int));
return *this;
}
biniostream& operator<< (unsigned int i) {
i = htoinl(i);
write((char*)&i, sizeof(unsigned int));
return *this;
}
biniostream& operator<< (short s) {
s = htoins((unsigned short)s);
write((char*)&s, sizeof(short));
return *this;
}
biniostream& operator<< (unsigned short s) {
s = htoins(s);
write((char*)&s, sizeof(unsigned short));
return *this;
}
biniostream& operator<< (long l) {
l = htoinl((unsigned long)l);
write((char*)&l, LONGSIZE);
return *this;
}
biniostream& operator<< (unsigned long l) {
l = htoinl(l);
write((char*)&l, LONGSIZE);
return *this;
}
biniostream& operator<< (const char* cp) {
int len = strlen(cp)+1;
write((char*)&len, sizeof(int));
write(cp,len);
return *this;
}
biniostream& operator<< (bool b) {
write((char*)&b, sizeof(bool));
return *this;
}
biniostream& operator<< (float f) {
write((char*)&f, sizeof(float));
return *this;
}
biniostream& operator<< (double d) {
write((char*)&d, sizeof(double));
return *this;
}
biniostream& operator<< (long double d) {
write((char*)&d, sizeof(long double));
return *this;
}
biniostream& operator<< (u_signed64 d) {
unsigned long n = (unsigned long)d; // Least significant part first
write((char*)&n, LONGSIZE);
n = htoinl((unsigned long)(d >> 32));
write((char*)&n, LONGSIZE);
return *this;
}
biniostream& operator<< (signed64 d) {
unsigned long n = (unsigned long)d; // Least significant part first
write((char*)&n, LONGSIZE);
n = htoinl((unsigned long)(d >> 32));
write((char*)&n, LONGSIZE);
return *this;
}
////////////////////////////////////////////////////////////
//
// Input Binary Operators
//
////////////////////////////////////////////////////////////
biniostream& operator>> (char& c) {
read((char*)&c, sizeof(char));
return *this;
}
biniostream& operator>> (unsigned char& c) {
read((char*)&c, sizeof(unsigned char));
return *this;
}
biniostream& operator>> (signed char& c) {
read((char*)&c, sizeof(signed char));
return *this;
}
biniostream& operator>> (int& i) {
read((char*)&i, sizeof(int));
i = intohl((unsigned int)i);
return *this;
}
biniostream& operator>> (unsigned int& i) {
read((char*)&i, sizeof(unsigned int));
i = intohl(i);
return *this;
}
biniostream& operator>> (short& s) {
read((char*)&s, sizeof(short));
s = intohs((unsigned short)s);
return *this;
}
biniostream& operator>> (unsigned short& s) {
read((char*)&s, sizeof(unsigned short));
s = intohs(s);
return *this;
}
biniostream& operator>> (long& l) {
l = 0;
read((char*)&l, LONGSIZE);
l = intohl((unsigned long)l);
if (((*((char*)(&l)+3)) & (1 << (7-(0)%8))) && (sizeof(long)-LONGSIZE > 0)) {
(void) memset((char *)&l+4, 255, sizeof(long)-LONGSIZE);
}
return *this;
}
biniostream& operator>> (unsigned long& l) {
l = 0;
read((char*)&l, LONGSIZE);
l = intohl(l);
return *this;
}
biniostream& operator>> (char* cp) {
int len;
read((char*)&len, sizeof(int));
read(cp,len);
return *this;
}
biniostream& operator>> (bool& b) {
read((char*)&b, sizeof(bool));
return *this;
}
biniostream& operator>> (float& f) {
read((char*)&f, sizeof(float));
return *this;
}
biniostream& operator>> (double& d) {
read((char*)&d, sizeof(double));
return *this;
}
biniostream& operator>> (long double& d) {
read((char*)&d, sizeof(long double));
return *this;
}
biniostream& operator>> (u_signed64& d) {
//read((char*)&d, sizeof(u_signed64));
unsigned int n;
read((char*)&n, LONGSIZE);
d = intohl((unsigned int)n); // Least Significant part first
read((char*)&n, LONGSIZE);
n = intohl((unsigned int)n);
d += (u_signed64)n << 32;
return *this;
}
biniostream& operator>> (signed64& d) {
//read((char*)&d, sizeof(signed64));
unsigned int n;
read((char*)&n, LONGSIZE);
d = intohl((unsigned int)n); // Least Significant part first
read((char*)&n, LONGSIZE);
n = intohl((unsigned int)n);
d += (u_signed64)n << 32;
return *this;
}
};
} // end of namespace io
} // end of namespace castor
template <class charT, class traits, class Allocator>
castor::io::biniostream&
operator>> (castor::io::biniostream& os,
std::basic_string <charT, traits, Allocator>& s) {
s.erase();
int len;
os >> len;
char* buf = (char*)malloc(len+1);
if(0 == buf) {
castor::exception::OutOfMemory e;
e.getMessage() << "Failed to allocate buffer of length " << len;
throw e;
}
os.read(buf, len);
buf[len] = 0;
s += buf;
free(buf);
return os;
}
template <class charT, class traits, class Allocator>
castor::io::biniostream &
operator<< (castor::io::biniostream& os,
const std::basic_string <charT, traits, Allocator>& s) {
int len = s.length();
os << len;
os.write(s.data(), len);
return os;
}
......@@ -27,8 +27,9 @@
#include "castor/io/io.hpp"
#include "castor/utils/SmartFd.hpp"
#include "castor/utils/utils.hpp"
#include "serrno.h"
#include "net.h"
#include "common/Utils.hpp"
#include "common/Timer.hpp"
#include "common/exception/Errnum.hpp"
#include <arpa/inet.h>
#include <fcntl.h>
......@@ -38,6 +39,7 @@
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/poll.h>
#include <time.h>
#include <list>
......@@ -129,10 +131,9 @@ int castor::io::createListenerSock(
// Create a socket
utils::SmartFd sock(socket(PF_INET, SOCK_STREAM, IPPROTO_TCP));
if(sock.get() < 0) {
char errBuf[100];
sstrerror_r(errno, errBuf, sizeof(errBuf));
castor::exception::Exception ex;
ex.getMessage() << ": Failed to create socket: " << errBuf;
ex.getMessage() << ": Failed to create socket: "
<< cta::Utils::errnoToString(errno);
throw ex;
}
......@@ -141,8 +142,6 @@ int castor::io::createListenerSock(
int reuseaddrOptval = 1;
if(0 > setsockopt(sock.get(), SOL_SOCKET, SO_REUSEADDR,
(char *)&reuseaddrOptval, sizeof(reuseaddrOptval))) {
char errBuf[100];
sstrerror_r(errno, errBuf, sizeof(errBuf));
castor::exception::Exception ex;
ex.getMessage() <<
": Failed to set socket option"
......@@ -150,7 +149,7 @@ int castor::io::createListenerSock(
" level=SOL_SOCKET"
" optname=SO_REUSEADDR"
" optval=" << reuseaddrOptval <<
": " << errBuf;
": " << cta::Utils::errnoToString(errno);
throw ex;
}
}
......@@ -179,13 +178,11 @@ int castor::io::createListenerSock(
// Mark the socket as being a listener
if(listen(sock.get(), LISTENBACKLOG) < 0) {
char errBuf[100];
sstrerror_r(errno, errBuf, sizeof(errBuf));
castor::exception::Exception ex;
ex.getMessage() <<
": Failed to mark socket as being a listener"
": listenSocketFd=" << sock.get() <<
": " << errBuf;
": " << cta::Utils::errnoToString(errno);
throw ex;
}
......@@ -201,13 +198,11 @@ int castor::io::createListenerSock(
// Else throw an exception
} else {
char errBuf[100];
sstrerror_r(bindErrno, errBuf, sizeof(errBuf));
castor::exception::Exception ex;
ex.getMessage() <<
": Failed to bind listener socket"
": listenSocketFd=" << sock.get() <<
": " << errBuf;
": " << cta::Utils::errnoToString(bindErrno);
throw ex;
}
}
......@@ -280,9 +275,7 @@ int castor::io::acceptConnection(const int listenSocketFd)
if(savedErrno == EINVAL) {
reason << ": Socket is not listening for connections";
} else {
char errBuf[100];
sstrerror_r(savedErrno, errBuf, sizeof(errBuf));
reason << ": " << errBuf;
reason << ": " << cta::Utils::errnoToString(savedErrno);
}
castor::exception::Exception ex;
......@@ -344,11 +337,9 @@ int castor::io::acceptConnection(const int listenSocketFd,
throw ex;
} else {
char errBuf[100];
sstrerror_r(selectErrno, errBuf, sizeof(errBuf));
castor::exception::Exception ex;
ex.getMessage() << "Failed to accept connection: Select failed: " <<
errBuf;
cta::Utils::errnoToString(selectErrno);
throw ex;
}
break;
......@@ -379,9 +370,7 @@ int castor::io::acceptConnection(const int listenSocketFd,
if(acceptErrno == EINVAL) {
reason << ": Socket is not listening for connections";
} else {
char errBuf[100];
sstrerror_r(acceptErrno, errBuf, sizeof(errBuf));
reason << ": " << errBuf;
reason << ": " << cta::Utils::errnoToString(acceptErrno);
}
castor::exception::Exception ex;
......@@ -412,11 +401,9 @@ castor::io::IpAndPort castor::io::getSockIpPort(
socklen_t addressLen = sizeof(address);
if(getsockname(socketFd, (struct sockaddr*)&address, &addressLen) < 0) {
char errBuf[100];
sstrerror_r(errno, errBuf, sizeof(errBuf));
castor::exception::Exception ex;
ex.getMessage() << "Failed to get socket name: socketFd=" << socketFd <<
": " << errBuf;
": " << cta::Utils::errnoToString(errno);
throw ex;
}
......@@ -443,11 +430,9 @@ castor::io::IpAndPort castor::io::getPeerIpPort(
socklen_t addressLen = sizeof(address);