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.

{}

## ~XrdSysUtils()

XrdSysUtils::~XrdSysUtils | ( |  | ) |

inline

Definition at line 97 of file XrdSysUtils.hh.

{}

## 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.

{
static const char *myEname = 0;
// If we have been here before, simply return what we discovered. This is
// relatively thread-safe as we might loose some memory but it will work.
// Anyway, this method is unlikely to be called by multiple threads. Also,
// according to gthe Condor team, this code will not be able to return the
// program name if the program is under the control of valgrind!
//
if (myEname) return myEname;
// Get the exec name based on platform
//
#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
{char epBuff[2048];
int epLen;
if ((epLen = readlink("/proc/self/exe", epBuff, sizeof(epBuff)-1)) > 0)
{epBuff[epLen] = 0;
myEname = strdup(epBuff);
return myEname;
}
}
#elif defined(__APPLE__)
{char epBuff[2048];
uint32_t epLen = sizeof(epBuff)-1;
if (!_NSGetExecutablePath(epBuff, &epLen))
{epBuff[epLen] = 0;
myEname = strdup(epBuff);
return myEname;
}
}
#elif defined(__solaris__)
{const char *epBuff = getexecname();
if (epBuff)
{if (*epBuff == '/') myEname = strdup(epBuff);
else {char *ename, *cwd = getcwd(0, MAXPATHLEN);
ename = (char *)malloc(strlen(cwd)+1+strlen(epBuff)+1);
sprintf(ename, "%s/%s", cwd, epBuff);
myEname = ename;
free(cwd);
}
return myEname;
}
}
#else
#endif
// If got here then we don't have a valid program name. Return a null string.
//
return "";
}

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.

{
#if defined(WINDOWS)
return snprintf(buff, blen, "%s", "windows");
#else
struct utsname uInfo;
// Obtain the uname inofmormation
//
if (uname(&uInfo) < 0) return snprintf(buff, blen, "%s", "unknown OS");
// Format appropriate for certain platforms
// Linux and MacOs do not add usefull version information
//
#if defined(__linux__)
return snprintf(buff, blen, "%s %s", uInfo.sysname, uInfo.release);
#elif defined(__APPLE__) || defined(__FreeBSD__) || (defined(__FreeBSD__) || defined(__GLIBC__))
return snprintf(buff, blen, "%s %s %s", uInfo.sysname, uInfo.release,
uInfo.machine);
#else
return snprintf(buff, blen, "%s %s %s %s", uInfo.sysname, uInfo.release,
uInfo.version, uInfo.machine);
#endif
#endif
}

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.

{
int i;
// Trim off the "sig" in sname
//
if (!strncmp(sname, "sig", 3) || !strncmp(sname, "SIG", 3)) sname += 3;
// Convert to signal number
//
for (i = 0; i < snum; i++)
{if (!strcmp(sname, sigtab[i].sname)) return sigtab[i].snum;}
return 0;
}

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 188 of file XrdSysUtils.cc.

{
sigset_t myset;
// Ignore pipe signals and prepare to blocks others
//
signal(SIGPIPE, SIG_IGN); // Solaris optimization
#ifdef ENABLE_COVERAGE
// Dump coverage information and exit upon receiving a TERM signal
signal(SIGTERM, [](int) { __gcov_dump(); _exit(EXIT_SUCCESS); });
#endif
// Add the standard signals we normally always block
//
sigemptyset(&myset);
sigaddset(&myset, SIGPIPE);
sigaddset(&myset, SIGCHLD);
// Block a couple of real-time signals if they are supported (async I/O)
//
#ifdef SIGRTMAX
sigaddset(&myset, SIGRTMAX);
sigaddset(&myset, SIGRTMAX-1);
#endif
// Now turn off these signals
//
return pthread_sigmask(SIG_BLOCK, &myset, NULL) == 0;
}

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 221 of file XrdSysUtils.cc.

{
sigset_t myset;
// Ignore pipe signals and prepare to blocks others
//
if (sigemptyset(&myset) == -1 || sigaddset(&myset, numsig) == -1)
return false;
// Now turn off these signals
//
return pthread_sigmask(SIG_BLOCK, &myset, NULL) == 0;
}

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

- XrdSysUtils.hh
- XrdSysUtils.cc