XRootD
Loading...
Searching...
No Matches
XrdClDefaultEnv.cc File Reference
#include "XrdCl/XrdClDefaultEnv.hh"
#include "XrdCl/XrdClConstants.hh"
#include "XrdCl/XrdClPostMaster.hh"
#include "XrdCl/XrdClLog.hh"
#include "XrdCl/XrdClForkHandler.hh"
#include "XrdCl/XrdClFileTimer.hh"
#include "XrdCl/XrdClUtils.hh"
#include "XrdCl/XrdClMonitor.hh"
#include "XrdCl/XrdClCheckSumManager.hh"
#include "XrdCl/XrdClTransportManager.hh"
#include "XrdCl/XrdClPlugInManager.hh"
#include "XrdCl/XrdClOptimizers.hh"
#include "XrdOuc/XrdOucPreload.hh"
#include "XrdSys/XrdSysAtomics.hh"
#include "XrdSys/XrdSysUtils.hh"
#include "XrdSys/XrdSysPwd.hh"
#include "XrdVersion.hh"
#include <libgen.h>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
+ Include dependency graph for XrdClDefaultEnv.cc:

Go to the source code of this file.

Namespaces

namespace  XrdCl
 

Macros

#define REGISTER_VAR_INT(array, name, def)    array.push_back( EnvVarHolder<int>( name, def ) )
 
#define REGISTER_VAR_STR(array, name, def)    array.push_back( EnvVarHolder<std::string>( name, def ) )
 

Functions

static void child ()
 
static void parent ()
 
static void prepare ()
 
 XrdVERSIONINFO (XrdCl, client)
 

Macro Definition Documentation

◆ REGISTER_VAR_INT

#define REGISTER_VAR_INT (   array,
  name,
  def 
)     array.push_back( EnvVarHolder<int>( name, def ) )

Definition at line 229 of file XrdClDefaultEnv.cc.

235{
236 //----------------------------------------------------------------------------
237 // Statics
238 //----------------------------------------------------------------------------
239 XrdSysMutex DefaultEnv::sInitMutex;
240 Env *DefaultEnv::sEnv = 0;
241 PostMaster *DefaultEnv::sPostMaster = 0;
242 Log *DefaultEnv::sLog = 0;
243 ForkHandler *DefaultEnv::sForkHandler = 0;
244 FileTimer *DefaultEnv::sFileTimer = 0;
245 Monitor *DefaultEnv::sMonitor = 0;
246 XrdOucPinLoader *DefaultEnv::sMonitorLibHandle = 0;
247 bool DefaultEnv::sMonitorInitialized = false;
248 CheckSumManager *DefaultEnv::sCheckSumManager = 0;
249 TransportManager *DefaultEnv::sTransportManager = 0;
250 PlugInManager *DefaultEnv::sPlugInManager = 0;
251
252 //----------------------------------------------------------------------------
253 // Constructor
254 //----------------------------------------------------------------------------
255 DefaultEnv::DefaultEnv()
256 {
257 Log *log = GetLog();
258 log->Debug( UtilityMsg, "Initializing xrootd client version: %s", XrdVERSION );
259
260 //--------------------------------------------------------------------------
261 // Declate the variables to be processed
262 //--------------------------------------------------------------------------
263 std::vector<EnvVarHolder<int> > varsInt;
264 std::vector<EnvVarHolder<std::string> > varsStr;
265 REGISTER_VAR_INT( varsInt, "ConnectionWindow", DefaultConnectionWindow );
266 REGISTER_VAR_INT( varsInt, "ConnectionRetry", DefaultConnectionRetry );
267 REGISTER_VAR_INT( varsInt, "RequestTimeout", DefaultRequestTimeout );
268 REGISTER_VAR_INT( varsInt, "StreamTimeout", DefaultStreamTimeout );
269 REGISTER_VAR_INT( varsInt, "SubStreamsPerChannel", DefaultSubStreamsPerChannel );
270 REGISTER_VAR_INT( varsInt, "TimeoutResolution", DefaultTimeoutResolution );
271 REGISTER_VAR_INT( varsInt, "StreamErrorWindow", DefaultStreamErrorWindow );
272 REGISTER_VAR_INT( varsInt, "RunForkHandler", DefaultRunForkHandler );
273 REGISTER_VAR_INT( varsInt, "RedirectLimit", DefaultRedirectLimit );
274 REGISTER_VAR_INT( varsInt, "WorkerThreads", DefaultWorkerThreads );
275 REGISTER_VAR_INT( varsInt, "CPChunkSize", DefaultCPChunkSize );
276 REGISTER_VAR_INT( varsInt, "CPParallelChunks", DefaultCPParallelChunks );
277 REGISTER_VAR_INT( varsInt, "DataServerTTL", DefaultDataServerTTL );
278 REGISTER_VAR_INT( varsInt, "LoadBalancerTTL", DefaultLoadBalancerTTL );
279 REGISTER_VAR_INT( varsInt, "CPInitTimeout", DefaultCPInitTimeout );
280 REGISTER_VAR_INT( varsInt, "CPTPCTimeout", DefaultCPTPCTimeout );
281 REGISTER_VAR_INT( varsInt, "CPTimeout", DefaultCPTimeout );
282 REGISTER_VAR_INT( varsInt, "TCPKeepAlive", DefaultTCPKeepAlive );
283 REGISTER_VAR_INT( varsInt, "TCPKeepAliveTime", DefaultTCPKeepAliveTime );
284 REGISTER_VAR_INT( varsInt, "TCPKeepAliveInterval", DefaultTCPKeepAliveInterval );
285 REGISTER_VAR_INT( varsInt, "TCPKeepProbes", DefaultTCPKeepAliveProbes );
286 REGISTER_VAR_INT( varsInt, "MultiProtocol", DefaultMultiProtocol );
287 REGISTER_VAR_INT( varsInt, "ParallelEvtLoop", DefaultParallelEvtLoop );
288 REGISTER_VAR_INT( varsInt, "MetalinkProcessing", DefaultMetalinkProcessing );
289 REGISTER_VAR_INT( varsInt, "LocalMetalinkFile", DefaultLocalMetalinkFile );
290 REGISTER_VAR_INT( varsInt, "XCpBlockSize", DefaultXCpBlockSize );
291 REGISTER_VAR_INT( varsInt, "NoDelay", DefaultNoDelay );
292 REGISTER_VAR_INT( varsInt, "AioSignal", DefaultAioSignal );
293 REGISTER_VAR_INT( varsInt, "PreferIPv4", DefaultPreferIPv4 );
294 REGISTER_VAR_INT( varsInt, "MaxMetalinkWait", DefaultMaxMetalinkWait );
295 REGISTER_VAR_INT( varsInt, "PreserveLocateTried", DefaultPreserveLocateTried );
296 REGISTER_VAR_INT( varsInt, "NotAuthorizedRetryLimit", DefaultNotAuthorizedRetryLimit );
297 REGISTER_VAR_INT( varsInt, "PreserveXAttrs", DefaultPreserveXAttrs );
298 REGISTER_VAR_INT( varsInt, "NoTlsOK", DefaultNoTlsOK );
299 REGISTER_VAR_INT( varsInt, "TlsNoData", DefaultTlsNoData );
300 REGISTER_VAR_INT( varsInt, "TlsMetalink", DefaultTlsMetalink );
301 REGISTER_VAR_INT( varsInt, "ZipMtlnCksum", DefaultZipMtlnCksum );
302 REGISTER_VAR_INT( varsInt, "IPNoShuffle", DefaultIPNoShuffle );
303 REGISTER_VAR_INT( varsInt, "WantTlsOnNoPgrw", DefaultWantTlsOnNoPgrw );
304 REGISTER_VAR_INT( varsInt, "RetryWrtAtLBLimit", DefaultRetryWrtAtLBLimit );
305 REGISTER_VAR_INT( varsInt, "XRateThreshold", DefaultXRateThreshold );
306 REGISTER_VAR_INT( varsInt, "CpRetry", DefaultCpRetry );
307 REGISTER_VAR_INT( varsInt, "CpUsePgWrtRd", DefaultCpUsePgWrtRd );
308
309 REGISTER_VAR_STR( varsStr, "ClientMonitor", DefaultClientMonitor );
310 REGISTER_VAR_STR( varsStr, "ClientMonitorParam", DefaultClientMonitorParam );
311 REGISTER_VAR_STR( varsStr, "NetworkStack", DefaultNetworkStack );
312 REGISTER_VAR_STR( varsStr, "PlugIn", DefaultPlugIn );
313 REGISTER_VAR_STR( varsStr, "PlugInConfDir", DefaultPlugInConfDir );
314 REGISTER_VAR_STR( varsStr, "ReadRecovery", DefaultReadRecovery );
315 REGISTER_VAR_STR( varsStr, "WriteRecovery", DefaultWriteRecovery );
316 REGISTER_VAR_STR( varsStr, "OpenRecovery", DefaultOpenRecovery );
317 REGISTER_VAR_STR( varsStr, "GlfnRedirector", DefaultGlfnRedirector );
318 REGISTER_VAR_STR( varsStr, "TlsDbgLvl", DefaultTlsDbgLvl );
319 REGISTER_VAR_STR( varsStr, "CpTarget", DefaultCpTarget );
320 REGISTER_VAR_STR( varsStr, "CpRetryPolicy", DefaultCpRetryPolicy );
321
322 //--------------------------------------------------------------------------
323 // Process the configuration files
324 //--------------------------------------------------------------------------
325 std::map<std::string, std::string> config, userConfig;
326 Status st = Utils::ProcessConfig( config, "/etc/xrootd/client.conf" );
327
328 if( !st.IsOK() )
329 log->Warning( UtilityMsg, "Unable to process global config file: %s",
330 st.ToString().c_str() );
331
332 XrdSysPwd pwdHandler;
333 passwd *pwd = pwdHandler.Get( getuid() );
334 if( pwd )
335 {
336 std::string userConfigFile = pwd->pw_dir;
337 userConfigFile += "/.xrootd/client.conf";
338
339 st = Utils::ProcessConfig( userConfig, userConfigFile );
340
341 if( !st.IsOK() )
342 log->Debug( UtilityMsg, "Unable to process user config file: %s",
343 st.ToString().c_str() );
344 }
345 else
346 log->Debug( UtilityMsg, "Unable to find user home directory." );
347
348 char *conffile = getenv( "XRD_CLCONFFILE" );
349 if( conffile )
350 {
351 st = Utils::ProcessConfig( userConfig, conffile );
352 if( !st.IsOK() )
353 log->Debug( UtilityMsg, "Unable to process %s file: %s",
354 conffile, st.ToString().c_str() );
355 }
356
357 char *confdir = getenv( "XRD_CLCONFDIR" );
358 if( confdir )
359 {
360 st = Utils::ProcessConfigDir( userConfig, confdir );
361 if( !st.IsOK() )
362 log->Debug( UtilityMsg, "Unable to process %s file: %s",
363 confdir, st.ToString().c_str() );
364 }
365
366 std::map<std::string, std::string>::iterator it;
367
368 for( it = config.begin(); it != config.end(); ++it )
369 log->Dump( UtilityMsg, "[Global config] \"%s\" = \"%s\"",
370 it->first.c_str(), it->second.c_str() );
371
372 for( it = userConfig.begin(); it != userConfig.end(); ++it )
373 {
374 config[it->first] = it->second;
375 log->Dump( UtilityMsg, "[User config] \"%s\" = \"%s\"",
376 it->first.c_str(), it->second.c_str() );
377 }
378
379 for( it = config.begin(); it != config.end(); ++it )
380 log->Debug( UtilityMsg, "[Effective config] \"%s\" = \"%s\"",
381 it->first.c_str(), it->second.c_str() );
382
383 //--------------------------------------------------------------------------
384 // Monitoring settings
385 //--------------------------------------------------------------------------
386 char *tmp = strdup( XrdSysUtils::ExecName() );
387 char *appName = basename( tmp );
388 PutString( "AppName", appName );
389 free( tmp );
390 ImportString( "AppName", "XRD_APPNAME" );
391 PutString( "MonInfo", "" );
392 ImportString( "MonInfo", "XRD_MONINFO" );
393
394 //--------------------------------------------------------------------------
395 // Process ints
396 //--------------------------------------------------------------------------
397 for( size_t i = 0; i < varsInt.size(); ++i )
398 {
399 PutInt( varsInt[i].name, varsInt[i].def );
400
401 it = config.find( varsInt[i].name );
402 if( it != config.end() )
403 {
404 char *endPtr = 0;
405 int value = (int)strtol( it->second.c_str(), &endPtr, 0 );
406 if( *endPtr )
407 log->Warning( UtilityMsg, "Unable to set %s to %s: not a proper "
408 "integer", varsInt[i].name.c_str(),
409 it->second.c_str() );
410 else
411 PutInt( varsInt[i].name, value );
412 }
413
414 std::string name = "XRD_" + varsInt[i].name;
415 std::transform( name.begin(), name.end(), name.begin(), ::toupper );
416 ImportInt( varsInt[i].name, name );
417 }
418
419 //--------------------------------------------------------------------------
420 // Process strings
421 //--------------------------------------------------------------------------
422 for( size_t i = 0; i < varsStr.size(); ++i )
423 {
424 PutString( varsStr[i].name, varsStr[i].def );
425
426 it = config.find( varsStr[i].name );
427 if( it != config.end() )
428 PutString( varsStr[i].name, it->second );
429
430 std::string name = "XRD_" + varsStr[i].name;
431 std::transform( name.begin(), name.end(), name.begin(), ::toupper );
432 ImportString( varsStr[i].name, name );
433 }
434
435 //--------------------------------------------------------------------------
436 // Register fork handlers
437 //--------------------------------------------------------------------------
438 pthread_atfork( prepare, parent, child );
439 }
440
441 //----------------------------------------------------------------------------
442 // Get default client environment
443 //----------------------------------------------------------------------------
444 Env *DefaultEnv::GetEnv()
445 {
446 return sEnv;
447 }
448
449 //----------------------------------------------------------------------------
450 // Get default post master
451 //----------------------------------------------------------------------------
452 PostMaster *DefaultEnv::GetPostMaster()
453 {
454 PostMaster* postMaster = AtomicGet(sPostMaster);
455
456 if( unlikely( !postMaster ) )
457 {
458 XrdSysMutexHelper scopedLock( sInitMutex );
459 postMaster = AtomicGet(sPostMaster);
460
461 if( postMaster )
462 return postMaster;
463
464 postMaster = new PostMaster();
465
466 if( !postMaster->Initialize() )
467 {
468 delete postMaster;
469 postMaster = 0;
470 return 0;
471 }
472
473 if( !postMaster->Start() )
474 {
475 postMaster->Finalize();
476 delete postMaster;
477 postMaster = 0;
478 return 0;
479 }
480
481 sForkHandler->RegisterPostMaster( postMaster );
482 postMaster->GetTaskManager()->RegisterTask( sFileTimer, time(0), false );
483 AtomicCAS(sPostMaster, sPostMaster, postMaster);
484 }
485
486 return postMaster;
487 }
488
489 //----------------------------------------------------------------------------
490 // Get log
491 //----------------------------------------------------------------------------
492 Log *DefaultEnv::GetLog()
493 {
494 return sLog;
495 }
496
497 //----------------------------------------------------------------------------
498 // Set log level
499 //----------------------------------------------------------------------------
500 void DefaultEnv::SetLogLevel( const std::string &level )
501 {
502 Log *log = GetLog();
503 log->SetLevel( level );
504 }
505
506 //----------------------------------------------------------------------------
507 // Set log file
508 //----------------------------------------------------------------------------
509 bool DefaultEnv::SetLogFile( const std::string &filepath )
510 {
511 Log *log = GetLog();
512 LogOutFile *out = new LogOutFile();
513
514 if( out->Open( filepath ) )
515 {
516 log->SetOutput( out );
517 return true;
518 }
519
520 delete out;
521 return false;
522 }
523
524 //----------------------------------------------------------------------------
526 //------------------------------------------------------------------------
527 void DefaultEnv::SetLogMask( const std::string &level,
528 const std::string &mask )
529 {
530 Log *log = GetLog();
531 MaskTranslator translator;
532 uint64_t topicMask = translator.translateMask( mask );
533
534 if( level == "All" )
535 {
536 log->SetMask( Log::ErrorMsg, topicMask );
537 log->SetMask( Log::WarningMsg, topicMask );
538 log->SetMask( Log::InfoMsg, topicMask );
539 log->SetMask( Log::DebugMsg, topicMask );
540 log->SetMask( Log::DumpMsg, topicMask );
541 return;
542 }
543
544 log->SetMask( level, topicMask );
545 }
546
547 //----------------------------------------------------------------------------
548 // Get fork handler
549 //----------------------------------------------------------------------------
550 ForkHandler *DefaultEnv::GetForkHandler()
551 {
552 return sForkHandler;
553 }
554
555 //----------------------------------------------------------------------------
556 // Get fork handler
557 //----------------------------------------------------------------------------
558 FileTimer *DefaultEnv::GetFileTimer()
559 {
560 return sFileTimer;
561 }
562
563 //----------------------------------------------------------------------------
564 // Get the monitor object
565 //----------------------------------------------------------------------------
566 Monitor *DefaultEnv::GetMonitor()
567 {
568 if( unlikely( !sMonitorInitialized ) )
569 {
570 XrdSysMutexHelper scopedLock( sInitMutex );
571 if( !sMonitorInitialized )
572 {
573 //----------------------------------------------------------------------
574 // Check the environment settings
575 //----------------------------------------------------------------------
576 Env *env = GetEnv();
577 Log *log = GetLog();
578 sMonitorInitialized = true;
579 std::string monitorLib = DefaultClientMonitor;
580 env->GetString( "ClientMonitor", monitorLib );
581 if( monitorLib.empty() )
582 {
583 log->Debug( UtilityMsg, "Monitor library name not set. No "
584 "monitoring" );
585 return 0;
586 }
587
588 std::string monitorParam = DefaultClientMonitorParam;
589 env->GetString( "ClientMonitorParam", monitorParam );
590
591 log->Debug( UtilityMsg, "Initializing monitoring, lib: %s, param: %s",
592 monitorLib.c_str(), monitorParam.c_str() );
593
594 //----------------------------------------------------------------------
595 // Loading the plugin
596 //----------------------------------------------------------------------
597 char *errBuffer = new char[4000];
598 sMonitorLibHandle = new XrdOucPinLoader(
599 errBuffer, 4000, &XrdVERSIONINFOVAR( XrdCl ),
600 "monitor", monitorLib.c_str() );
601
602 typedef XrdCl::Monitor *(*MonLoader)(const char *, const char *);
603 MonLoader loader;
604 loader = (MonLoader)sMonitorLibHandle->Resolve( "XrdClGetMonitor", -1 );
605 if( !loader )
606 {
607 log->Error( UtilityMsg, "Unable to initialize user monitoring: %s",
608 errBuffer );
609 delete [] errBuffer;
610 sMonitorLibHandle->Unload();
611 delete sMonitorLibHandle; sMonitorLibHandle = 0;
612 return 0;
613 }
614
615 //----------------------------------------------------------------------
616 // Instantiating the monitor object
617 //----------------------------------------------------------------------
618 const char *param = monitorParam.empty() ? 0 : monitorParam.c_str();
619 sMonitor = (*loader)( XrdSysUtils::ExecName(), param );
620
621 if( !sMonitor )
622 {
623 log->Error( UtilityMsg, "Unable to initialize user monitoring: %s",
624 errBuffer );
625 delete [] errBuffer;
626 sMonitorLibHandle->Unload();
627 delete sMonitorLibHandle; sMonitorLibHandle = 0;
628 return 0;
629 }
630 log->Debug( UtilityMsg, "Successfully initialized monitoring from: %s",
631 monitorLib.c_str() );
632 delete [] errBuffer;
633 }
634 }
635 return sMonitor;
636 }
637
638 //----------------------------------------------------------------------------
639 // Get checksum manager
640 //----------------------------------------------------------------------------
641 CheckSumManager *DefaultEnv::GetCheckSumManager()
642 {
643 if( unlikely( !sCheckSumManager ) )
644 {
645 XrdSysMutexHelper scopedLock( sInitMutex );
646 if( !sCheckSumManager )
647 sCheckSumManager = new CheckSumManager();
648 }
649 return sCheckSumManager;
650 }
651
652 //----------------------------------------------------------------------------
653 // Get transport manager
654 //----------------------------------------------------------------------------
655 TransportManager *DefaultEnv::GetTransportManager()
656 {
657 if( unlikely( !sTransportManager ) )
658 {
659 XrdSysMutexHelper scopedLock( sInitMutex );
660 if( !sTransportManager )
661 sTransportManager = new TransportManager();
662 }
663 return sTransportManager;
664 }
665
666 //----------------------------------------------------------------------------
667 // Get plug-in manager
668 //----------------------------------------------------------------------------
669 PlugInManager *DefaultEnv::GetPlugInManager()
670 {
671 return sPlugInManager;
672 }
673
674 //----------------------------------------------------------------------------
675 // Retrieve the plug-in factory for the given URL
676 //----------------------------------------------------------------------------
677 PlugInFactory *DefaultEnv::GetPlugInFactory( const std::string url )
678 {
679 return sPlugInManager->GetFactory( url );
680 }
681
682 //----------------------------------------------------------------------------
683 // Initialize the environment
684 //----------------------------------------------------------------------------
685 void DefaultEnv::Initialize()
686 {
687 sLog = new Log();
688 SetUpLog();
689
690 sEnv = new DefaultEnv();
691 sForkHandler = new ForkHandler();
692 sFileTimer = new FileTimer();
693 sPlugInManager = new PlugInManager();
694
695 sPlugInManager->ProcessEnvironmentSettings();
696 sForkHandler->RegisterFileTimer( sFileTimer );
697
698 //--------------------------------------------------------------------------
699 // MacOSX library loading is completely moronic. We cannot dlopen a library
700 // from a thread other than a main thread, so we-pre dlopen all the
701 // libraries that we may potentially want.
702 //--------------------------------------------------------------------------
703#ifdef __APPLE__
704 char *errBuff = new char[1024];
705
706 const char *libs[] =
707 {
708 "libXrdSeckrb5.so",
709 "libXrdSecgsi.so",
710 "libXrdSecgsiAuthzVO.so",
711 "libXrdSecgsiGMAPDN.so",
712 "libXrdSecpwd.so",
713 "libXrdSecsss.so",
714 "libXrdSecunix.so",
715 0
716 };
717
718 for( int i = 0; libs[i]; ++i )
719 {
720 sLog->Debug( UtilityMsg, "Attempting to pre-load: %s", libs[i] );
721 bool ok = XrdOucPreload( libs[i], errBuff, 1024 );
722 if( !ok )
723 sLog->Error( UtilityMsg, "Unable to pre-load %s: %s", libs[i], errBuff );
724 }
725 delete [] errBuff;
726#endif
727 }
728
729 //----------------------------------------------------------------------------
730 // Finalize the environment
731 //----------------------------------------------------------------------------
732 void DefaultEnv::Finalize()
733 {
734 if( sPostMaster )
735 {
736 sPostMaster->Stop();
737 sPostMaster->Finalize();
738 delete sPostMaster;
739 sPostMaster = 0;
740 }
741
742 delete sTransportManager;
743 sTransportManager = 0;
744
745 delete sCheckSumManager;
746 sCheckSumManager = 0;
747
748 delete sMonitor;
749 sMonitor = 0;
750
751 if( sMonitorLibHandle )
752 sMonitorLibHandle->Unload();
753
754 delete sMonitorLibHandle;
755 sMonitorLibHandle = 0;
756
757 delete sForkHandler;
758 sForkHandler = 0;
759
760 delete sFileTimer;
761 sFileTimer = 0;
762
763 delete sPlugInManager;
764 sPlugInManager = 0;
765
766 delete sEnv;
767 sEnv = 0;
768
769 delete sLog;
770 sLog = 0;
771 }
772
773 //----------------------------------------------------------------------------
774 // Re-initialize the logging
775 //----------------------------------------------------------------------------
776 void DefaultEnv::ReInitializeLogging()
777 {
778 delete sLog;
779 sLog = new Log();
780 SetUpLog();
781 }
782
783 //----------------------------------------------------------------------------
784 // Set up the log
785 //----------------------------------------------------------------------------
786 void DefaultEnv::SetUpLog()
787 {
788 Log *log = GetLog();
789
790 //--------------------------------------------------------------------------
791 // Check if the log level has been defined in the environment
792 //--------------------------------------------------------------------------
793 char *level = getenv( "XRD_LOGLEVEL" );
794 if( level )
795 log->SetLevel( level );
796
797 //--------------------------------------------------------------------------
798 // Check if we need to log to a file
799 //--------------------------------------------------------------------------
800 char *file = getenv( "XRD_LOGFILE" );
801 if( file )
802 {
803 LogOutFile *out = new LogOutFile();
804 if( out->Open( file ) )
805 log->SetOutput( out );
806 else
807 delete out;
808 }
809
810 //--------------------------------------------------------------------------
811 // Log mask defaults
812 //--------------------------------------------------------------------------
813 MaskTranslator translator;
814 log->SetMask( Log::DumpMsg, translator.translateMask( "All|^PollerMsg" ) );
815
816 //--------------------------------------------------------------------------
817 // Initialize the topic mask
818 //--------------------------------------------------------------------------
819 char *logMask = getenv( "XRD_LOGMASK" );
820 if( logMask )
821 {
822 uint64_t mask = translator.translateMask( logMask );
823 log->SetMask( Log::ErrorMsg, mask );
824 log->SetMask( Log::WarningMsg, mask );
825 log->SetMask( Log::InfoMsg, mask );
826 log->SetMask( Log::DebugMsg, mask );
827 log->SetMask( Log::DumpMsg, mask );
828 }
829
830 logMask = getenv( "XRD_LOGMASK_ERROR" );
831 if( logMask ) log->SetMask( Log::ErrorMsg, translator.translateMask( logMask ) );
832
833 logMask = getenv( "XRD_LOGMASK_WARNING" );
834 if( logMask ) log->SetMask( Log::WarningMsg, translator.translateMask( logMask ) );
835
836 logMask = getenv( "XRD_LOGMASK_INFO" );
837 if( logMask ) log->SetMask( Log::InfoMsg, translator.translateMask( logMask ) );
838
839 logMask = getenv( "XRD_LOGMASK_DEBUG" );
840 if( logMask ) log->SetMask( Log::DebugMsg, translator.translateMask( logMask ) );
841
842 logMask = getenv( "XRD_LOGMASK_DUMP" );
843 if( logMask ) log->SetMask( Log::DumpMsg, translator.translateMask( logMask ) );
844
845 //--------------------------------------------------------------------------
846 // Set up the topic strings
847 //--------------------------------------------------------------------------
848 log->SetTopicName( AppMsg, "App" );
849 log->SetTopicName( UtilityMsg, "Utility" );
850 log->SetTopicName( FileMsg, "File" );
851 log->SetTopicName( PollerMsg, "Poller" );
852 log->SetTopicName( PostMasterMsg, "PostMaster" );
853 log->SetTopicName( XRootDTransportMsg, "XRootDTransport" );
854 log->SetTopicName( TaskMgrMsg, "TaskMgr" );
855 log->SetTopicName( XRootDMsg, "XRootD" );
856 log->SetTopicName( FileSystemMsg, "FileSystem" );
857 log->SetTopicName( AsyncSockMsg, "AsyncSock" );
858 log->SetTopicName( JobMgrMsg, "JobMgr" );
859 log->SetTopicName( PlugInMgrMsg, "PlugInMgr" );
860 log->SetTopicName( ExDbgMsg, "ExDbgMsg" );
861 log->SetTopicName( TlsMsg, "TlsMsg" );
862 log->SetTopicName( ZipMsg, "ZipMsg" );
863 }
864
865}
866
867//------------------------------------------------------------------------------
868// Static initialization and finalization
869//------------------------------------------------------------------------------
871
872//------------------------------------------------------------------------------
873// The constructor will be invoked in every translation unit
874// that includes XrdClDefaultEnv.hh, but the DefaultEnv will
875// be initialized only in the first one
876//------------------------------------------------------------------------------
878{
879 if( counter++ == 0 ) XrdCl::DefaultEnv::Initialize();
880}
881
882//------------------------------------------------------------------------------
883// The destructor will be invoked in every translation unit
884// that includes XrdClDefaultEnv.hh, but the DefaultEnv will
885// be finalized only once in the last one
886//------------------------------------------------------------------------------
888{
889 if( --counter == 0 ) XrdCl::DefaultEnv::Finalize();
890}
891
static void child()
#define REGISTER_VAR_INT(array, name, def)
#define REGISTER_VAR_STR(array, name, def)
static void prepare()
static void parent()
#define unlikely(x)
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)
#define AtomicGet(x)
An abstract class to describe the client-side monitoring plugin interface.
struct passwd * Get(const char *Usr)
Definition XrdSysPwd.hh:42
static const char * ExecName()
const char *const DefaultClientMonitorParam
const char *const DefaultClientMonitor
XrdSysError Log
Definition XrdConfig.cc:112

◆ REGISTER_VAR_STR

#define REGISTER_VAR_STR (   array,
  name,
  def 
)     array.push_back( EnvVarHolder<std::string>( name, def ) )

Definition at line 232 of file XrdClDefaultEnv.cc.

Function Documentation

◆ child()

static void child ( )
static

Definition at line 105 of file XrdClDefaultEnv.cc.

106 {
107 using namespace XrdCl;
108 DefaultEnv::ReInitializeLogging();
109 Log *log = DefaultEnv::GetLog();
110 Env *env = DefaultEnv::GetEnv();
111 ForkHandler *forkHandler = DefaultEnv::GetForkHandler();
112 env->RecreateLock();
113
114 pid_t pid = getpid();
115 log->Debug( UtilityMsg, "In the child fork handler for process %d", pid );
116
117 //--------------------------------------------------------------------------
118 // Run the fork handler if it's enabled
119 //--------------------------------------------------------------------------
120 int runForkHandler = DefaultRunForkHandler;
121 env->GetInt( "RunForkHandler", runForkHandler );
122 if( runForkHandler )
123 {
124 log->SetPid(pid);
125 forkHandler->Child();
126 }
127 }
void RecreateLock()
Definition XrdClEnv.hh:141
bool GetInt(const std::string &key, int &value)
Definition XrdClEnv.cc:89
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
void SetPid(pid_t pid)
Set pid.
Definition XrdClLog.hh:247
const int DefaultRunForkHandler

References XrdCl::ForkHandler::Child(), XrdCl::Log::Debug(), XrdCl::Env::GetInt(), XrdCl::Env::RecreateLock(), and XrdCl::Log::SetPid().

+ Here is the call graph for this function:

◆ parent()

static void parent ( )
static

Definition at line 80 of file XrdClDefaultEnv.cc.

81 {
82 using namespace XrdCl;
83 Log *log = DefaultEnv::GetLog();
84 Env *env = DefaultEnv::GetEnv();
85 ForkHandler *forkHandler = DefaultEnv::GetForkHandler();
86
87 pid_t pid = getpid();
88 log->Debug( UtilityMsg, "In the parent fork handler for process %d", pid );
89
90 //--------------------------------------------------------------------------
91 // Run the fork handler if it's enabled
92 //--------------------------------------------------------------------------
93 int runForkHandler = DefaultRunForkHandler;
94 env->GetInt( "RunForkHandler", runForkHandler );
95 if( runForkHandler )
96 {
97 log->SetPid(pid);
98 forkHandler->Parent();
99 }
100 }
void Parent()
Handle the parent post-fork.

References XrdCl::Log::Debug(), XrdCl::Env::GetInt(), XrdCl::ForkHandler::Parent(), and XrdCl::Log::SetPid().

Referenced by XrdCl::DirectoryList::SetParentName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepare()

static void prepare ( )
static

Definition at line 58 of file XrdClDefaultEnv.cc.

59 {
60 using namespace XrdCl;
61 Log *log = DefaultEnv::GetLog();
62 Env *env = DefaultEnv::GetEnv();
63 ForkHandler *forkHandler = DefaultEnv::GetForkHandler();
64
65 log->Debug( UtilityMsg, "In the prepare fork handler for process %d",
66 getpid() );
67
68 //--------------------------------------------------------------------------
69 // Run the fork handler if it's enabled
70 //--------------------------------------------------------------------------
71 int runForkHandler = DefaultRunForkHandler;
72 env->GetInt( "RunForkHandler", runForkHandler );
73 if( runForkHandler )
74 forkHandler->Prepare();
75 }
void Prepare()
Handle the preparation part of the forking process.

References XrdCl::Log::Debug(), XrdCl::Env::GetInt(), and XrdCl::ForkHandler::Prepare().

+ Here is the call graph for this function:

◆ XrdVERSIONINFO()

XrdVERSIONINFO ( XrdCl  ,
client   
)