Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
c9139368
Commit
c9139368
authored
Sep 01, 2016
by
Victor Kotlyar
Browse files
Moved castor::server::ProcessCap to
cta::server::ProcessCap
parent
8a160874
Changes
35
Hide whitespace changes
Inline
Side-by-side
common/CMakeLists.txt
View file @
c9139368
...
...
@@ -96,6 +96,7 @@ set (COMMON_LIB_SRC_FILES
priorities/MountCriteria.cpp
priorities/UserGroup.cpp
processCap/ProcessCap.cpp
processCap/ProcessCapDummy.cpp
processCap/SmartCap.cpp
remoteFS/RemoteFileStatus.cpp
remoteFS/RemotePath.cpp
...
...
@@ -132,6 +133,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES
checksum/ChecksumTest.cpp
dataStructures/ArchiveFileTest.cpp
dataStructures/StorageClassTest.cpp
processCap/SmartCapTest.cpp
log/LogContextTest.cpp
log/ParamTest.cpp
log/SyslogLoggerTest.cpp
...
...
@@ -148,3 +150,4 @@ add_library (ctacommonunittests SHARED
${
COMMON_UNIT_TESTS_LIB_SRC_FILES
}
)
install
(
TARGETS ctacommonunittests DESTINATION usr/
${
CMAKE_INSTALL_LIBDIR
}
)
common/processCap/ProcessCap.cpp
View file @
c9139368
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
****************************************************************************
*/
*
You should have received a copy of the GNU General Public License
*
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/Exception.hpp"
#include "common/processCap/ProcessCap.hpp"
...
...
common/processCap/ProcessCap.hpp
View file @
c9139368
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
...
...
@@ -95,4 +90,4 @@ private:
};
// class ProcessCap
}
// namespace server
}
// namespace ca
stor
}
// namespace c
t
a
common/processCap/ProcessCapDummy.cpp
View file @
c9139368
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
****************************************************************************
*/
*
You should have received a copy of the GNU General Public License
*
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "c
astor/server
/ProcessCapDummy.hpp"
#include "c
ommon/processCap
/ProcessCapDummy.hpp"
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
ca
stor
::
server
::
ProcessCapDummy
::~
ProcessCapDummy
()
c
t
a
::
server
::
ProcessCapDummy
::~
ProcessCapDummy
()
throw
()
{
}
//------------------------------------------------------------------------------
// getProcText
//------------------------------------------------------------------------------
std
::
string
ca
stor
::
server
::
ProcessCapDummy
::
getProcText
()
{
std
::
string
c
t
a
::
server
::
ProcessCapDummy
::
getProcText
()
{
return
m_text
;
}
//------------------------------------------------------------------------------
// setProcText
//------------------------------------------------------------------------------
void
ca
stor
::
server
::
ProcessCapDummy
::
setProcText
(
const
std
::
string
&
text
)
{
void
c
t
a
::
server
::
ProcessCapDummy
::
setProcText
(
const
std
::
string
&
text
)
{
m_text
=
text
;
}
common/processCap/ProcessCapDummy.hpp
View file @
c9139368
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "c
astor/server
/ProcessCap.hpp"
#include "c
ommon/processCap
/ProcessCap.hpp"
#include <string>
#include <sys/capability.h>
namespace
ca
stor
{
namespace
c
t
a
{
namespace
server
{
/**
...
...
@@ -70,4 +65,4 @@ private:
};
// class ProcessCapDummy
}
// namespace server
}
// namespace ca
stor
}
// namespace c
t
a
common/processCap/SmartCap.cpp
View file @
c9139368
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
****************************************************************************
*/
*
You should have received a copy of the GNU General Public License
*
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/Exception.hpp"
#include "common/processCap/SmartCap.hpp"
...
...
common/processCap/SmartCap.hpp
View file @
c9139368
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
...
...
common/processCap/SmartCapTest.cpp
View file @
c9139368
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* 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 3 of the License, or
* (at your option) any later version.
*
* 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
****************************************************************************
*/
*
You should have received a copy of the GNU General Public License
*
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "c
astor
/exception/Exception.hpp"
#include "c
astor/server
/SmartCap.hpp"
#include "c
ommon
/exception/Exception.hpp"
#include "c
ommon/processCap
/SmartCap.hpp"
#include <gtest/gtest.h>
namespace
unitTests
{
class
ca
stor
_server_SmartCapTest
:
public
::
testing
::
Test
{
class
c
t
a_server_SmartCapTest
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
...
...
@@ -38,21 +33,21 @@ protected:
}
};
TEST_F
(
ca
stor
_server_SmartCapTest
,
default_constructor
)
{
ca
stor
::
server
::
SmartCap
smartPtr
;
TEST_F
(
c
t
a_server_SmartCapTest
,
default_constructor
)
{
c
t
a
::
server
::
SmartCap
smartPtr
;
ASSERT_EQ
((
cap_t
)
NULL
,
smartPtr
.
get
());
}
TEST_F
(
ca
stor
_server_SmartCapTest
,
constructor
)
{
TEST_F
(
c
t
a_server_SmartCapTest
,
constructor
)
{
cap_t
cap
=
cap_get_proc
();
ASSERT_NE
((
cap_t
)
NULL
,
cap
);
ca
stor
::
server
::
SmartCap
smartPtr
(
cap
);
c
t
a
::
server
::
SmartCap
smartPtr
(
cap
);
ASSERT_EQ
(
cap
,
smartPtr
.
get
());
}
TEST_F
(
ca
stor
_server_SmartCapTest
,
reset
)
{
ca
stor
::
server
::
SmartCap
smartPtr
;
TEST_F
(
c
t
a_server_SmartCapTest
,
reset
)
{
c
t
a
::
server
::
SmartCap
smartPtr
;
ASSERT_EQ
((
cap_t
)
NULL
,
smartPtr
.
get
());
cap_t
cap
=
cap_get_proc
();
...
...
@@ -62,12 +57,12 @@ TEST_F(castor_server_SmartCapTest, reset) {
ASSERT_EQ
(
cap
,
smartPtr
.
get
());
}
TEST_F
(
ca
stor
_server_SmartCapTest
,
assignment
)
{
TEST_F
(
c
t
a_server_SmartCapTest
,
assignment
)
{
cap_t
cap
=
cap_get_proc
();
ASSERT_NE
((
cap_t
)
NULL
,
cap
);
ca
stor
::
server
::
SmartCap
smartPtr1
;
ca
stor
::
server
::
SmartCap
smartPtr2
;
c
t
a
::
server
::
SmartCap
smartPtr1
;
c
t
a
::
server
::
SmartCap
smartPtr2
;
ASSERT_EQ
((
cap_t
)
NULL
,
smartPtr1
.
get
());
ASSERT_EQ
((
cap_t
)
NULL
,
smartPtr2
.
get
());
...
...
@@ -80,9 +75,9 @@ TEST_F(castor_server_SmartCapTest, assignment) {
ASSERT_EQ
(
cap
,
smartPtr2
.
get
());
}
TEST_F
(
ca
stor
_server_SmartCapTest
,
releaseNull
)
{
ca
stor
::
server
::
SmartCap
smartPtr
;
ASSERT_THROW
(
smartPtr
.
release
(),
ca
stor
::
exception
::
Exception
);
TEST_F
(
c
t
a_server_SmartCapTest
,
releaseNull
)
{
c
t
a
::
server
::
SmartCap
smartPtr
;
ASSERT_THROW
(
smartPtr
.
release
(),
c
t
a
::
exception
::
Exception
);
}
}
// namespace unitTests
tapeserver/castor/server/CMakeLists.txt
View file @
c9139368
...
...
@@ -17,7 +17,6 @@ include_directories(${PROJECT_SOURCE_DIR}/tapeserver/h)
add_library
(
ctaserverunittests SHARED
AtomicCounterTest.cpp
DaemonTest.cpp
SmartCapTest.cpp
ThreadingBlockingQTests.cpp
# ThreadingMPTests.cpp is commented out because of errors caused by libust
ThreadingMTTests.cpp
...
...
tapeserver/castor/server/ProcessCap.cpp
deleted
100644 → 0
View file @
8a160874
/******************************************************************************
*
* 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/server/ProcessCap.hpp"
#include "castor/server/SmartCap.hpp"
#include "castor/utils/utils.hpp"
#include "common/exception/Exception.hpp"
#include <errno.h>
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor
::
server
::
ProcessCap
::~
ProcessCap
()
throw
()
{
}
//------------------------------------------------------------------------------
// getProcText
//------------------------------------------------------------------------------
std
::
string
castor
::
server
::
ProcessCap
::
getProcText
()
{
try
{
SmartCap
cap
(
getProc
());
return
toText
((
cap_t
)
cap
.
get
());
}
catch
(
cta
::
exception
::
Exception
&
ne
)
{
cta
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to get text representation of the capabilities of the process: "
<<
ne
.
getMessage
().
str
();
throw
ex
;
}
}
//------------------------------------------------------------------------------
// getProc
//------------------------------------------------------------------------------
cap_t
castor
::
server
::
ProcessCap
::
getProc
()
{
cap_t
cap
=
cap_get_proc
();
if
(
NULL
==
cap
)
{
cta
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to get the capabilities of the process: "
<<
castor
::
utils
::
errnoToString
(
errno
);
throw
ex
;
}
return
cap
;
}
//------------------------------------------------------------------------------
// toText
//------------------------------------------------------------------------------
std
::
string
castor
::
server
::
ProcessCap
::
toText
(
const
cap_t
cap
)
{
// Create a C++ string with the result of calling cap_to_text()
char
*
const
text
=
cap_to_text
(
cap
,
NULL
);
if
(
NULL
==
text
)
{
cta
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to create string representation of capability state: "
<<
castor
::
utils
::
errnoToString
(
errno
);
throw
ex
;
}
std
::
string
result
(
text
);
// Free the memory allocated by cap_to_text()
if
(
cap_free
(
text
))
{
cta
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to free string representation of capability state: "
<<
castor
::
utils
::
errnoToString
(
errno
);
throw
ex
;
}
// Return the C++ string
return
result
;
}
//------------------------------------------------------------------------------
// setProcText
//------------------------------------------------------------------------------
void
castor
::
server
::
ProcessCap
::
setProcText
(
const
std
::
string
&
text
)
{
try
{
SmartCap
cap
(
fromText
(
text
));
setProc
(
cap
.
get
());
}
catch
(
cta
::
exception
::
Exception
&
ne
)
{
cta
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to set capabilities of process: "
<<
ne
.
getMessage
().
str
();
throw
ex
;
}
}
//------------------------------------------------------------------------------
// fromText
//------------------------------------------------------------------------------
cap_t
castor
::
server
::
ProcessCap
::
fromText
(
const
std
::
string
&
text
)
{
const
cap_t
cap
=
cap_from_text
(
text
.
c_str
());
if
(
NULL
==
cap
)
{
cta
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to create capability state from string representation"
": text='"
<<
text
<<
"': "
<<
castor
::
utils
::
errnoToString
(
errno
);
throw
ex
;
}
return
cap
;
}
//------------------------------------------------------------------------------
// setProc
//------------------------------------------------------------------------------
void
castor
::
server
::
ProcessCap
::
setProc
(
const
cap_t
cap
)
{
if
(
cap_set_proc
(
cap
))
{
cta
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to set the capabilities of the process: "
<<
castor
::
utils
::
errnoToString
(
errno
);
throw
ex
;
}
}
tapeserver/castor/server/ProcessCap.hpp
deleted
100644 → 0
View file @
8a160874
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <sys/capability.h>
namespace
castor
{
namespace
server
{
/**
* Class providing support for UNIX capabilities.
*
* This class is used to provide support for UNIX capbilities, so that
* subclasses can be created that override its virtual member functions.
* Unit testing is the primary use-case where you may want a dummy capabilities
* object that does nothing.
*
* Please note that process capabilities are not supported on Mac OS X.
*/
class
ProcessCap
{
public:
/**
* Destructor.
*/
virtual
~
ProcessCap
()
throw
();
/**
* C++ wrapper around the C functions cap_get_proc() and cap_to_text().
*
* @return The string representation the capabilities of the current
* process.
*/
virtual
std
::
string
getProcText
();
/**
* C++ wrapper around the C functions cap_from_text() and cap_set_proc().
*
* @text The string representation the capabilities that the current
* process should have.
*/
virtual
void
setProcText
(
const
std
::
string
&
text
);
private:
/**
* C++ wrapper around the C function cap_get_proc().
*
* @return The capability state.
*/
cap_t
getProc
();
/**
* C++ wrapper around the C function cap_to_text().
*
* @param cap The capability state.
*/
std
::
string
toText
(
const
cap_t
cap
);
/**
* C++ wrapper around the C function cap_from_text().
*
* @return The capability state.
*/
cap_t
fromText
(
const
std
::
string
&
text
);
/**