XRootD
Loading...
Searching...
No Matches
XrdClForkHandler.cc
Go to the documentation of this file.
1
//------------------------------------------------------------------------------
2
// Copyright (c) 2012 by European Organization for Nuclear Research (CERN)
3
// Author: Lukasz Janyst <ljanyst@cern.ch>
4
//------------------------------------------------------------------------------
5
// XRootD is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// XRootD is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17
//------------------------------------------------------------------------------
18
19
#include "
XrdCl/XrdClForkHandler.hh
"
20
#include "
XrdCl/XrdClConstants.hh
"
21
#include "
XrdCl/XrdClLog.hh
"
22
#include "
XrdCl/XrdClDefaultEnv.hh
"
23
#include "
XrdCl/XrdClPostMaster.hh
"
24
#include "
XrdCl/XrdClFileTimer.hh
"
25
#include "
XrdCl/XrdClFileStateHandler.hh
"
26
27
namespace
XrdCl
28
{
29
//----------------------------------------------------------------------------
30
// Constructor
31
//----------------------------------------------------------------------------
32
ForkHandler::ForkHandler
():
33
pPostMaster(0), pFileTimer(0)
34
{
35
}
36
37
//----------------------------------------------------------------------------
38
// Handle the preparation part of the forking process
39
//----------------------------------------------------------------------------
40
void
ForkHandler::Prepare
()
41
{
42
Log
*log =
DefaultEnv::GetLog
();
43
pid_t pid = getpid();
44
log->
Debug
(
UtilityMsg
,
"Running the prepare fork handler for process %d"
,
45
pid );
46
47
pMutex.
Lock
();
48
if
( pPostMaster )
49
pPostMaster->
Stop
();
50
pFileTimer->
Lock
();
51
52
//--------------------------------------------------------------------------
53
// Lock the user-level objects
54
//--------------------------------------------------------------------------
55
log->
Debug
(
UtilityMsg
,
"Locking File and FileSystem objects for process: "
56
"%d"
, pid );
57
58
std::set<FileStateHandler*>::iterator itFile;
59
for
( itFile = pFileObjects.begin(); itFile != pFileObjects.end();
60
++itFile )
61
(*itFile)->Lock();
62
63
std::set<FileSystem*>::iterator itFs;
64
for
( itFs = pFileSystemObjects.begin(); itFs != pFileSystemObjects.end();
65
++itFs )
66
(*itFs)->Lock();
67
}
68
69
//----------------------------------------------------------------------------
70
// Handle the parent post-fork
71
//----------------------------------------------------------------------------
72
void
ForkHandler::Parent
()
73
{
74
Log
*log =
DefaultEnv::GetLog
();
75
pid_t pid = getpid();
76
log->
Debug
(
UtilityMsg
,
"Running the parent fork handler for process %d"
,
77
pid );
78
79
log->
Debug
(
UtilityMsg
,
"Unlocking File and FileSystem objects for "
80
"process: %d"
, pid );
81
82
std::set<FileStateHandler*>::iterator itFile;
83
for
( itFile = pFileObjects.begin(); itFile != pFileObjects.end();
84
++itFile )
85
(*itFile)->UnLock();
86
87
std::set<FileSystem*>::iterator itFs;
88
for
( itFs = pFileSystemObjects.begin(); itFs != pFileSystemObjects.end();
89
++itFs )
90
(*itFs)->UnLock();
91
92
pFileTimer->
UnLock
();
93
if
( pPostMaster )
94
pPostMaster->
Start
();
95
96
pMutex.
UnLock
();
97
}
98
99
//------------------------------------------------------------------------
101
//------------------------------------------------------------------------
102
void
ForkHandler::Child
()
103
{
104
Log
*log =
DefaultEnv::GetLog
();
105
pid_t pid = getpid();
106
log->
Debug
(
UtilityMsg
,
"Running the child fork handler for process %d"
,
107
pid );
108
109
log->
Debug
(
UtilityMsg
,
"Unlocking File and FileSystem objects for "
110
"process: %d"
, pid );
111
112
std::set<FileStateHandler*>::iterator itFile;
113
for
( itFile = pFileObjects.begin(); itFile != pFileObjects.end();
114
++itFile )
115
{
116
(*itFile)->AfterForkChild();
117
(*itFile)->UnLock();
118
}
119
120
std::set<FileSystem*>::iterator itFs;
121
for
( itFs = pFileSystemObjects.begin(); itFs != pFileSystemObjects.end();
122
++itFs )
123
(*itFs)->UnLock();
124
125
pFileTimer->
UnLock
();
126
if
( pPostMaster )
127
{
128
pPostMaster->
Finalize
();
129
pPostMaster->
Initialize
();
130
pPostMaster->
Start
();
131
pPostMaster->
GetTaskManager
()->
RegisterTask
( pFileTimer, time(0),
false
);
132
}
133
134
pMutex.
UnLock
();
135
}
136
}
XrdClConstants.hh
XrdClDefaultEnv.hh
XrdClFileStateHandler.hh
XrdClFileTimer.hh
XrdClForkHandler.hh
XrdClLog.hh
XrdClPostMaster.hh
XrdCl::DefaultEnv::GetLog
static Log * GetLog()
Get default log.
Definition
XrdClDefaultEnv.cc:493
XrdCl::FileTimer::Lock
void Lock()
Lock the task.
Definition
XrdClFileTimer.hh:71
XrdCl::FileTimer::UnLock
void UnLock()
Un-lock the task.
Definition
XrdClFileTimer.hh:79
XrdCl::ForkHandler::Parent
void Parent()
Handle the parent post-fork.
Definition
XrdClForkHandler.cc:72
XrdCl::ForkHandler::Prepare
void Prepare()
Handle the preparation part of the forking process.
Definition
XrdClForkHandler.cc:40
XrdCl::ForkHandler::Child
void Child()
Handler the child post-fork.
Definition
XrdClForkHandler.cc:102
XrdCl::ForkHandler::ForkHandler
ForkHandler()
Definition
XrdClForkHandler.cc:32
XrdCl::Log
Handle diagnostics.
Definition
XrdClLog.hh:101
XrdCl::Log::Debug
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition
XrdClLog.cc:282
XrdCl::PostMaster::Start
bool Start()
Start the post master.
Definition
XrdClPostMaster.cc:160
XrdCl::PostMaster::Finalize
bool Finalize()
Finalizer.
Definition
XrdClPostMaster.cc:138
XrdCl::PostMaster::Stop
bool Stop()
Stop the postmaster.
Definition
XrdClPostMaster.cc:188
XrdCl::PostMaster::GetTaskManager
TaskManager * GetTaskManager()
Get the task manager object user by the post master.
Definition
XrdClPostMaster.cc:299
XrdCl::PostMaster::Initialize
bool Initialize()
Initializer.
Definition
XrdClPostMaster.cc:111
XrdCl::TaskManager::RegisterTask
void RegisterTask(Task *task, time_t time, bool own=true)
Definition
XrdClTaskManager.cc:127
XrdSysMutex::Lock
void Lock()
Definition
XrdSysPthread.hh:222
XrdSysMutex::UnLock
void UnLock()
Definition
XrdSysPthread.hh:224
XrdCl
Definition
XrdClAction.hh:34
XrdCl::UtilityMsg
const uint64_t UtilityMsg
Definition
XrdClConstants.hh:33
XrdCl
XrdClForkHandler.cc
Generated by
1.12.0