Commit 9360c3ec authored by Steven Murray's avatar Steven Murray
Browse files

Removed utils.[ch]pp from tapeserver/castor

parent ecd97ced
......@@ -216,7 +216,6 @@ Unit tests and system tests with virtual tape drives
%attr(0755,root,root) %{_libdir}/libctatapeserverdriveunittests.so
%attr(0755,root,root) %{_libdir}/libctatapeserverfileunittests.so
%attr(0755,root,root) %{_libdir}/libctatapeserverscsiunittests.so
%attr(0755,root,root) %{_libdir}/libctautilsunittests.so
%attr(0755,root,root) %{_libdir}/libctadaemonunittests.so
%attr(0755,root,root) %{_libdir}/libctamediachangerunittests.so
%attr(0755,root,root) %{_bindir}/cta-systemTests
......
......@@ -24,7 +24,6 @@
#pragma once
#include "castor/messages/Header.pb.h"
#include "tapeserver/castor/utils/utils.hpp"
#include <google/protobuf/message.h>
#include <string>
......
......@@ -31,7 +31,6 @@
#include "castor/tape/tapeserver/daemon/TpconfigLine.hpp"
#include "castor/tape/tapeserver/daemon/TaskWatchDog.hpp"
#include "castor/tape/tapeserver/drive/FakeDrive.hpp"
#include "castor/utils/utils.hpp"
#include "mediachanger/AcsProxyDummy.hpp"
#include "mediachanger/MediaChangerFacade.hpp"
#include "mediachanger/MmcProxyDummy.hpp"
......
......@@ -30,7 +30,6 @@
#include "tapeserver/daemon/TapedProxy.hpp"
#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"
#include "common/Timer.hpp"
#include "castor/utils/utils.hpp"
#include "castor/tape/tapeserver/daemon/TapeSessionStats.hpp"
#include <map>
......
......@@ -23,7 +23,6 @@ include_directories(/usr/include/shift)
include_directories(${PROJECT_SOURCE_DIR}/tapeserver)
set (UTILS_LIB_SRC_FILES
utils.cpp
../common/CastorConfiguration.cpp)
add_library (ctautils SHARED ${UTILS_LIB_SRC_FILES})
......@@ -31,8 +30,3 @@ add_library (ctautils SHARED ${UTILS_LIB_SRC_FILES})
target_link_libraries(ctautils)
install(TARGETS ctautils DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
add_library (ctautilsunittests SHARED
UtilsTest.cpp)
install(TARGETS ctautilsunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
/******************************************************************************
*
* 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 "castor/utils/utils.hpp"
#include "h/Castor_limits.h"
#include <errno.h>
#include <gtest/gtest.h>
#include <list>
#include <stdlib.h>
#include <string>
#include <sys/time.h>
#include <unistd.h>
#include <vector>
namespace unitTests {
class castor_utils : public ::testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
};
TEST_F(castor_utils, testCopyStringNullDst) {
using namespace castor::utils;
char dummy[6] = "Dummy";
ASSERT_THROW(copyString(NULL, 0, dummy),
cta::exception::Exception);
}
TEST_F(castor_utils, testCopyString) {
using namespace castor::utils;
char src[12] = "Hello World";
char dst[12];
copyString(dst, src);
ASSERT_EQ(0, strcmp(dst, src));
}
} // namespace unitTests
/******************************************************************************
*
* 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 "castor/utils/utils.hpp"
#include "common/utils/strerror_r_wrapper.hpp"
#include "common/utils/utils.hpp"
#include "h/Castor_limits.h"
#include <algorithm>
#include <errno.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <locale>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/prctl.h>
#include <sys/socket.h>
//-----------------------------------------------------------------------------
// copyString
//-----------------------------------------------------------------------------
void castor::utils::copyString(char *const dst, const size_t dstSize,
const std::string &src) {
if(dst == NULL) {
cta::exception::Exception ex;
ex.getMessage() << __FUNCTION__
<< ": Pointer to destination string is NULL";
throw ex;
}
if(src.length() >= dstSize) {
cta::exception::Exception ex;
ex.getMessage() << __FUNCTION__
<< ": Source string is longer than destination. Source length: "
<< src.length() << " Max destination length: " << (dstSize - 1);
throw ex;
}
strncpy(dst, src.c_str(), dstSize);
*(dst + dstSize -1) = '\0'; // Ensure destination string is null terminated
}
//------------------------------------------------------------------------------
// setProcessNameAndCmdLine
//------------------------------------------------------------------------------
void castor::utils::setProcessNameAndCmdLine(char *const argv0,
const std::string &name) {
try {
setProcessName(name);
setCmdLine(argv0, name);
} catch(cta::exception::Exception &ne) {
cta::exception::Exception ex;
ex.getMessage() << "Failed to set process name and command-line"
": " << ne.getMessage().str();
}
}
//------------------------------------------------------------------------------
// setProcessName
//------------------------------------------------------------------------------
void castor::utils::setProcessName(const std::string &name) {
char buf[16];
strncpy(buf, name.c_str(), sizeof(buf));
buf[sizeof(buf)-1] = '\0';
if(prctl(PR_SET_NAME, buf)) {
const std::string errMsg = cta::utils::errnoToString(errno);
cta::exception::Exception ex;
ex.getMessage() << "Failed to set process name: " << errMsg;
throw ex;
}
}
//------------------------------------------------------------------------------
// setCmdLine
//------------------------------------------------------------------------------
void castor::utils::setCmdLine(char *const argv0, const std::string &cmdLine)
throw() {
const size_t argv0Len = strlen(argv0);
strncpy(argv0, cmdLine.c_str(), argv0Len);
argv0[argv0Len] = '\0';
}
/******************************************************************************
*
* 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 "common/exception/InvalidArgument.hpp"
#include "common/exception/InvalidConfigEntry.hpp"
#include "common/exception/Exception.hpp"
#include <ostream>
#include <string>
#include <sstream>
#include <sys/time.h>
#include <time.h>
#include <vector>
namespace castor {
namespace utils {
/**
* Safely copies source string into destination string. The destination
* will always be null terminated if this function is successful.
*
* @param dst Destination string.
* @param dstSize The size of the destination string including the terminating
* null character.
* @param src Source string.
* destination.
*/
void copyString(char *const dst, const size_t dstSize, const std::string &src);
/**
* Safely copies source string into destination string. The destination
* will always be null terminated if this function is successful.
*
* @param dst Destination string.
* @param src Source string.
*/
template<size_t dstSize> void copyString(char (&dst)[dstSize],
const std::string &src) {
copyString(dst, dstSize, src);
}
/**
* Sets both the process name and the command-line to the specified value.
*
* The command-line is set by modifiying argv[0] and the process name is
* modified using prctl(PR_SET_NAME, ...). Please note that the length of
* argv[0] cannot be changed and that prctl(PR_SET_NAME, ...) is limited to
* 15 characters plus the null terminator.
*
* @param argv0 In/out paramater: A pointer to argv[0].
* @param name The new name of the process. If the name is too long for either
* the command-line or the process name then it will truncated. Any truncation
* for argv[0] will be independent of any truncation for process name if argv[0]
* is not 15 characters in length.
*/
void setProcessNameAndCmdLine(char *const argv0, const std::string &name);
/**
* Sets the process name to the specified value.
*
* The process name is modified using prctl(PR_SET_NAME, ...). Please note that
* prctl(PR_SET_NAME, ...) is limited to 15 characters plus the null terminator.
*
* @param name The new name of the process. If the new name is longer than 15
* characters then it will be truncated.
*/
void setProcessName(const std::string &name);
/**
* Sets both the process name and the command-line to the specified value.
*
* The command-line is set by modifiying argv[0] and the process name is
* modified using prctl(PR_SET_NAME, ...). Please note that the length of
* argv[0] cannot be changed and that prctl(PR_SET_NAME, ...) is limited to
* 15 characters plus the null terminator.
*
* @param argv0 In/out paramater: A pointer to argv[0].
* @param cmdLine The new command-line. If the new command-line is longer than
* argv[0] then it will be truncated.
*/
void setCmdLine(char *const argv0, const std::string &cmdLine) throw();
} // namespace utils
} // namespace castor
......@@ -29,7 +29,6 @@ target_link_libraries(cta-unitTests
ctatapeserverdriveunittests
ctatapeserverfileunittests
ctatapeserverscsiunittests
ctautilsunittests
ctacommon
ctacommonunittests
ctaobjectstore
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment