XRootD
Loading...
Searching...
No Matches
XrdSysUtils Class Reference

#include <XrdSysUtils.hh>

+ Collaboration diagram for XrdSysUtils:

Public Member Functions

 XrdSysUtils ()
 Constructor and destructor.
 
 ~XrdSysUtils ()
 

Static Public Member Functions

static const char * ExecName ()
 
static int FmtUname (char *buff, int blen)
 
static int GetSigNum (const char *sname)
 
static bool SigBlock ()
 
static bool SigBlock (int numsig)
 

Detailed Description

Definition at line 36 of file XrdSysUtils.hh.

Constructor & Destructor Documentation

◆ XrdSysUtils()

XrdSysUtils::XrdSysUtils ( )
inline

Constructor and destructor.

Definition at line 96 of file XrdSysUtils.hh.

96{}

◆ ~XrdSysUtils()

XrdSysUtils::~XrdSysUtils ( )
inline

Definition at line 97 of file XrdSysUtils.hh.

97{}

Member Function Documentation

◆ ExecName()

const char * XrdSysUtils::ExecName ( )
static

Get the name of the current executable.

Returns
the full path of the executable invoked.

Definition at line 60 of file XrdSysUtils.cc.

61{
62 static const char *myEname = 0;
63
64// If we have been here before, simply return what we discovered. This is
65// relatively thread-safe as we might loose some memory but it will work.
66// Anyway, this method is unlikely to be called by multiple threads. Also,
67// according to gthe Condor team, this code will not be able to return the
68// program name if the program is under the control of valgrind!
69//
70 if (myEname) return myEname;
71
72// Get the exec name based on platform
73//
74#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
75 {char epBuff[2048];
76 int epLen;
77 if ((epLen = readlink("/proc/self/exe", epBuff, sizeof(epBuff)-1)) > 0)
78 {epBuff[epLen] = 0;
79 myEname = strdup(epBuff);
80 return myEname;
81 }
82 }
83#elif defined(__APPLE__)
84 {char epBuff[2048];
85 uint32_t epLen = sizeof(epBuff)-1;
86 if (!_NSGetExecutablePath(epBuff, &epLen))
87 {epBuff[epLen] = 0;
88 myEname = strdup(epBuff);
89 return myEname;
90 }
91 }
92#elif defined(__solaris__)
93 {const char *epBuff = getexecname();
94 if (epBuff)
95 {if (*epBuff == '/') myEname = strdup(epBuff);
96 else {char *ename, *cwd = getcwd(0, MAXPATHLEN);
97 ename = (char *)malloc(strlen(cwd)+1+strlen(epBuff)+1);
98 sprintf(ename, "%s/%s", cwd, epBuff);
99 myEname = ename;
100 free(cwd);
101 }
102 return myEname;
103 }
104 }
105#else
106#endif
107
108// If got here then we don't have a valid program name. Return a null string.
109//
110 return "";
111}

Referenced by XrdCl::DefaultEnv::GetMonitor().

+ Here is the caller graph for this function:

◆ FmtUname()

int XrdSysUtils::FmtUname ( char * buff,
int blen )
static

Format the uname information

Parameters
buff- pointer to the buffer to hold the uname as: <sysname> <release> [<version>] [<machine>]
blen- length of the buffer.
Returns
the output of snprintf(buff, blen, ...);

Definition at line 117 of file XrdSysUtils.cc.

118{
119#if defined(WINDOWS)
120 return snprintf(buff, blen, "%s", "windows");
121#else
122 struct utsname uInfo;
123
124// Obtain the uname inofmormation
125//
126 if (uname(&uInfo) < 0) return snprintf(buff, blen, "%s", "unknown OS");
127
128// Format appropriate for certain platforms
129// Linux and MacOs do not add usefull version information
130//
131#if defined(__linux__)
132 return snprintf(buff, blen, "%s %s", uInfo.sysname, uInfo.release);
133#elif defined(__APPLE__) || defined(__FreeBSD__) || (defined(__FreeBSD__) || defined(__GLIBC__))
134 return snprintf(buff, blen, "%s %s %s", uInfo.sysname, uInfo.release,
135 uInfo.machine);
136#else
137 return snprintf(buff, blen, "%s %s %s %s", uInfo.sysname, uInfo.release,
138 uInfo.version, uInfo.machine);
139#endif
140#endif
141}

Referenced by XrdConfig::Configure().

+ Here is the caller graph for this function:

◆ GetSigNum()

int XrdSysUtils::GetSigNum ( const char * sname)
static

Get common signal number.

Parameters
sname- the signal name as in sigxxx or just xxx (see kill).
Returns
=0 - unknown or unsupported signal.
!0 - the corresponding signal number.

Definition at line 165 of file XrdSysUtils.cc.

166{
167 int i;
168
169// Trim off the "sig" in sname
170//
171 if (!strncmp(sname, "sig", 3) || !strncmp(sname, "SIG", 3)) sname += 3;
172
173// Convert to signal number
174//
175 for (i = 0; i < snum; i++)
176 {if (!strcmp(sname, sigtab[i].sname)) return sigtab[i].snum;}
177 return 0;
178}

Referenced by XrdSysLogger::ParseKeep().

+ Here is the caller graph for this function:

◆ SigBlock() [1/2]

bool XrdSysUtils::SigBlock ( )
static

Block common signals. This must be called at program start.

Returns
true - common signals are blocked.
false - common signals not blocked, errno has the reason.

Definition at line 184 of file XrdSysUtils.cc.

185{
186 sigset_t myset;
187
188// Ignore pipe signals and prepare to blocks others
189//
190 signal(SIGPIPE, SIG_IGN); // Solaris optimization
191
192// Add the standard signals we normally always block
193//
194 sigemptyset(&myset);
195 sigaddset(&myset, SIGPIPE);
196 sigaddset(&myset, SIGCHLD);
197
198// Block a couple of real-time signals if they are supported (async I/O)
199//
200#ifdef SIGRTMAX
201 sigaddset(&myset, SIGRTMAX);
202 sigaddset(&myset, SIGRTMAX-1);
203#endif
204
205// Now turn off these signals
206//
207 return pthread_sigmask(SIG_BLOCK, &myset, NULL) == 0;
208}

Referenced by XrdSysLogger::Bind(), and main().

+ Here is the caller graph for this function:

◆ SigBlock() [2/2]

bool XrdSysUtils::SigBlock ( int numsig)
static

Block a particular signal. This should be called at program start so that the block applies to all threads.

@aparam numsig - The signal value to be blocked.

Returns
true - signal is blocked.
false - signal not blocked, errno has the reason.

Definition at line 212 of file XrdSysUtils.cc.

213{
214 sigset_t myset;
215
216// Ignore pipe signals and prepare to blocks others
217//
218 if (sigemptyset(&myset) == -1 || sigaddset(&myset, numsig) == -1)
219 return false;
220
221// Now turn off these signals
222//
223 return pthread_sigmask(SIG_BLOCK, &myset, NULL) == 0;
224}

The documentation for this class was generated from the following files: