Skip to content
GitLab
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
ef42c823
Commit
ef42c823
authored
Aug 31, 2016
by
Victor Kotlyar
Browse files
Renamed castor::exception::Errnum to
cta::exception::Errnum
parent
4eef892e
Changes
27
Hide whitespace changes
Inline
Side-by-side
tapeserver/castor/exception/Errnum.cpp
deleted
100644 → 0
View file @
4eef892e
/******************************************************************************
*
* 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/exception/Errnum.hpp"
#include
"common/utils/utils.hpp"
#include
<errno.h>
#include
<string.h>
using
namespace
castor
::
exception
;
Errnum
::
Errnum
(
std
::
string
what
)
:
Exception
(
""
)
{
m_errnum
=
errno
;
ErrnumConstructorBottomHalf
(
what
);
}
Errnum
::
Errnum
(
int
err
,
std
::
string
what
)
:
Exception
(
""
)
{
m_errnum
=
err
;
ErrnumConstructorBottomHalf
(
what
);
}
void
Errnum
::
ErrnumConstructorBottomHalf
(
const
std
::
string
&
what
)
{
m_strerror
=
cta
::
utils
::
errnoToString
(
m_errnum
);
std
::
stringstream
w2
;
if
(
what
.
size
())
w2
<<
what
<<
" "
;
w2
<<
"Errno="
<<
m_errnum
<<
": "
<<
m_strerror
;
getMessage
().
str
(
w2
.
str
());
}
void
Errnum
::
throwOnReturnedErrno
(
int
err
,
std
::
string
context
)
{
if
(
err
)
throw
Errnum
(
err
,
context
);
}
void
Errnum
::
throwOnNonZero
(
int
status
,
std
::
string
context
)
{
if
(
status
)
throw
Errnum
(
context
);
}
void
Errnum
::
throwOnZero
(
int
status
,
std
::
string
context
)
{
if
(
!
status
)
throw
Errnum
(
context
);
}
void
Errnum
::
throwOnNull
(
void
*
f
,
std
::
string
context
)
{
if
(
NULL
==
f
)
throw
Errnum
(
context
);
}
void
Errnum
::
throwOnNegative
(
int
ret
,
std
::
string
context
)
{
if
(
ret
<
0
)
throw
Errnum
(
context
);
}
void
Errnum
::
throwOnMinusOne
(
int
ret
,
std
::
string
context
)
{
if
(
-
1
==
ret
)
throw
Errnum
(
context
);
}
tapeserver/castor/exception/Errnum.hpp
deleted
100644 → 0
View file @
4eef892e
/******************************************************************************
*
* 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/Exception.hpp"
namespace
castor
{
namespace
exception
{
class
Errnum
:
public
cta
::
exception
::
Exception
{
public:
Errnum
(
std
::
string
what
=
""
);
Errnum
(
int
err
,
std
::
string
what
=
""
);
virtual
~
Errnum
()
throw
()
{};
int
errorNumber
()
const
{
return
m_errnum
;
}
std
::
string
strError
()
const
{
return
m_strerror
;
}
static
void
throwOnReturnedErrno
(
int
err
,
std
::
string
context
=
""
);
static
void
throwOnNonZero
(
int
status
,
std
::
string
context
=
""
);
static
void
throwOnZero
(
int
status
,
std
::
string
context
=
""
);
static
void
throwOnNull
(
void
*
f
,
std
::
string
context
=
""
);
static
void
throwOnNegative
(
int
ret
,
std
::
string
context
=
""
);
static
void
throwOnMinusOne
(
int
ret
,
std
::
string
context
=
""
);
protected:
void
ErrnumConstructorBottomHalf
(
const
std
::
string
&
what
);
int
m_errnum
;
std
::
string
m_strerror
;
};
}
}
tapeserver/castor/exception/ExceptionTest.cpp
View file @
ef42c823
...
...
@@ -22,7 +22,7 @@
*****************************************************************************/
#include
"common/exception/Exception.hpp"
#include
"Errnum.hpp"
#include
"
common/exception/
Errnum.hpp"
#include
<errno.h>
#include
<gtest/gtest.h>
...
...
@@ -75,51 +75,51 @@ namespace unitTests {
}
}
TEST
(
ca
stor
_exceptions
,
errnum_throwing
)
{
TEST
(
c
t
a_exceptions
,
errnum_throwing
)
{
/* Mickey Mouse test as we had trouble which throwing Errnum (with errno=ENOENT)*/
errno
=
ENOENT
;
try
{
throw
ca
stor
::
exception
::
Errnum
(
"Test ENOENT"
);
throw
c
t
a
::
exception
::
Errnum
(
"Test ENOENT"
);
}
catch
(
std
::
exception
&
e
)
{
std
::
string
temp
=
e
.
what
();
temp
+=
" "
;
}
}
TEST
(
ca
stor
_exceptions
,
Errnum_throwers
)
{
TEST
(
c
t
a_exceptions
,
Errnum_throwers
)
{
/* throwOnReturnedErrno */
ASSERT_NO_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
0
,
"Context"
));
ASSERT_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
ENOSPC
,
"Context"
),
ca
stor
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
0
,
"Context"
));
ASSERT_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
ENOSPC
,
"Context"
),
c
t
a
::
exception
::
Errnum
);
/* throwOnNonZero */
errno
=
ENOENT
;
ASSERT_NO_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnNonZero
(
0
,
"Context"
));
ASSERT_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnNonZero
(
-
1
,
"Context"
),
ca
stor
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnNonZero
(
0
,
"Context"
));
ASSERT_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnNonZero
(
-
1
,
"Context"
),
c
t
a
::
exception
::
Errnum
);
/* throwOnMinusOne */
errno
=
ENOENT
;
ASSERT_NO_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnMinusOne
(
0
,
"Context"
));
ASSERT_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnMinusOne
(
-
1
,
"Context"
),
ca
stor
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnMinusOne
(
0
,
"Context"
));
ASSERT_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnMinusOne
(
-
1
,
"Context"
),
c
t
a
::
exception
::
Errnum
);
/* throwOnNegative */
errno
=
ENOENT
;
ASSERT_NO_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnNegative
(
0
,
"Context"
));
ASSERT_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnNegative
(
-
1
,
"Context"
),
ca
stor
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnNegative
(
0
,
"Context"
));
ASSERT_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnNegative
(
-
1
,
"Context"
),
c
t
a
::
exception
::
Errnum
);
/* throwOnNull */
errno
=
ENOENT
;
ASSERT_NO_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnNull
(
this
,
"Context"
));
ASSERT_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnNull
(
NULL
,
"Context"
),
ca
stor
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnNull
(
this
,
"Context"
));
ASSERT_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnNull
(
NULL
,
"Context"
),
c
t
a
::
exception
::
Errnum
);
/* throwOnZero */
errno
=
ENOENT
;
ASSERT_NO_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnZero
(
1
,
"Context"
));
ASSERT_THROW
(
ca
stor
::
exception
::
Errnum
::
throwOnZero
(
0
,
"Context"
),
ca
stor
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnZero
(
1
,
"Context"
));
ASSERT_THROW
(
c
t
a
::
exception
::
Errnum
::
throwOnZero
(
0
,
"Context"
),
c
t
a
::
exception
::
Errnum
);
}
}
tapeserver/castor/io/IoTest.cpp
View file @
ef42c823
...
...
@@ -24,7 +24,7 @@
#include
"castor/io/io.hpp"
#include
"castor/utils/SmartFd.hpp"
#include
"castor/io/marshall.h"
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
<fcntl.h>
#include
<gtest/gtest.h>
...
...
@@ -82,7 +82,7 @@ protected:
strncpy
(
listenAddr
.
sun_path
,
listenSockPath
,
sizeof
(
listenAddr
.
sun_path
)
-
1
);
ca
stor
::
exception
::
Errnum
::
throwOnNonZero
(
c
t
a
::
exception
::
Errnum
::
throwOnNonZero
(
bind
(
smartListenSock
.
get
(),
(
const
struct
sockaddr
*
)
&
listenAddr
,
sizeof
(
listenAddr
)),
"Call to bind() failed: "
);
}
...
...
tapeserver/castor/messages/Mutex.cpp
View file @
ef42c823
#include
"castor/messages/Mutex.hpp"
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
"common/exception/Exception.hpp"
//------------------------------------------------------------------------------
...
...
@@ -7,17 +7,17 @@
//------------------------------------------------------------------------------
castor
::
messages
::
Mutex
::
Mutex
()
{
pthread_mutexattr_t
attr
;
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutexattr_init
(
&
attr
),
"Error from pthread_mutexattr_init in castor::messages::Mutex::Mutex()"
);
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutexattr_settype
(
&
attr
,
PTHREAD_MUTEX_ERRORCHECK
),
"Error from pthread_mutexattr_settype in castor::messages::Mutex::Mutex()"
);
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_init
(
&
m_mutex
,
&
attr
),
"Error from pthread_mutex_init in castor::messages::Mutex::Mutex()"
);
try
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutexattr_destroy
(
&
attr
),
"Error from pthread_mutexattr_destroy in"
" castor::messages::Mutex::Mutex()"
);
...
...
@@ -38,7 +38,7 @@ castor::messages::Mutex::~Mutex() throw() {
// lock
//------------------------------------------------------------------------------
void
castor
::
messages
::
Mutex
::
lock
()
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_lock
(
&
m_mutex
),
"Error from pthread_mutex_lock in castor::messages::Mutex::lock()"
);
}
...
...
@@ -47,7 +47,7 @@ void castor::messages::Mutex::lock() {
// unlock
//------------------------------------------------------------------------------
void
castor
::
messages
::
Mutex
::
unlock
()
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_unlock
(
&
m_mutex
),
"Error from pthread_mutex_unlock in castor::messages::Mutex::unlock()"
);
}
tapeserver/castor/messages/MutexLockerTest.cpp
View file @
ef42c823
...
...
@@ -21,7 +21,7 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
"castor/messages/MutexLocker.hpp"
#include
<gtest/gtest.h>
...
...
@@ -46,7 +46,7 @@ TEST(castor_messages_MutexLockerTest,
{
MutexLocker
ml
(
&
m
);
// This is a different flavour of duplicate locking
ASSERT_THROW
(
m
.
lock
(),
ca
stor
::
exception
::
Errnum
);
ASSERT_THROW
(
m
.
lock
(),
c
t
a
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
m
.
unlock
());
ASSERT_NO_THROW
(
m
.
lock
());
}
...
...
tapeserver/castor/messages/MutexTest.cpp
View file @
ef42c823
...
...
@@ -21,7 +21,7 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
"castor/messages/Mutex.hpp"
#include
<gtest/gtest.h>
...
...
@@ -46,11 +46,11 @@ TEST(castor_messages_MutexTest, Mutex_properly_throws_exceptions) {
ASSERT_NO_THROW
(
m
.
lock
());
// Duplicate lock
ASSERT_THROW
(
m
.
lock
(),
ca
stor
::
exception
::
Errnum
);
ASSERT_THROW
(
m
.
lock
(),
c
t
a
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
m
.
unlock
());
// Duplicate release
ASSERT_THROW
(
m
.
unlock
(),
ca
stor
::
exception
::
Errnum
);
ASSERT_THROW
(
m
.
unlock
(),
c
t
a
::
exception
::
Errnum
);
}
}
// namespace unitTests
tapeserver/castor/server/ChildProcess.hpp
View file @
ef42c823
...
...
@@ -22,7 +22,7 @@
*****************************************************************************/
#pragma once
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
"common/exception/Exception.hpp"
#include
<unistd.h>
...
...
tapeserver/castor/server/Daemon.cpp
View file @
ef42c823
...
...
@@ -19,7 +19,7 @@
* @author Castor Dev team, castor-dev@cern.ch
******************************************************************************/
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
"castor/server/Daemon.hpp"
#include
"castor/server/ThreadNotification.hpp"
#include
"castor/System.hpp"
...
...
@@ -163,7 +163,7 @@ void castor::server::Daemon::daemonizeIfNotRunInForeground(
{
pid_t
pid
=
0
;
ca
stor
::
exception
::
Errnum
::
throwOnNegative
(
pid
=
fork
(),
c
t
a
::
exception
::
Errnum
::
throwOnNegative
(
pid
=
fork
(),
"Failed to daemonize: Failed to fork"
);
// If we got a good PID, then we can exit the parent process
if
(
0
<
pid
)
{
...
...
@@ -179,17 +179,17 @@ void castor::server::Daemon::daemonizeIfNotRunInForeground(
umask
(
0
);
// Run the daemon in a new session
ca
stor
::
exception
::
Errnum
::
throwOnNegative
(
setsid
(),
c
t
a
::
exception
::
Errnum
::
throwOnNegative
(
setsid
(),
"Failed to daemonize: Failed to run daemon is a new session"
);
// Redirect standard files to /dev/null
ca
stor
::
exception
::
Errnum
::
throwOnNull
(
c
t
a
::
exception
::
Errnum
::
throwOnNull
(
freopen
(
"/dev/null"
,
"r"
,
stdin
),
"Failed to daemonize: Falied to freopen stdin"
);
ca
stor
::
exception
::
Errnum
::
throwOnNull
(
c
t
a
::
exception
::
Errnum
::
throwOnNull
(
freopen
(
"/dev/null"
,
"w"
,
stdout
),
"Failed to daemonize: Failed to freopen stdout"
);
ca
stor
::
exception
::
Errnum
::
throwOnNull
(
c
t
a
::
exception
::
Errnum
::
throwOnNull
(
freopen
(
"/dev/null"
,
"w"
,
stderr
),
"Failed to daemonize: Failed to freopen stderr"
);
}
// if (!m_foreground)
...
...
tapeserver/castor/server/Mutex.cpp
View file @
ef42c823
#include
"castor/server/Mutex.hpp"
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
"common/exception/Exception.hpp"
//------------------------------------------------------------------------------
...
...
@@ -7,17 +7,17 @@
//------------------------------------------------------------------------------
castor
::
server
::
Mutex
::
Mutex
()
{
pthread_mutexattr_t
attr
;
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutexattr_init
(
&
attr
),
"Error from pthread_mutexattr_init in castor::server::Mutex::Mutex()"
);
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutexattr_settype
(
&
attr
,
PTHREAD_MUTEX_ERRORCHECK
),
"Error from pthread_mutexattr_settype in castor::server::Mutex::Mutex()"
);
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_init
(
&
m_mutex
,
&
attr
),
"Error from pthread_mutex_init in castor::server::Mutex::Mutex()"
);
try
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutexattr_destroy
(
&
attr
),
"Error from pthread_mutexattr_destroy in castor::server::Mutex::Mutex()"
);
}
catch
(...)
{
...
...
@@ -35,7 +35,7 @@ castor::server::Mutex::~Mutex() {
//lock
//------------------------------------------------------------------------------
void
castor
::
server
::
Mutex
::
lock
()
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_lock
(
&
m_mutex
),
"Error from pthread_mutex_lock in castor::server::Mutex::lock()"
);
}
...
...
@@ -43,7 +43,7 @@ void castor::server::Mutex::lock() {
//unlock
//------------------------------------------------------------------------------
void
castor
::
server
::
Mutex
::
unlock
()
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_unlock
(
&
m_mutex
),
"Error from pthread_mutex_unlock in castor::server::Mutex::unlock()"
);
}
tapeserver/castor/server/Semaphores.cpp
View file @
ef42c823
#include
"castor/server/MutexLocker.hpp"
#include
"castor/server/Semaphores.hpp"
#include
"castor/server/Threading.hpp"
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
"common/exception/Exception.hpp"
#include
<errno.h>
#include
<sys/time.h>
...
...
@@ -11,7 +11,7 @@
//------------------------------------------------------------------------------
castor
::
server
::
PosixSemaphore
::
PosixSemaphore
(
int
initial
)
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
sem_init
(
&
m_sem
,
0
,
initial
),
"Error from sem_init in castor::server::PosixSemaphore::PosixSemaphore()"
);
}
...
...
@@ -34,7 +34,7 @@ void castor::server::PosixSemaphore::acquire()
/* If we receive EINTR, we should just keep trying (signal interruption) */
while
((
ret
=
sem_wait
(
&
m_sem
))
&&
EINTR
==
errno
)
{}
/* If it was not EINTR, it's a failure */
ca
stor
::
exception
::
Errnum
::
throwOnNonZero
(
ret
,
c
t
a
::
exception
::
Errnum
::
throwOnNonZero
(
ret
,
"Error from sem_wait in castor::server::PosixSemaphore::acquire()"
);
}
//------------------------------------------------------------------------------
...
...
@@ -57,7 +57,7 @@ void castor::server::PosixSemaphore::acquireWithTimeout(uint64_t timeout_us)
/* If we got a timeout, throw a special exception */
if
(
ret
&&
ETIMEDOUT
==
errno
)
{
throw
Timeout
();
}
/* If it was not EINTR, it's a failure */
ca
stor
::
exception
::
Errnum
::
throwOnNonZero
(
ret
,
c
t
a
::
exception
::
Errnum
::
throwOnNonZero
(
ret
,
"Error from sem_wait in castor::server::PosixSemaphore::acquireWithTimeout()"
);
}
...
...
@@ -69,7 +69,7 @@ bool castor::server::PosixSemaphore::tryAcquire()
int
ret
=
sem_trywait
(
&
m_sem
);
if
(
!
ret
)
return
true
;
if
(
ret
&&
EAGAIN
==
errno
)
return
false
;
ca
stor
::
exception
::
Errnum
::
throwOnNonZero
(
ret
,
c
t
a
::
exception
::
Errnum
::
throwOnNonZero
(
ret
,
"Error from sem_trywait in castor::server::PosixSemaphore::tryAcquire()"
);
/* unreacheable, just for compiler happiness */
return
false
;
...
...
@@ -81,7 +81,7 @@ void castor::server::PosixSemaphore::release(int n)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
MutexLocker
ml
(
&
m_mutexPosterProtection
);
ca
stor
::
exception
::
Errnum
::
throwOnNonZero
(
sem_post
(
&
m_sem
),
c
t
a
::
exception
::
Errnum
::
throwOnNonZero
(
sem_post
(
&
m_sem
),
"Error from sem_post in castor::server::PosixSemaphore::release()"
);
}
}
...
...
@@ -90,10 +90,10 @@ void castor::server::PosixSemaphore::release(int n)
//------------------------------------------------------------------------------
castor
::
server
::
CondVarSemaphore
::
CondVarSemaphore
(
int
initial
)
:
m_value
(
initial
)
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_cond_init
(
&
m_cond
,
NULL
),
"Error from pthread_cond_init in castor::server::CondVarSemaphore::CondVarSemaphore()"
);
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_init
(
&
m_mutex
,
NULL
),
"Error from pthread_mutex_init in castor::server::CondVarSemaphore::CondVarSemaphore()"
);
}
...
...
@@ -115,16 +115,16 @@ castor::server::CondVarSemaphore::~CondVarSemaphore() {
//------------------------------------------------------------------------------
void
castor
::
server
::
CondVarSemaphore
::
acquire
()
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_lock
(
&
m_mutex
),
"Error from pthread_mutex_lock in castor::server::CondVarSemaphore::acquire()"
);
while
(
m_value
<=
0
)
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_cond_wait
(
&
m_cond
,
&
m_mutex
),
"Error from pthread_cond_wait in castor::server::CondVarSemaphore::acquire()"
);
}
m_value
--
;
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_unlock
(
&
m_mutex
),
"Error from pthread_mutex_unlock in castor::server::CondVarSemaphore::acquire()"
);
}
...
...
@@ -134,7 +134,7 @@ void castor::server::CondVarSemaphore::acquire()
bool
castor
::
server
::
CondVarSemaphore
::
tryAcquire
()
{
bool
ret
;
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_lock
(
&
m_mutex
),
"Error from pthread_mutex_lock in castor::server::CondVarSemaphore::tryAcquire()"
);
if
(
m_value
>
0
)
{
...
...
@@ -143,7 +143,7 @@ bool castor::server::CondVarSemaphore::tryAcquire()
}
else
{
ret
=
false
;
}
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_unlock
(
&
m_mutex
),
"Error from pthread_mutex_unlock in castor::server::CondVarSemaphore::tryAcquire()"
);
return
ret
;
...
...
@@ -154,14 +154,14 @@ bool castor::server::CondVarSemaphore::tryAcquire()
void
castor
::
server
::
CondVarSemaphore
::
release
(
int
n
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_lock
(
&
m_mutex
),
"Error from pthread_mutex_unlock in castor::server::CondVarSemaphore::release()"
);
m_value
++
;
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_cond_signal
(
&
m_cond
),
"Error from pthread_cond_signal in castor::server::CondVarSemaphore::release()"
);
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_mutex_unlock
(
&
m_mutex
),
"Error from pthread_mutex_unlock in castor::server::CondVarSemaphore::release()"
);
}
...
...
tapeserver/castor/server/Threading.cpp
View file @
ef42c823
...
...
@@ -34,7 +34,7 @@
//------------------------------------------------------------------------------
void
castor
::
server
::
Thread
::
start
()
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_create
(
&
m_thread
,
NULL
,
pthread_runner
,
this
),
"Error from pthread_create in castor::server::Thread::start()"
);
}
...
...
@@ -43,7 +43,7 @@ void castor::server::Thread::start()
//------------------------------------------------------------------------------
void
castor
::
server
::
Thread
::
wait
()
{
ca
stor
::
exception
::
Errnum
::
throwOnReturnedErrno
(
c
t
a
::
exception
::
Errnum
::
throwOnReturnedErrno
(
pthread_join
(
m_thread
,
NULL
),
"Error from pthread_join in castor::server::Thread::wait()"
);
if
(
m_hadException
)
{
...
...
tapeserver/castor/server/Threading.hpp
View file @
ef42c823
...
...
@@ -25,7 +25,7 @@
#include
<pthread.h>
#include
<semaphore.h>
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
#include
"castor/server/Mutex.hpp"
#include
"common/exception/Exception.hpp"
...
...
tapeserver/castor/server/ThreadingTests.cpp
View file @
ef42c823
...
...
@@ -39,10 +39,10 @@ namespace unitTests {
castor
::
server
::
Mutex
m
;
ASSERT_NO_THROW
(
m
.
lock
());
/* Duplicate lock */
ASSERT_THROW
(
m
.
lock
(),
ca
stor
::
exception
::
Errnum
);
ASSERT_THROW
(
m
.
lock
(),
c
t
a
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
m
.
unlock
());
/* Duplicate release */
ASSERT_THROW
(
m
.
unlock
(),
ca
stor
::
exception
::
Errnum
);
ASSERT_THROW
(
m
.
unlock
(),
c
t
a
::
exception
::
Errnum
);
}
TEST
(
castor_tape_threading
,
MutexLocker_locks_and_properly_throws_exceptions
)
{
...
...
@@ -50,7 +50,7 @@ namespace unitTests {
{
castor
::
server
::
MutexLocker
ml
(
&
m
);
/* This is a different flavourr of duplicate locking */
ASSERT_THROW
(
m
.
lock
(),
ca
stor
::
exception
::
Errnum
);
ASSERT_THROW
(
m
.
lock
(),
c
t
a
::
exception
::
Errnum
);
ASSERT_NO_THROW
(
m
.
unlock
());
ASSERT_NO_THROW
(
m
.
lock
());
}
...
...
tapeserver/castor/tape/tapeserver/SCSI/Device.cpp
View file @
ef42c823
...
...
@@ -25,7 +25,7 @@
#include
<scsi/sg.h>
#include
"Device.hpp"
#include
"c
astor
/exception/Errnum.hpp"
#include
"c
ommon
/exception/Errnum.hpp"
using
namespace
castor
::
tape
;
...
...
@@ -40,7 +40,7 @@ SCSI::DeviceVector::DeviceVector(System::virtualWrapper& sysWrapper) : m_sysWrap
utils
::
Regex
ifFirstCharIsDigit
(
"^[[:digit:]]"
);
std
::
vector
<
std
::
string
>
checkResult
;
DIR
*
dirp
;
ca
stor
::
exception
::
Errnum
::
throwOnNull
(
c
t
a
::
exception
::
Errnum
::
throwOnNull
(
dirp
=
m_sysWrapper
.
opendir
(
sysDevsPath
.
c_str
()),
"Error opening sysfs scsi devs"
);
while
(
struct
dirent
*
dent
=
m_sysWrapper
.
readdir
(
dirp
))
{
...
...
@@ -51,7 +51,7 @@ SCSI::DeviceVector::DeviceVector(System::virtualWrapper& sysWrapper) : m_sysWrap
std
::
string
fullpath
=
sysDevsPath
+
"/"
+
std
::
string
(
dent
->
d_name
);
/* We expect only symbolic links in this directory, */
char
rp
[
PATH_MAX
];
ca
stor
::
exception
::
Errnum
::
throwOnNull
(