38 #include <sys/param.h>
41 #include <mach-o/dyld.h>
46 #include "XrdSys/XrdWin32.hh"
51 #include <sys/types.h>
52 #include <sys/utsname.h>
62 static const char *myEname = 0;
70 if (myEname)
return myEname;
74 #if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
77 if ((epLen = readlink(
"/proc/self/exe", epBuff,
sizeof(epBuff)-1)) > 0)
79 myEname = strdup(epBuff);
83 #elif defined(__APPLE__)
85 uint32_t epLen =
sizeof(epBuff)-1;
86 if (!_NSGetExecutablePath(epBuff, &epLen))
88 myEname = strdup(epBuff);
92 #elif defined(__solaris__)
93 {
const char *epBuff = getexecname();
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);
120 return snprintf(buff, blen,
"%s",
"windows");
122 struct utsname uInfo;
126 if (uname(&uInfo) < 0)
return snprintf(buff, blen,
"%s",
"unknown OS");
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,
137 return snprintf(buff, blen,
"%s %s %s %s", uInfo.sysname, uInfo.release,
138 uInfo.version, uInfo.machine);
149 static struct SigTab {
const char *sname;
int snum;} sigtab[] =
150 {{
"hup", SIGHUP}, {
"HUP", SIGHUP},
152 {
"rtmin", SIGRTMIN}, {
"RTMIN", SIGRTMIN},
153 {
"rtmin+1", SIGRTMIN+1}, {
"RTMIN+1", SIGRTMIN+1},
154 {
"rtmin+2", SIGRTMIN+2}, {
"RTMIN+2", SIGRTMIN+2},
156 {
"ttou", SIGTTOU}, {
"TTOU", SIGTTOU},
159 {
"winch", SIGWINCH}, {
"WINCH", SIGWINCH},
160 {
"xfsz", SIGXFSZ}, {
"XFSZ", SIGXFSZ}
162 static int snum =
sizeof(sigtab)/
sizeof(
struct SigTab);
171 if (!strncmp(sname,
"sig", 3) || !strncmp(sname,
"SIG", 3)) sname += 3;
175 for (i = 0; i < snum; i++)
176 {
if (!strcmp(sname, sigtab[i].sname))
return sigtab[i].snum;}
180 #ifdef ENABLE_COVERAGE
181 extern "C" void __gcov_dump(
void);
194 signal(SIGPIPE, SIG_IGN);
196 #ifdef ENABLE_COVERAGE
198 signal(SIGTERM, [](
int) { __gcov_dump(); _exit(EXIT_SUCCESS); });
204 sigaddset(&myset, SIGPIPE);
205 sigaddset(&myset, SIGCHLD);
210 sigaddset(&myset, SIGRTMAX);
211 sigaddset(&myset, SIGRTMAX-1);
216 return pthread_sigmask(SIG_BLOCK, &myset, NULL) == 0;
227 if (sigemptyset(&myset) == -1 || sigaddset(&myset, numsig) == -1)
232 return pthread_sigmask(SIG_BLOCK, &myset, NULL) == 0;
static const char * ExecName()
static int FmtUname(char *buff, int blen)
static int GetSigNum(const char *sname)