35 #include "XrdVersion.hh"
45 #include <sys/types.h>
60 using namespace XrdCl;
72 env->
GetInt(
"RunForkHandler", runForkHandler );
82 using namespace XrdCl;
88 log->
Debug(
UtilityMsg,
"In the parent fork handler for process %d", pid );
94 env->
GetInt(
"RunForkHandler", runForkHandler );
107 using namespace XrdCl;
114 pid_t pid = getpid();
115 log->
Debug(
UtilityMsg,
"In the child fork handler for process %d", pid );
121 env->
GetInt(
"RunForkHandler", runForkHandler );
125 forkHandler->
Child();
135 struct MaskTranslator
161 uint64_t translateMask(
const std::string mask )
164 return 0xffffffffffffffffULL;
166 std::vector<std::string> topics;
167 std::vector<std::string>::iterator it;
170 uint64_t resultMask = 0;
171 std::map<std::string, uint64_t>::iterator maskIt;
172 for( it = topics.begin(); it != topics.end(); ++it )
179 resultMask = 0xffffffffffffffffULL;
192 std::string topic = *it;
193 bool disable =
false;
194 if( !topic.empty() && topic[0] ==
'^' )
197 topic = topic.substr( 1, topic.length()-1 );
200 maskIt = masks.find( topic );
201 if( maskIt == masks.end() )
205 resultMask &= (0xffffffffffffffffULL ^ maskIt->second);
207 resultMask |= maskIt->second;
213 std::map<std::string, uint64_t> masks;
219 template<
typename Item>
222 EnvVarHolder(
const std::string &name_,
const Item &def_ ):
223 name( name_ ), def( def_ ) {}
229 #define REGISTER_VAR_INT( array, name, def ) \
230 array.push_back( EnvVarHolder<int>( name, def ) )
232 #define REGISTER_VAR_STR( array, name, def ) \
233 array.push_back( EnvVarHolder<std::string>( name, def ) )
241 Env *DefaultEnv::sEnv = 0;
243 Log *DefaultEnv::sLog = 0;
246 Monitor *DefaultEnv::sMonitor = 0;
248 bool DefaultEnv::sMonitorInitialized =
false;
256 DefaultEnv::DefaultEnv()
259 log->
Debug(
UtilityMsg,
"Initializing xrootd client version: %s", XrdVERSION );
264 std::vector<EnvVarHolder<int> > varsInt;
265 std::vector<EnvVarHolder<std::string> > varsStr;
326 std::map<std::string, std::string> config, userConfig;
334 passwd *pwd = pwdHandler.
Get( getuid() );
337 std::string userConfigFile = pwd->pw_dir;
338 userConfigFile +=
"/.xrootd/client.conf";
349 char *conffile = getenv(
"XRD_CLCONFFILE" );
358 char *confdir = getenv(
"XRD_CLCONFDIR" );
367 std::map<std::string, std::string>::iterator it;
369 for( it = config.begin(); it != config.end(); ++it )
371 it->first.c_str(), it->second.c_str() );
373 for( it = userConfig.begin(); it != userConfig.end(); ++it )
375 config[it->first] = it->second;
377 it->first.c_str(), it->second.c_str() );
380 for( it = config.begin(); it != config.end(); ++it )
382 it->first.c_str(), it->second.c_str() );
388 char *appName = basename( tmp );
398 for(
size_t i = 0; i < varsInt.size(); ++i )
400 PutInt( varsInt[i].name, varsInt[i].def );
402 it = config.find( varsInt[i].name );
403 if( it != config.end() )
406 int value = (int)strtol( it->second.c_str(), &endPtr, 0 );
409 "integer", varsInt[i].name.c_str(),
410 it->second.c_str() );
412 PutInt( varsInt[i].name, value );
415 std::string name =
"XRD_" + varsInt[i].name;
416 std::transform( name.begin(), name.end(), name.begin(), ::toupper );
423 for(
size_t i = 0; i < varsStr.size(); ++i )
425 PutString( varsStr[i].name, varsStr[i].def );
427 it = config.find( varsStr[i].name );
428 if( it != config.end() )
429 PutString( varsStr[i].name, it->second );
431 std::string name =
"XRD_" + varsStr[i].name;
432 std::transform( name.begin(), name.end(), name.begin(), ::toupper );
474 if( !postMaster->
Start() )
484 AtomicCAS(sPostMaster, sPostMaster, postMaster);
515 if( out->
Open( filepath ) )
529 const std::string &mask )
532 MaskTranslator translator;
533 uint64_t topicMask = translator.translateMask( mask );
545 log->
SetMask( level, topicMask );
569 if(
unlikely( !sMonitorInitialized ) )
572 if( !sMonitorInitialized )
579 sMonitorInitialized =
true;
581 env->
GetString(
"ClientMonitor", monitorLib );
582 if( monitorLib.empty() )
590 env->
GetString(
"ClientMonitorParam", monitorParam );
593 monitorLib.c_str(), monitorParam.c_str() );
598 char *errBuffer =
new char[4000];
600 errBuffer, 4000, &XrdVERSIONINFOVAR(
XrdCl ),
601 "monitor", monitorLib.c_str() );
605 loader = (MonLoader)sMonitorLibHandle->
Resolve(
"XrdClGetMonitor", -1 );
611 sMonitorLibHandle->
Unload();
612 delete sMonitorLibHandle; sMonitorLibHandle = 0;
619 const char *param = monitorParam.empty() ? 0 : monitorParam.c_str();
627 sMonitorLibHandle->
Unload();
628 delete sMonitorLibHandle; sMonitorLibHandle = 0;
631 log->
Debug(
UtilityMsg,
"Successfully initialized monitoring from: %s",
632 monitorLib.c_str() );
647 if( !sCheckSumManager )
650 return sCheckSumManager;
658 if(
unlikely( !sTransportManager ) )
661 if( !sTransportManager )
664 return sTransportManager;
672 return sPlugInManager;
686 void DefaultEnv::Initialize()
705 char *errBuff =
new char[1024];
711 "libXrdSecgsiAuthzVO.so",
712 "libXrdSecgsiGMAPDN.so",
719 for(
int i = 0; libs[i]; ++i )
724 sLog->
Error(
UtilityMsg,
"Unable to pre-load %s: %s", libs[i], errBuff );
733 void DefaultEnv::Finalize()
743 delete sTransportManager;
744 sTransportManager = 0;
746 delete sCheckSumManager;
747 sCheckSumManager = 0;
752 if( sMonitorLibHandle )
753 sMonitorLibHandle->
Unload();
755 delete sMonitorLibHandle;
756 sMonitorLibHandle = 0;
764 delete sPlugInManager;
787 void DefaultEnv::SetUpLog()
794 char *level = getenv(
"XRD_LOGLEVEL" );
801 char *file = getenv(
"XRD_LOGFILE" );
805 if( out->
Open( file ) )
814 MaskTranslator translator;
820 char *logMask = getenv(
"XRD_LOGMASK" );
823 uint64_t mask = translator.translateMask( logMask );
831 logMask = getenv(
"XRD_LOGMASK_ERROR" );
834 logMask = getenv(
"XRD_LOGMASK_WARNING" );
837 logMask = getenv(
"XRD_LOGMASK_INFO" );
840 logMask = getenv(
"XRD_LOGMASK_DEBUG" );
843 logMask = getenv(
"XRD_LOGMASK_DUMP" );
880 if(
counter++ == 0 ) XrdCl::DefaultEnv::Initialize();
890 if( --
counter == 0 ) XrdCl::DefaultEnv::Finalize();
XrdVERSIONINFO(XrdCl, client)
#define REGISTER_VAR_INT(array, name, def)
#define REGISTER_VAR_STR(array, name, def)
bool XrdOucPreload(const char *plib, char *eBuff, int eBlen, bool retry)
This include file define a utility function that pre-loads a plugin.
#define AtomicCAS(x, y, z)
Manage the checksum calc objects.
static PlugInManager * GetPlugInManager()
Get plug-in manager.
static bool SetLogFile(const std::string &filepath)
static CheckSumManager * GetCheckSumManager()
Get checksum manager.
static Monitor * GetMonitor()
Get the monitor object.
static TransportManager * GetTransportManager()
Get transport manager.
static PlugInFactory * GetPlugInFactory(const std::string url)
static Log * GetLog()
Get default log.
static PostMaster * GetPostMaster()
Get default post master.
static void SetLogLevel(const std::string &level)
static void SetLogMask(const std::string &level, const std::string &mask)
Set log mask.
static FileTimer * GetFileTimer()
Get file timer task.
static ForkHandler * GetForkHandler()
Get the fork handler.
static Env * GetEnv()
Get default client environment.
static void ReInitializeLogging()
Re-initialize the logging.
bool PutInt(const std::string &key, int value)
bool PutString(const std::string &key, const std::string &value)
bool ImportString(const std::string &key, const std::string &shellKey)
bool ImportInt(const std::string &key, const std::string &shellKey)
bool GetString(const std::string &key, std::string &value)
bool GetInt(const std::string &key, int &value)
Task generating timeout events for FileStateHandlers in recovery mode.
void Parent()
Handle the parent post-fork.
void Prepare()
Handle the preparation part of the forking process.
void Child()
Handler the child post-fork.
void RegisterFileTimer(FileTimer *fileTimer)
void RegisterPostMaster(PostMaster *postMaster)
Register a post master object.
Write log messages to a file.
bool Open(const std::string &fileName)
Open the log file.
@ WarningMsg
report warnings
@ DebugMsg
print debug info
@ DumpMsg
print details of the request and responses
void SetMask(LogLevel level, uint64_t mask)
Sets the mask for the topics of messages that should be printed.
void SetTopicName(uint64_t topic, std::string name)
Map a topic number to a string.
void SetLevel(LogLevel level)
Set the level of the messages that should be sent to the destination.
void Error(uint64_t topic, const char *format,...)
Report an error.
void Warning(uint64_t topic, const char *format,...)
Report a warning.
void Dump(uint64_t topic, const char *format,...)
Print a dump message.
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
void SetOutput(LogOut *output)
Set the output that should be used.
void SetPid(pid_t pid)
Set pid.
An abstract class to describe the client-side monitoring plugin interface.
Manage client-side plug-ins and match them agains URLs.
void ProcessEnvironmentSettings()
PlugInFactory * GetFactory(const std::string url)
A hub for dispatching and receiving messages.
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)
Manage transport handler objects.
static Status ProcessConfig(std::map< std::string, std::string > &config, const std::string &file)
Process a config file and return key-value pairs.
static Status ProcessConfigDir(std::map< std::string, std::string > &config, const std::string &dir)
Process a config directory and return key-value pairs.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
void * Resolve(const char *symbl, int mcnt=1)
void Unload(bool dodel=false)
struct passwd * Get(const char *Usr)
static const char * ExecName()
const int DefaultPreserveLocateTried
const int DefaultRunForkHandler
const int DefaultRedirectLimit
const int DefaultCPInitTimeout
const int DefaultXRateThreshold
const int DefaultLoadBalancerTTL
const uint64_t XRootDTransportMsg
const int DefaultMaxMetalinkWait
const char *const DefaultCpTarget
const int DefaultTCPKeepAliveProbes
const int DefaultCPChunkSize
const char *const DefaultClientMonitorParam
const int DefaultRetryWrtAtLBLimit
const uint64_t PostMasterMsg
const int DefaultWantTlsOnNoPgrw
const char *const DefaultOpenRecovery
const int DefaultStreamErrorWindow
const char *const DefaultPlugIn
const int DefaultMultiProtocol
const int DefaultConnectionRetry
const int DefaultIPNoShuffle
const int DefaultSubStreamsPerChannel
const int DefaultConnectionWindow
const int DefaultDataServerTTL
const int DefaultCPParallelChunks
const int DefaultTlsMetalink
const int DefaultTimeoutResolution
const char *const DefaultNetworkStack
const int DefaultStreamTimeout
const int DefaultLocalMetalinkFile
const int DefaultCpUsePgWrtRd
const int DefaultMetalinkProcessing
const uint64_t AsyncSockMsg
const char *const DefaultPlugInConfDir
const int DefaultTCPKeepAliveInterval
const int DefaultXCpBlockSize
const uint64_t PlugInMgrMsg
const uint64_t UtilityMsg
const char *const DefaultReadRecovery
const int DefaultCPTimeout
const int DefaultTCPKeepAlive
const int DefaultRequestTimeout
const int DefaultTCPKeepAliveTime
const int DefaultPreserveXAttrs
const int DefaultPreferIPv4
const char *const DefaultWriteRecovery
const char *const DefaultGlfnRedirector
const uint64_t TaskMgrMsg
const char *const DefaultCpRetryPolicy
const int DefaultNotAuthorizedRetryLimit
const int DefaultWorkerThreads
const uint64_t FileSystemMsg
const int DefaultAioSignal
const int DefaultCPTPCTimeout
const int DefaultTlsNoData
const char *const DefaultTlsDbgLvl
const char *const DefaultClientMonitor
const int DefaultParallelEvtLoop
const int DefaultZipMtlnCksum
Procedure execution status.
bool IsOK() const
We're fine.
std::string ToString() const
Create a string representation.