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
21#include "XrdCl/XrdClLog.hh"
26
27namespace XrdCl
28{
29 //----------------------------------------------------------------------------
30 // Constructor
31 //----------------------------------------------------------------------------
33 pPostMaster(0), pFileTimer(0)
34 {
35 }
36
37 //----------------------------------------------------------------------------
38 // Handle the preparation part of the forking process
39 //----------------------------------------------------------------------------
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 //----------------------------------------------------------------------------
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 //------------------------------------------------------------------------
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}
static Log * GetLog()
Get default log.
void Lock()
Lock the task.
void UnLock()
Un-lock the task.
void Parent()
Handle the parent post-fork.
void Prepare()
Handle the preparation part of the forking process.
void Child()
Handler the child post-fork.
Handle diagnostics.
Definition XrdClLog.hh:101
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition XrdClLog.cc:282
bool Start()
Start the post master.
bool Finalize()
Finalizer.
bool Stop()
Stop the postmaster.
TaskManager * GetTaskManager()
Get the task manager object user by the post master.
bool Initialize()
Initializer.
void RegisterTask(Task *task, time_t time, bool own=true)
const uint64_t UtilityMsg