20#include "RConfigure.h"
51#if defined(R__SUN) || defined(R__AIX) || \
52 defined(R__LINUX) || defined(R__SOLARIS) || \
53 defined(R__FBSD) || defined(R__OBSD) || \
54 defined(R__MACOSX) || defined(R__HURD)
62#if defined(ULTRIX) || defined(R__SUN)
65#if defined(R__AIX) || defined(R__LINUX) || \
66 defined(R__FBSD) || defined(R__OBSD) || \
67 defined(R__LYNXOS) || defined(R__MACOSX) || defined(R__HURD)
68# include <sys/ioctl.h>
70#if defined(R__AIX) || defined(R__SOLARIS)
71# include <sys/select.h>
74# include <mach-o/dyld.h>
75# include <sys/mount.h>
76 extern "C" int statfs(
const char *
file,
struct statfs *buffer);
77#elif defined(R__LINUX) || defined(R__HURD)
79#elif defined(R__FBSD) || defined(R__OBSD)
80# include <sys/param.h>
81# include <sys/mount.h>
84# include <sys/types.h>
85# include <sys/param.h>
86# include <sys/queue.h>
87# include <libprocstat.h>
91# include <sys/statfs.h>
103#include <sys/resource.h>
108#include <sys/socket.h>
109#include <netinet/in.h>
110#include <netinet/tcp.h>
112# define _XOPEN_EXTENDED_SOURCE
113# include <arpa/inet.h>
114# undef _XOPEN_EXTENDED_SOURCE
115# if !defined(_AIX41) && !defined(_AIX43)
117# define HASNOT_INETATON
120# include <arpa/inet.h>
125#if defined(R__SOLARIS)
126# include <sys/systeminfo.h>
127# include <sys/filio.h>
128# include <sys/sockio.h>
129# define HASNOT_INETATON
131# define INADDR_NONE (UInt_t)-1
135#if defined(R__SOLARIS)
140#if defined(MAC_OS_X_VERSION_10_5)
146# include <sys/param.h>
147# if __FreeBSD_version >= 900007
152#if defined(R__AIX) || defined(R__FBSD) || \
153 defined(R__OBSD) || defined(R__LYNXOS) || \
154 (defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5))
158#if defined(R__LYNXOS)
160 extern int putenv(
const char *);
161 extern int inet_aton(
const char *,
struct in_addr *);
167#define STRUCT_UTMP struct utmpx
170#define STRUCT_UTMP struct utmp
172#if !defined(UTMP_FILE) && defined(_PATH_UTMP)
173#define UTMP_FILE _PATH_UTMP
175#if defined(UTMPX_FILE)
177#define UTMP_FILE UTMPX_FILE
180#define UTMP_FILE "/etc/utmp"
184#if (defined(R__LINUX) || defined(R__HURD)) && !defined(R__WINGCC)
185# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
186# define HAVE_BACKTRACE_SYMBOLS_FD
190#if defined(R__MACOSX) || defined(R__FBSD)
191# define HAVE_BACKTRACE_SYMBOLS_FD
195#ifdef HAVE_BACKTRACE_SYMBOLS_FD
196# include <execinfo.h>
205#ifdef HAVE_BACKTRACE_SYMBOLS_FD
208 static const int kMAX_BACKTRACE_DEPTH = 128;
212#if (defined(R__LINUX) && !defined(R__WINGCC))
214#include <sys/prctl.h>
217#if defined(R__MACOSX) && defined(__SSE2__)
218#include <xmmintrin.h>
221#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
222 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
229#include <mach/thread_status.h>
231#define fegetenvd(x) asm volatile("mffs %0" : "=f" (x));
232#define fesetenvd(x) asm volatile("mtfsf 255,%0" : : "f" (x));
235 FE_ENABLE_INEXACT = 0x00000008,
236 FE_ENABLE_DIVBYZERO = 0x00000010,
237 FE_ENABLE_UNDERFLOW = 0x00000020,
238 FE_ENABLE_OVERFLOW = 0x00000040,
239 FE_ENABLE_INVALID = 0x00000080,
240 FE_ENABLE_ALL_EXCEPT = 0x000000F8
244#if defined(R__MACOSX) && !defined(__SSE2__) && \
245 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
257 template<
typename U = T,
typename std::enable_if<std::is_member_po
inter<decltype(&U::ut_name)>::value,
int>::type = 0>
258 static char getValue(U* ue,
int) {
259 return ue->ut_name[0];
262 template<
typename U = T,
typename std::enable_if<std::is_member_po
inter<decltype(&U::ut_user)>::value,
int>::type = 0>
263 static char getValue(U* ue,
long) {
264 return ue->ut_user[0];
270 return ut_name<STRUCT_UTMP>::getValue(ue, 0);
289 if (get_ut_name(ue) && !strncmp(tty, ue->ut_line,
sizeof(ue->ut_line)))
301 struct stat file_stats;
312 if (fstat(fileno(utmp), &file_stats) == -1) {
316 size = file_stats.st_size;
330 if (fclose(utmp) != EOF && n_read ==
size) {
349# define HOWMANY(x, y) (((x)+((y)-1))/(y))
409 TTHREAD_TLS_DECL(
TString,exepath);
411#if defined(R__MACOSX)
412 exepath = _dyld_get_image_name(0);
413#elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__FBSD)
418 int ret = readlink(
"/proc/self/exe", buf,
kMAXPATHLEN);
419#elif defined(R__SOLARIS)
420 int ret = readlink(
"/proc/self/path/a.out", buf,
kMAXPATHLEN);
421#elif defined(R__FBSD)
422 procstat* ps = procstat_open_sysctl();
423 kinfo_proc* kp = kinfo_getproc(getpid());
427 procstat_getpathname(ps, kp, buf,
sizeof(buf));
441 if (
p.BeginsWith(
"/"))
443 else if (
p.Contains(
"/")) {
459#if defined(HAVE_DLADDR) && !defined(R__MACOSX)
469 if (dladdr(addr, &info) && info.dli_fname && info.dli_fname[0]) {
471 if (!realpath(info.dli_fname, respath)) {
473 ::SysError(
"TUnixSystem::SetRootSys",
"error getting realpath of libCore, please set ROOTSYS in the shell");
485#if defined(R__MACOSX)
490static void DylibAdded(
const struct mach_header *mh, intptr_t )
499 gLinkedDylibs = linkedDylibs;
503 TString lib = _dyld_get_image_name(i++);
505 TRegexp sovers =
"libCore\\.[0-9]+\\.*[0-9]*\\.*[0-9]*\\.so";
506 TRegexp dyvers =
"libCore\\.[0-9]+\\.*[0-9]*\\.*[0-9]*\\.dylib";
514 if (!realpath(lib, respath)) {
516 ::SysError(
"TUnixSystem::DylibAdded",
"error getting realpath of libCore, please set ROOTSYS in the shell");
530 if (lib.
EndsWith(
"/libSystem.B.dylib")) {
532 if (linkedDylibs.
IsNull()) {
542 sovers =
"\\.[0-9]+\\.*[0-9]*\\.so";
548 dyvers =
"\\.[0-9]+\\.*[0-9]*\\.dylib";
549 idx = lib.
Index(dyvers);
555 if (linkedDylibs.
Length())
611#if defined(R__MACOSX)
614 _dyld_register_func_for_add_image(DylibAdded);
615#elif defined(HAVE_DLADDR)
658 char *tty = ::ttyname(0);
667 if (utmp_entry->ut_host[0]) {
669 for (
unsigned n = 0; (
n <
sizeof(utmp_entry->ut_host)) && utmp_entry->ut_host[
n];
n++)
670 disp.
Append(utmp_entry->ut_host[
n]);
674 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s", disp.
Data());
677 else if (utmp_entry->ut_addr) {
679 struct sockaddr_in addr;
680 addr.sin_family = AF_INET;
682 memcpy(&addr.sin_addr, &utmp_entry->ut_addr,
sizeof(addr.sin_addr));
683 memset(&addr.sin_zero[0], 0,
sizeof(addr.sin_zero));
684 struct sockaddr *sa = (
struct sockaddr *) &addr;
686 char hbuf[NI_MAXHOST + 4];
687 if (getnameinfo(sa,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, NI_NAMEREQD) == 0) {
688 assert( strlen(hbuf) < NI_MAXHOST );
689 strlcat(hbuf,
":0.0",
sizeof(hbuf));
691 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
699 if (!
gROOT->IsBatch() && !getenv(
"DISPLAY")) {
700 Error(
"SetDisplay",
"Can't figure out DISPLAY, set it manually\n"
701 "In case you run a remote ssh session, restart your ssh session with:\n"
702 "=========> ssh -Y");
717#if defined(R__SOLARIS) || defined (R__LINUX) || defined(R__AIX) || \
718 defined(R__FBSD) || defined(R__OBSD) || defined(R__HURD)
719 return strerror(err);
721 if (err < 0 || err >= sys_nerr)
722 return Form(
"errno out of range %d", err);
723 return sys_errlist[err];
734#if defined(R__SOLARIS)
735 sysinfo(SI_HOSTNAME, hn,
sizeof(hn));
737 gethostname(hn,
sizeof(hn));
757 if (
h->HasReadInterest()) {
761 if (
h->HasWriteInterest()) {
774 if (!
h)
return nullptr;
787 int fd = th->
GetFd();
819 if (!
h)
return nullptr;
888#if defined(R__LINUX) && !defined(__powerpc__)
889#if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
891#if __GLIBC_MINOR__>=3
893 Int_t oldmask = fegetexcept();
900 Int_t oldmask = ~oldenv;
902 Int_t oldmask = ~oldenv.__control_word;
916#if defined(R__MACOSX) && defined(__SSE2__)
918 Int_t oldmask = ~_MM_GET_EXCEPTION_MASK();
927#if defined(R__MACOSX) && !defined(__SSE2__) && \
928 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
933 Int_t oldmask = ~oldenv.__fpscr;
934#elif defined(__arm64__)
935 Int_t oldmask = ~oldenv.__fpcr;
937 Int_t oldmask = ~oldenv.__control;
947#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
948 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
973#if defined(R__LINUX) && !defined(__powerpc__)
974#if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
984#if __GLIBC_MINOR__>=3
987 feclearexcept(FE_ALL_EXCEPT);
988 fedisableexcept(FE_ALL_EXCEPT);
989 feenableexcept(newm);
998 cur.__control_word &= ~newm;
1006#if defined(R__MACOSX) && defined(__SSE2__)
1015 _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~newm);
1018#if defined(R__MACOSX) && !defined(__SSE2__) && \
1019 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
1030 cur.__fpscr &= ~newm;
1031#elif defined(__arm64__)
1032 cur.__fpcr &= ~newm;
1034 cur.__control &= ~newm;
1039#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
1040 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
1051 curmask = (curmask & ~FE_ENABLE_ALL_EXCEPT) | newm;
1063 Bool_t pollOnce = pendingOnly;
1072 if (!pendingOnly)
return;
1078 if (!pendingOnly)
return;
1083 if (pendingOnly && !pollOnce)
1089 if (!pendingOnly)
return;
1120 if (mxfd == 0 && nextto == -1)
1127 for (fd = 0; fd < mxfd; fd++) {
1131 if (rc < 0 && rc != -2) {
1132 SysError(
"DispatchOneEvent",
"select: read error on %d", fd);
1138 if (rc < 0 && rc != -2) {
1139 SysError(
"DispatchOneEvent",
"select: write error on %d", fd);
1156 tv.tv_sec = milliSec / 1000;
1157 tv.tv_usec = (milliSec % 1000) * 1000;
1159 select(0,
nullptr,
nullptr,
nullptr, &tv);
1181 if (
h->HasReadInterest()) {
1185 if (
h->HasWriteInterest()) {
1189 h->ResetReadyMask();
1228 if (
h->HasReadInterest())
1230 if (
h->HasWriteInterest())
1232 h->ResetReadyMask();
1262 if (sync == sh->
IsSync()) {
1264 if ((
fSignals->
IsSet(sig) && sigdone == -1) || sigdone == sig) {
1265 if (sigdone == -1) {
1290 TIter next(zombieHandler);
1291 register UnixPtty *pty;
1292 while ((pty = (UnixPtty*) next()))
1293 if (pty->GetPid() == pid) {
1294 zombieHandler->RemovePtr(pty);
1313 if ((fd <= fMaxrfd && fReadready->IsSet(fd) && fddone == -1) ||
1314 (fddone == fd && read)) {
1324 if ((fd <= fMaxwfd && fWriteready->IsSet(fd) && fddone == -1) ||
1325 (fddone == fd && !read)) {
1381 ::closedir((DIR*)dirp);
1435 return std::string(cwd);
1444 Error(
"WorkingDirectory",
"getcwd() failed");
1463 if (res)
return std::string(res);
1464 else return std::string();
1496 char *arg =
StrDup(base);
1497 int fd = mkstemp(arg);
1505 FILE *fp = fdopen(fd,
"w+");
1507 SysError(
"TempFileName",
"converting filedescriptor (%d)", fd);
1517 if (
name.IsNull() ||
name ==
".") {
1520 if (dir[strlen(dir) - 1] !=
'/')
1526 if (!dir || !dir[0])
1528 else if (dir[strlen(dir) - 1] !=
'/')
1566 FILE *from = fopen(
f,
"r");
1570 FILE *to = fopen(t,
"w");
1576 const int bufsize = 1024;
1579 while (!ret && !feof(from)) {
1580 size_t numread = fread (buf,
sizeof(
char), bufsize, from);
1581 size_t numwritten = fwrite(buf,
sizeof(
char), numread, to);
1582 if (numread != numwritten)
1597 int ret = ::rename(
f, t);
1642 return UnixFSstat(path,
id, bsize, blocks, bfree);
1651 return ::link(from, to);
1661 return ::symlink((
char*)from, (
char*)to);
1663 return ::symlink(from, to);
1677#if defined(R__SEEK64)
1678 struct stat64 finfo;
1679 if (lstat64(
name, &finfo) < 0)
1682 if (lstat(
name, &finfo) < 0)
1686 if (S_ISDIR(finfo.st_mode))
1687 return ::rmdir(
name);
1689 return ::unlink(
name);
1698 kShellEscape =
'\\',
1699 *kShellStuff =
"(){}<>\"'",
1714 const char *
p, *patbuf = (
const char *)path;
1717 while (*patbuf ==
' ')
1721 for (
p = patbuf; *
p;
p++)
1746 const char *patbuf = (
const char *)patbuf0;
1755 while (*patbuf ==
' ')
1759 for (
p = patbuf; *
p;
p++)
1771 EscChar(patbuf, stuffedPat,
sizeof(stuffedPat), (
char*)kShellStuff, kShellEscape);
1776 if (stuffedPat[0] ==
'~') {
1777 if (stuffedPat[1] !=
'\0' && stuffedPat[1] !=
'/') {
1779 for (
p = &stuffedPat[1],
q =
name; *
p && *
p !=
'/';)
1796 cmd += &stuffedPat[1];
1801 if ((pf = ::popen(cmd.Data(),
"r")) == 0) {
1812 for (ch = fgetc(pf); ch != EOF && ch !=
' ' && ch !=
'\n'; ch = fgetc(pf)) {
1818 if (cnt == 0 && ch == EOF)
goto again;
1824 if (ch ==
' ' || ch ==
'\t') {
1866 return ::umask(
mask);
1879 t.actime = (time_t)actime;
1880 t.modtime = (time_t)modtime;
1881 return ::utime(
file, &t);
1894 show.
Form(
"Which: %s =", wfil.
Data());
1898 if (wfil[0] ==
'/') {
1899#if defined(R__SEEK64)
1900 struct stat64 finfo;
1901 if (access(wfil.
Data(),
mode) == 0 &&
1902 stat64(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1905 if (access(wfil.
Data(),
mode) == 0 &&
1906 stat(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1923 for (
const char* ptr = search; *ptr;) {
1925 if (*ptr !=
'/' && *ptr !=
'$' && *ptr !=
'~')
1927 const char* posEndOfPart = strchr(ptr,
':');
1929 name.Append(ptr, posEndOfPart - ptr);
1930 ptr = posEndOfPart + 1;
1936 if (!
name.EndsWith(
"/"))
1941#if defined(R__SEEK64)
1942 struct stat64 finfo;
1943 if (access(
name.Data(),
mode) == 0 &&
1944 stat64(
name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1947 if (access(
name.Data(),
mode) == 0 &&
1948 stat(
name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1970 if (!user || !user[0])
1973 struct passwd *apwd = getpwnam(user);
2020 static UserInfoCache_t gUserInfo;
2022 UserInfoCache_t::const_iterator iUserInfo = gUserInfo.find(uid);
2023 if (iUserInfo != gUserInfo.end())
2026 struct passwd *apwd = getpwuid(uid);
2039 gUserInfo[uid] = *ug;
2064 struct group *grp = getgrgid(gid);
2102 return ::getenv(
name);
2120 return ::system(shellcmd);
2128 return ::popen(command,
mode);
2136 return ::pclose(pipe);
2174#include <mach/mach.h>
2182 typedef CSTypeRef CSSymbolicatorRef;
2183 typedef CSTypeRef CSSourceInfoRef;
2184 typedef CSTypeRef CSSymbolOwnerRef;
2185 typedef CSTypeRef CSSymbolRef;
2187 CSSymbolicatorRef CSSymbolicatorCreateWithPid(pid_t pid);
2188 CSSymbolRef CSSymbolicatorGetSymbolWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2189 CSSourceInfoRef CSSymbolicatorGetSourceInfoWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2190 const char* CSSymbolGetName(CSSymbolRef
sym);
2191 CSSymbolOwnerRef CSSymbolGetSymbolOwner(CSSymbolRef
sym);
2192 const char* CSSymbolOwnerGetPath(CSSymbolOwnerRef symbol);
2193 const char* CSSourceInfoGetPath(CSSourceInfoRef info);
2194 int CSSourceInfoGetLineNumber(CSSourceInfoRef info);
2197bool CSTypeRefIdValid(CSTypeRef ref) {
2198 return ref.csCppData || ref.csCppObj;
2201void macosx_backtrace() {
2202void* addrlist[kMAX_BACKTRACE_DEPTH];
2204 int numstacks = backtrace( addrlist,
sizeof( addrlist ) /
sizeof(
void* ));
2206 CSSymbolicatorRef symbolicator = CSSymbolicatorCreateWithPid(getpid());
2209 static const int skipFrames = 2;
2210 for (
int i = skipFrames; i < numstacks; ++i) {
2212 CSSymbolRef
sym = CSSymbolicatorGetSymbolWithAddressAtTime(symbolicator,
2213 (vm_address_t)addrlist[i],
2215 CSSymbolOwnerRef symOwner = CSSymbolGetSymbolOwner(
sym);
2217 if (
const char* libPath = CSSymbolOwnerGetPath(symOwner)) {
2218 printf(
"[%s]", libPath);
2220 printf(
"[<unknown binary>]");
2223 if (
const char* symname = CSSymbolGetName(
sym)) {
2224 printf(
" %s", symname);
2227 CSSourceInfoRef sourceInfo
2228 = CSSymbolicatorGetSourceInfoWithAddressAtTime(symbolicator,
2229 (vm_address_t)addrlist[i],
2231 if (
const char* sourcePath = CSSourceInfoGetPath(sourceInfo)) {
2232 printf(
" %s:%d", sourcePath, (
int)CSSourceInfoGetLineNumber(sourceInfo));
2234 printf(
" (no debug info)");
2251 gdbscript = gdbscript.
Strip();
2252 if (gdbscript !=
"") {
2254 fprintf(stderr,
"Root.StacktraceScript %s does not exist\n", gdbscript.
Data());
2258 if (gdbscript ==
"") {
2259 gdbscript =
"gdb-backtrace.sh";
2262 fprintf(stderr,
"Error in <TUnixSystem::StackTrace> script %s is missing\n", gdbscript.
Data());
2269 gdbmess = gdbmess.
Strip();
2277 int fd = STDERR_FILENO;
2279 const char *message =
" Generating stack trace...\n";
2281 if (fd && message) { }
2284 Getlinem(kCleanUp,
nullptr);
2286#if defined(USE_GDB_STACK_TRACE)
2289 fprintf(stderr,
"gdb not found, need it for stack trace\n");
2294 TString gdbmessf =
"gdb-message";
2295 if (gdbmess !=
"") {
2297 fprintf(
f,
"%s\n", gdbmess.
Data());
2305 if (gdbmess !=
"") {
2307 gdbscript += gdbmessf;
2309 gdbscript +=
" 1>&2";
2314#elif defined(R__AIX)
2315 TString script =
"procstack ";
2319#elif defined(R__SOLARIS)
2330#elif defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_DLADDR)
2338 const char *cppfilt =
"c++filt";
2339 const char *cppfiltarg =
"";
2341 const char *format1 =
" 0x%016lx in %.200s %s 0x%lx from %.200s\n";
2343 const char *format2 =
" 0x%016lx in %.200s\n";
2345 const char *format2 =
" 0x%016lx in %.200s at %.200s from %.200s\n";
2347 const char *format3 =
" 0x%016lx in %.200s from %.200s\n";
2348 const char *format4 =
" 0x%016lx in <unknown function>\n";
2350 const char *format1 =
" 0x%08lx in %.200s %s 0x%lx from %.200s\n";
2352 const char *format2 =
" 0x%08lx in %.200s\n";
2354 const char *format2 =
" 0x%08lx in %.200s at %.200s from %.200s\n";
2356 const char *format3 =
" 0x%08lx in %.200s from %.200s\n";
2357 const char *format4 =
" 0x%08lx in <unknown function>\n";
2369 while (help.
Gets(
p)) {
2371 cppfiltarg =
"--format=gnu-v3";
2373 }
else if (help.
Index(
"gnu-new-abi") !=
kNPOS) {
2374 cppfiltarg =
"--format=gnu-new-abi";
2383#if (defined(R__LINUX) && !defined(R__WINGCC))
2386#ifdef PR_SET_PTRACER
2387 prctl(PR_SET_PTRACER, getpid(), 0, 0, 0);
2393 TString gdbmessf =
"gdb-message";
2394 if (gdbmess !=
"") {
2396 fprintf(
f,
"%s\n", gdbmess.
Data());
2406 if (gdbmess !=
"") {
2408 gdbscript += gdbmessf;
2410 gdbscript +=
" 1>&2";
2423 if (write(fd, message, strlen(message)) < 0)
2428 TString tmpf1 =
"gdb-backtrace";
2429 std::ofstream file1;
2435 Error(
"StackTrace",
"could not open file %s", tmpf1.
Data());
2447 void *trace[kMAX_BACKTRACE_DEPTH];
2448 int depth = backtrace(trace, kMAX_BACKTRACE_DEPTH);
2449 for (
int n = 5;
n < depth;
n++) {
2453 if (dladdr(trace[
n], &info) && info.dli_fname && info.dli_fname[0]) {
2454 const char *libname = info.dli_fname;
2455 const char *symname = (info.dli_sname && info.dli_sname[0]) ?
2456 info.dli_sname :
"<unknown>";
2459 Bool_t gte = (addr >= symaddr);
2460 ULong_t diff = (gte) ? addr - symaddr : symaddr - addr;
2461 if (addr2line && symaddr) {
2465#if defined(MAC_OS_X_VERSION_10_10)
2466 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2467#elif defined(MAC_OS_X_VERSION_10_9)
2469 snprintf(buffer,
sizeof(buffer),
"%s -d -p %d 0x%016lx", addr2line,
GetPid(), addr);
2471 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2480 if (
name.Contains(
".so") ||
name.Contains(
".sl")) noShare =
kFALSE;
2481 if (noShare)
offset = addr;
2482 if (noPath)
name =
"`which " +
name +
"`";
2483 snprintf(buffer,
sizeof(buffer),
"%s -e %s 0x%016lx", addr2line,
name.Data(),
offset);
2485 if (FILE *pf = ::popen(buffer,
"r")) {
2487 if (fgets(buf, 2048, pf)) {
2488 buf[strlen(buf)-1] = 0;
2489 if (strncmp(buf,
"??", 2)) {
2491 snprintf(buffer,
sizeof(buffer), format2, addr, buf);
2493 snprintf(buffer,
sizeof(buffer), format2, addr, symname, buf, libname);
2501 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2502 gte ?
"+" :
"-", diff, libname);
2505 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2506 gte ?
"+" :
"-", diff, libname);
2508 snprintf(buffer,
sizeof(buffer), format3, addr, symname, libname);
2511 snprintf(buffer,
sizeof(buffer), format4, addr);
2517 if (write(fd, buffer, ::strlen(buffer)) < 0)
2522 TString tmpf2 =
"gdb-backtrace";
2526 snprintf(buffer,
sizeof(buffer),
"%s %s < %s > %s", filter, cppfiltarg, tmpf1.
Data(), tmpf2.
Data());
2528 std::ifstream file2(tmpf2);
2532 line.ReadString(file2);
2533 if (write(fd,
line.Data(),
line.Length()) < 0)
2541 delete [] addr2line;
2544#elif defined(HAVE_EXCPT_H) && defined(HAVE_PDSC_H) && \
2545 defined(HAVE_RLD_INTERFACE_H)
2554 exc_capture_context (&context);
2555 while (!rc && context.sc_pc) {
2557 pdsc_crd *func, *base, *crd
2558 = exc_remote_lookup_function_entry(0, 0, context.sc_pc, 0, &func, &base);
2559 Elf32_Addr addr = PDSC_CRD_BEGIN_ADDRESS(base, func);
2561 const char *
name =
"<unknown function>";
2562 sprintf(buffer,
" 0x%012lx %.200s + 0x%lx\n",
2563 context.sc_pc,
name, context.sc_pc - addr);
2564 write(fd, buffer, ::strlen(buffer));
2565 rc = exc_virtual_unwind(0, &context);
2610 ::openlog(
name, options, fac);
2620 ::syslog(level,
"%s", mess);
2660 const char *tty = ttyname(STDOUT_FILENO);
2664 if ((xh->
fStdOutDup = dup(STDOUT_FILENO)) < 0) {
2672 const char *tty = ttyname(STDERR_FILENO);
2676 if ((xh->
fStdErrDup = dup(STDERR_FILENO)) < 0) {
2678 if (outdone && dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2679 Warning(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2688 const char *
m = (
mode[0] ==
'a' ||
mode[0] ==
'w') ?
mode :
"a";
2701 if (freopen(
file,
m, stdout) ==
nullptr) {
2705 if (freopen(
file,
m, stderr) ==
nullptr) {
2721 if (close(STDOUT_FILENO) != 0) {
2723 "problems closing STDOUT_FILENO (%d) before 'dup2' (errno: %d)",
2727 if (dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2728 SysError(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2734 "problems closing temporary 'out' descriptor %d (errno: %d)",
2747 if (close(STDERR_FILENO) != 0) {
2749 "problems closing STDERR_FILENO (%d) before 'dup2' (errno: %d)",
2753 if (dup2(xh->
fStdErrDup, STDERR_FILENO) < 0) {
2754 SysError(
"RedirectOutput",
"could not restore stderr (back to original redirected"
2760 "problems closing temporary 'err' descriptor %d (errno: %d)",
2805 Error(
"ListSymbols",
"not yet implemented");
2827 if (!linkedLibs.
IsNull())
2833#if !defined(R__MACOSX)
2839#if defined(R__MACOSX)
2841 linkedLibs = gLinkedDylibs;
2845 while (otool.
Gets(
p)) {
2850 if (!linkedLibs.
IsNull())
2852 linkedLibs += dylib;
2860#elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__AIX)
2861#if defined(R__WINGCC )
2862 const char *cLDD=
"cygcheck";
2863 const char *cSOEXT=
".dll";
2864 size_t lenexe = strlen(exe);
2865 if (strcmp(exe + lenexe - 4,
".exe")
2866 && strcmp(exe + lenexe - 4,
".dll")) {
2869 char* longerexe =
new char[lenexe + 5];
2870 strlcpy(longerexe, exe,lenexe+5);
2871 strlcat(longerexe,
".exe",lenexe+5);
2873 #error "unsupported platform, fix memory leak to use it"
2875 TRegexp sovers =
"\\.so\\.[0-9]+";
2877 const char *cLDD=
"ldd";
2879 const char *cSOEXT=
".a";
2880 TRegexp sovers =
"\\.a\\.[0-9]+";
2882 const char *cSOEXT=
".so";
2883 TRegexp sovers =
"\\.so\\.[0-9]+";
2889 while (ldd.
Gets(
p)) {
2908 if (!linkedLibs.
IsNull())
2910 linkedLibs += solib;
2983 if (!ti)
return nullptr;
3012 struct addrinfo hints;
3013 struct addrinfo *
result, *rp;
3014 memset(&hints, 0,
sizeof(
struct addrinfo));
3015 hints.ai_family = AF_INET;
3016 hints.ai_socktype = 0;
3017 hints.ai_protocol = 0;
3018 hints.ai_flags = AI_CANONNAME;
3023 size_t lenHostname = strlen(hostname);
3024 std::string hostnameWithoutLocal{hostname};
3025 if (lenHostname > 6 && !strcmp(hostname + lenHostname - 6,
".local")) {
3026 hostnameWithoutLocal.erase(lenHostname - 6);
3027 hostname = hostnameWithoutLocal.c_str();
3032 int rc = getaddrinfo(hostname,
nullptr, &hints, &
result);
3034 if (rc == EAI_NONAME) {
3035 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host '%s'", hostname);
3038 Error(
"GetHostByName",
"getaddrinfo failed for '%s': %s", hostname, gai_strerror(rc));
3044 std::string hostcanon(
result->ai_canonname ?
result->ai_canonname : hostname);
3047 ia.
fAddresses[0] = ntohl(((
struct sockaddr_in *)(
result->ai_addr))->sin_addr.s_addr);
3049 if (hostcanon.compare(hostname) != 0) ia.
AddAlias(hostname);
3052 char tmp[
sizeof(
struct in_addr)];
3053 if (inet_pton(AF_INET, hostcanon.data(), tmp) == 1) {
3054 char hbuf[NI_MAXHOST];
3055 if (getnameinfo(
result->ai_addr,
result->ai_addrlen, hbuf,
sizeof(hbuf),
nullptr, 0, 0) == 0)
3061 for (; rp !=
nullptr; rp = rp->ai_next) {
3062 UInt_t arp = ntohl(((
struct sockaddr_in *)(rp->ai_addr))->sin_addr.s_addr);
3076 struct sockaddr addr;
3077 socklen_t
len =
sizeof(addr);
3080 if (getsockname(sock, &addr, &
len) == -1) {
3081 SysError(
"GetSockName",
"getsockname failed");
3085 if (addr.sa_family != AF_INET)
return ia;
3087 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3088 ia.
fPort = ntohs(addrin->sin_port);
3089 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3091 char hbuf[NI_MAXHOST];
3092 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3093 Error(
"GetSockName",
"getnameinfo failed");
3106 struct sockaddr addr;
3107 socklen_t
len =
sizeof(addr);
3110 if (getpeername(sock, &addr, &
len) == -1) {
3111 SysError(
"GetPeerName",
"getpeername failed");
3115 if (addr.sa_family != AF_INET)
return ia;
3117 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3118 ia.
fPort = ntohs(addrin->sin_port);
3119 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3121 char hbuf[NI_MAXHOST];
3122 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3123 Error(
"GetPeerName",
"getnameinfo failed");
3138 if ((sp = getservbyname(servicename,
kProtocolName)) ==
nullptr) {
3139 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
3143 return ntohs(sp->s_port);
3153 if ((sp = getservbyport(htons(port),
kProtocolName)) ==
nullptr) {
3156 return Form(
"%d", port);
3165 int tcpwindowsize,
const char *protocol)
3167 if (!strcmp(servername,
"unix")) {
3173 if (!strcmp(protocol,
"udp")){
3243 while ((soc = ::accept(sock,
nullptr,
nullptr)) == -1 &&
GetErrno() == EINTR)
3250 SysError(
"AcceptConnection",
"accept");
3263 if (sock < 0)
return;
3265#if !defined(R__AIX) || defined(_AIX41) || defined(_AIX43)
3267 ::shutdown(sock, 2);
3270 while (::close(sock) == -1 &&
GetErrno() == EINTR)
3283 if (
UnixRecv(sock, &header,
sizeof(header), 0) > 0) {
3284 int count = ntohl(header);
3287 Error(
"RecvBuf",
"record header exceeds buffer size");
3289 }
else if (count > 0) {
3290 if (
UnixRecv(sock, buf, count, 0) < 0) {
3291 Error(
"RecvBuf",
"cannot receive buffer");
3308 if (
UnixSend(sock, &header,
sizeof(header), 0) < 0) {
3309 Error(
"SendBuf",
"cannot send header");
3314 Error(
"SendBuf",
"cannot send buffer");
3356 Error(
"RecvRaw",
"cannot receive buffer");
3391 Error(
"SendRaw",
"cannot send buffer");
3402 if (sock < 0)
return -1;
3406 if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == -1) {
3407 SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
3412 if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == -1) {
3413 SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
3418 if (setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == -1) {
3419 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
3424 if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == -1) {
3425 SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
3430 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == -1) {
3431 SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
3436 if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == -1) {
3437 SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
3442 if (ioctl(sock, FIONBIO, (
char*)&val) == -1) {
3443 SysError(
"SetSockOpt",
"ioctl(FIONBIO)");
3449 if (ioctl(sock, SIOCSPGRP, (
char*)&val) == -1) {
3450 SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
3454 Error(
"SetSockOpt",
"ioctl(SIOCGPGRP) not supported on cygwin/gcc");
3461 Error(
"SetSockOpt",
"illegal option (%d)", opt);
3472 if (sock < 0)
return -1;
3474 socklen_t optlen =
sizeof(*val);
3478 if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == -1) {
3479 SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
3484 if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == -1) {
3485 SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
3490 if (getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == -1) {
3491 SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
3496 if (getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == -1) {
3497 SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
3502 if (getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == -1) {
3503 SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
3508 if (getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == -1) {
3509 SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
3515 if ((flg = fcntl(sock, F_GETFL, 0)) == -1) {
3516 SysError(
"GetSockOpt",
"fcntl(F_GETFL)");
3519 *val = flg & O_NDELAY;
3522#if !defined(R__LYNXOS) && !defined(R__WINGCC)
3523 if (ioctl(sock, SIOCGPGRP, (
char*)val) == -1) {
3524 SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
3528 Error(
"GetSockOpt",
"ioctl(SIOCGPGRP) not supported on LynxOS and cygwin/gcc");
3533#if !defined(R__LYNXOS)
3534 if (ioctl(sock, SIOCATMARK, (
char*)val) == -1) {
3535 SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
3539 Error(
"GetSockOpt",
"ioctl(SIOCATMARK) not supported on LynxOS");
3544#if !defined(R__LYNXOS)
3545 if (ioctl(sock, FIONREAD, (
char*)val) == -1) {
3546 SysError(
"GetSockOpt",
"ioctl(FIONREAD)");
3550 Error(
"GetSockOpt",
"ioctl(FIONREAD) not supported on LynxOS");
3555 Error(
"GetSockOpt",
"illegal option (%d)", opt);
3576 { SIGBUS,
nullptr,
nullptr,
"bus error" },
3577 { SIGSEGV,
nullptr,
nullptr,
"segmentation violation" },
3578 { SIGSYS,
nullptr,
nullptr,
"bad argument to system call" },
3579 { SIGPIPE,
nullptr,
nullptr,
"write on a pipe with no one to read it" },
3580 { SIGILL,
nullptr,
nullptr,
"illegal instruction" },
3581 { SIGABRT,
nullptr,
nullptr,
"abort" },
3582 { SIGQUIT,
nullptr,
nullptr,
"quit" },
3583 { SIGINT,
nullptr,
nullptr,
"interrupt" },
3584 { SIGWINCH,
nullptr,
nullptr,
"window size change" },
3585 { SIGALRM,
nullptr,
nullptr,
"alarm clock" },
3586 { SIGCHLD,
nullptr,
nullptr,
"death of a child" },
3587 { SIGURG,
nullptr,
nullptr,
"urgent data arrived on an I/O channel" },
3588 { SIGFPE,
nullptr,
nullptr,
"floating point exception" },
3589 { SIGTERM,
nullptr,
nullptr,
"termination signal" },
3590 { SIGUSR1,
nullptr,
nullptr,
"user-defined signal 1" },
3591 { SIGUSR2,
nullptr,
nullptr,
"user-defined signal 2" }
3649 Break(
"TUnixSystem::DispatchSignals",
"%s: printing stacktrace",
UnixSigname(sig));
3672 struct sigaction sigact;
3679#elif defined(R__SOLARIS)
3681#elif defined(R__LYNXOS)
3685 sigact.sa_handler = (void (*)(...))
sighandler;
3690 sigemptyset(&sigact.sa_mask);
3691 sigact.sa_flags = 0;
3692#if defined(SA_RESTART)
3693 sigact.sa_flags |= SA_RESTART;
3695 if (sigaction(
gSignalMap[sig].fCode, &sigact,
3697 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3708 TTHREAD_TLS_ARRAY(
struct sigaction,
kMAXSIGNALS,oldsigact);
3710 if (ignore != ignoreSig[sig]) {
3711 ignoreSig[sig] = ignore;
3713 struct sigaction sigact;
3715 sigact.sa_handler = (void (*)())SIG_IGN;
3716#elif defined(R__SOLARIS)
3717 sigact.sa_handler = (void (*)(
int))SIG_IGN;
3719 sigact.sa_handler = SIG_IGN;
3721 sigemptyset(&sigact.sa_mask);
3722 sigact.sa_flags = 0;
3723 if (sigaction(
gSignalMap[sig].fCode, &sigact, &oldsigact[sig]) < 0)
3724 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3726 if (sigaction(
gSignalMap[sig].fCode, &oldsigact[sig],
nullptr) < 0)
3727 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3743 struct sigaction sigact;
3746#elif defined(R__SOLARIS)
3748#elif defined(R__LYNXOS)
3752 sigact.sa_handler = (void (*)(...))
sighandler;
3757 sigemptyset(&sigact.sa_mask);
3758 sigact.sa_flags = 0;
3760#if defined(SA_INTERRUPT)
3761 sigact.sa_flags |= SA_INTERRUPT;
3764#if defined(SA_RESTART)
3765 sigact.sa_flags |= SA_RESTART;
3769 ::SysError(
"TUnixSystem::UnixSigAlarmInterruptsSyscalls",
"sigaction");
3789 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3812 static std::atomic<time_t> jan95{0};
3823 jan95 = mktime(&tp);
3824 if ((
int)jan95 == -1) {
3825 ::SysError(
"TUnixSystem::UnixNow",
"error converting 950001 0:00 to time_t");
3831 gettimeofday(&t,
nullptr);
3840 struct itimerval itv;
3841 itv.it_value.tv_sec = 0;
3842 itv.it_value.tv_usec = 0;
3843 itv.it_interval.tv_sec = 0;
3844 itv.it_interval.tv_usec = 0;
3846 itv.it_value.tv_sec = time_t(ms / 1000);
3847 itv.it_value.tv_usec = time_t((ms % 1000) * 1000);
3849 int st = setitimer(ITIMER_REAL, &itv,
nullptr);
3851 ::SysError(
"TUnixSystem::UnixSetitimer",
"setitimer");
3869 fd_set *rd = (readready) ? (fd_set*)readready->
GetBits() :
nullptr;
3870 fd_set *wr = (writeready) ? (fd_set*)writeready->
GetBits() :
nullptr;
3874 tv.tv_sec =
Int_t(timeout / 1000);
3875 tv.tv_usec = (timeout % 1000) * 1000;
3876 retcode = select(nfds, rd, wr,
nullptr, &tv);
3878 retcode = select(nfds, rd, wr,
nullptr,
nullptr);
3880 if (retcode == -1) {
3911 pw = getpwnam(
name);
3920 pw = getpwuid(getuid());
3925 }
else if (pw && pw->
pw_dir) {
3953 if (stat(edir, &finfo) < 0)
3956 if (!S_ISDIR(finfo.st_mode))
3959 return (
void*) opendir(edir);
3962#if defined(_POSIX_SOURCE)
3965# define REAL_DIR_ENTRY(dp) 1
3967# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
3975 DIR *dirp = (DIR*)dirp1;
4007#if defined(R__SEEK64)
4009 if (path && lstat64(path, &sbuf) == 0) {
4012 if (path && lstat(path, &sbuf) == 0) {
4014 buf.
fIsLink = S_ISLNK(sbuf.st_mode);
4016#if defined(R__SEEK64)
4017 if (stat64(path, &sbuf) == -1) {
4019 if (stat(path, &sbuf) == -1) {
4024 buf.
fDev = sbuf.st_dev;
4025 buf.
fIno = sbuf.st_ino;
4026 buf.
fMode = sbuf.st_mode;
4027 buf.
fUid = sbuf.st_uid;
4028 buf.
fGid = sbuf.st_gid;
4029 buf.
fSize = sbuf.st_size;
4030 buf.
fMtime = sbuf.st_mtime;
4049 struct statfs statfsbuf;
4050#if (defined(R__SOLARIS) && !defined(R__LINUX))
4051 if (statfs(path, &statfsbuf,
sizeof(
struct statfs), 0) == 0) {
4052 *
id = statfsbuf.f_fstyp;
4053 *bsize = statfsbuf.f_bsize;
4054 *blocks = statfsbuf.f_blocks;
4055 *bfree = statfsbuf.f_bfree;
4057 if (statfs((
char*)path, &statfsbuf) == 0) {
4063 if (!strcmp(statfsbuf.f_fstypename, MOUNT_FFS) ||
4064 !strcmp(statfsbuf.f_fstypename, MOUNT_MFS))
4066 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NFS))
4068 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_MSDOS))
4070 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_EXT2FS))
4072 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_CD9660))
4074 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NCPFS))
4079 *
id = statfsbuf.f_type;
4081 *bsize = statfsbuf.f_bsize;
4082 *blocks = statfsbuf.f_blocks;
4083 *bfree = statfsbuf.f_bavail;
4096 return (
int) waitpid(0, &status, WNOHANG);
4117 sport = htons(port);
4120 if (!addr.
IsValid())
return -1;
4123 struct sockaddr_in server;
4124 memset(&server, 0,
sizeof(server));
4125 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4127 server.sin_port = sport;
4131 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4132 ::SysError(
"TUnixSystem::UnixTcpConnect",
"socket (%s:%d)",
4137 if (tcpwindowsize > 0) {
4142 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4146 ::SysError(
"TUnixSystem::UnixTcpConnect",
"connect (%s:%d)",
4168 sport = htons(port);
4171 if (!addr.
IsValid())
return -1;
4174 struct sockaddr_in server;
4175 memset(&server, 0,
sizeof(server));
4176 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4178 server.sin_port = sport;
4182 if ((sock =
socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4183 ::SysError(
"TUnixSystem::UnixUdpConnect",
"socket (%s:%d)",
4188 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4192 ::SysError(
"TUnixSystem::UnixUdpConnect",
"connect (%s:%d)",
4214 if (!sockpath || strlen(sockpath) <= 0) {
4215 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket path undefined");
4220 struct sockaddr_un unserver;
4221 unserver.sun_family = AF_UNIX;
4223 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4224 ::Error(
"TUnixSystem::UnixUnixConnect",
"socket path %s, longer than max allowed length (%u)",
4225 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4228 strlcpy(unserver.sun_path, sockpath,
sizeof(unserver.sun_path));
4231 if ((sock =
socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4232 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket");
4236 while (connect(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2) == -1) {
4240 ::SysError(
"TUnixSystem::UnixUnixConnect",
"connect");
4263 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4264 short sport, tryport = kSOCKET_MINPORT;
4267 if (port == 0 && reuse) {
4268 ::Error(
"TUnixSystem::UnixTcpService",
"cannot do a port scan while reuse is true");
4275 sport = htons(port);
4279 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4280 ::SysError(
"TUnixSystem::UnixTcpService",
"socket");
4287 if (tcpwindowsize > 0) {
4292 struct sockaddr_in inserver;
4293 memset(&inserver, 0,
sizeof(inserver));
4294 inserver.sin_family = AF_INET;
4295 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4296 inserver.sin_port = sport;
4300 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4301 ::SysError(
"TUnixSystem::UnixTcpService",
"bind");
4308 inserver.sin_port = htons(tryport);
4309 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4311 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4313 ::SysError(
"TUnixSystem::UnixTcpService",
"bind (port scan)");
4320 if (::listen(sock, backlog)) {
4321 ::SysError(
"TUnixSystem::UnixTcpService",
"listen");
4338 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4339 short sport, tryport = kSOCKET_MINPORT;
4345 sport = htons(port);
4349 if ((sock =
socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4350 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
4354 struct sockaddr_in inserver;
4355 memset(&inserver, 0,
sizeof(inserver));
4356 inserver.sin_family = AF_INET;
4357 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4358 inserver.sin_port = sport;
4362 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4363 ::SysError(
"TUnixSystem::UnixUdpService",
"bind");
4370 inserver.sin_port = htons(tryport);
4371 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4373 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4375 ::SysError(
"TUnixSystem::UnixUdpService",
"bind (port scan)");
4382 if (::listen(sock, backlog)) {
4383 ::SysError(
"TUnixSystem::UnixUdpService",
"listen");
4400 oldumask = umask(0);
4412 unlink(sockpath.
Data());
4423 if (!sockpath || strlen(sockpath) <= 0) {
4424 ::SysError(
"TUnixSystem::UnixUnixService",
"socket path undefined");
4428 struct sockaddr_un unserver;
4432 memset(&unserver, 0,
sizeof(unserver));
4433 unserver.sun_family = AF_UNIX;
4435 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4436 ::Error(
"TUnixSystem::UnixUnixService",
"socket path %s, longer than max allowed length (%u)",
4437 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4440 strlcpy(unserver.sun_path, sockpath,
sizeof(unserver.sun_path));
4443 if ((sock =
socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4444 ::SysError(
"TUnixSystem::UnixUnixService",
"socket");
4448 if (::bind(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2)) {
4449 ::SysError(
"TUnixSystem::UnixUnixService",
"bind");
4455 if (::listen(sock, backlog)) {
4456 ::SysError(
"TUnixSystem::UnixUnixService",
"listen");
4475 if (sock < 0)
return -1;
4482 if (flag == MSG_PEEK)
4486 char *buf = (
char *)buffer;
4489 if ((nrecv = recv(sock, buf+
n,
length-
n, flag)) <= 0) {
4492 if (flag == MSG_OOB) {
4523 if (sock < 0)
return -1;
4532 const char *buf = (
const char *)buffer;
4535 if ((nsent = send(sock, buf+
n,
length-
n, flag)) <= 0) {
4563 static std::atomic<bool> initialized(
kFALSE);
4564 static std::atomic<bool> seenCling(
kFALSE);
4568 if (newpath ==
nullptr && !reset && (seenCling || (initialized &&
gCling ==
nullptr)))
4569 return dynpath_full;
4574 dynpath_full = newpath;
4576 initialized =
kTRUE;
4584 return dynpath_full;
4590 if (!reset && (seenCling || (initialized &&
gCling ==
nullptr)))
4591 return dynpath_full;
4600 static TString dynpath_envpart;
4601 static TString dynpath_syspart;
4603 if (reset || !initialized) {
4612 #if defined (R__AIX)
4614 #elif defined(R__MACOSX)
4626 if (!dynpath_envpart.
IsNull())
4627 dynpath_envpart +=
":";
4628 dynpath_envpart += ldpath;
4630 if (!rdynpath.
IsNull()) {
4631 if (!dynpath_envpart.
IsNull())
4632 dynpath_envpart +=
":";
4633 dynpath_envpart += rdynpath;
4639 #if defined(R__WINGCC) || defined(R__MACOSX)
4641 dynpath_syspart =
"/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:";
4642 dynpath_syspart +=
"/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:";
4645 std::string cmd(
"LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls 2>&1");
4646 FILE *pf = popen(cmd.c_str (),
"r");
4650 if (fgets(buffer, 128, pf) != NULL)
4654 std::size_t from =
result.find(
"search path=",
result.find(
"(LD_LIBRARY_PATH)"));
4655 std::size_t to =
result.find(
"(system search path)");
4656 if (from != std::string::npos && to != std::string::npos) {
4658 std::string sys_path =
result.substr(from, to-from);
4659 sys_path.erase(std::remove_if(sys_path.begin(), sys_path.end(), isspace), sys_path.end());
4660 dynpath_syspart = sys_path.c_str();
4667 if (!initialized || (!seenCling &&
gCling)) {
4668 dynpath_full = dynpath_envpart;
4669 if (!dynpath_full.
EndsWith(
":")) dynpath_full +=
":";
4672 if (!dynpath_full.
EndsWith(
":")) dynpath_full +=
":";
4676 dynpath_full += dynpath_syspart;
4677 initialized =
kTRUE;
4679 if (
gDebug > 0) std::cout <<
"dynpath = " << dynpath_full.
Data() << std::endl;
4682 return dynpath_full;
4726 char buf[PATH_MAX + 1];
4727 char *res = realpath(sLib.
Data(), buf);
4728 if (res) sLib = buf;
4734 const char* lib = sLib.
Data();
4736 if (
len > 3 && (!strcmp(lib+
len-3,
".so") ||
4737 !strcmp(lib+
len-3,
".dl") ||
4738 !strcmp(lib+
len-4,
".dll") ||
4739 !strcmp(lib+
len-4,
".DLL") ||
4740 !strcmp(lib+
len-6,
".dylib") ||
4741 !strcmp(lib+
len-3,
".sl") ||
4742 !strcmp(lib+
len-2,
".a"))) {
4747 Error(
"FindDynamicLibrary",
4751 static const char* exts[] = {
4752 ".so",
".dll",
".dylib",
".sl",
".dl",
".a",
nullptr };
4753 const char** ext = exts;
4765 Error(
"FindDynamicLibrary",
4766 "%s[.so | .dll | .dylib | .sl | .dl | .a] does not exist in %s",
4778static void GetFreeBSDSysInfo(
SysInfo_t *sysinfo)
4783 "hw.physmem dev.cpu.0.freq",
"r");
4806#if defined(R__MACOSX)
4807#include <sys/resource.h>
4808#include <mach/mach.h>
4809#include <mach/mach_error.h>
4814static void GetDarwinSysInfo(
SysInfo_t *sysinfo)
4816 FILE *
p =
gSystem->
OpenPipe(
"sysctl -n kern.ostype hw.model hw.ncpu hw.cpufrequency "
4817 "hw.busfrequency hw.l2cachesize hw.memsize",
"r");
4850static void ReadDarwinCpu(
long *ticks)
4852 mach_msg_type_number_t count;
4854 host_cpu_load_info_data_t cpu;
4856 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
4858 count = HOST_CPU_LOAD_INFO_COUNT;
4859 kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpu, &count);
4860 if (kr != KERN_SUCCESS) {
4861 ::Error(
"TUnixSystem::ReadDarwinCpu",
"host_statistics: %s", mach_error_string(kr));
4863 ticks[0] = cpu.cpu_ticks[CPU_STATE_USER];
4864 ticks[1] = cpu.cpu_ticks[CPU_STATE_SYSTEM];
4865 ticks[2] = cpu.cpu_ticks[CPU_STATE_IDLE];
4866 ticks[3] = cpu.cpu_ticks[CPU_STATE_NICE];
4874static void GetDarwinCpuInfo(
CpuInfo_t *cpuinfo,
Int_t sampleTime)
4877 if (getloadavg(avg,
sizeof(avg)) < 0) {
4878 ::Error(
"TUnixSystem::GetDarwinCpuInfo",
"getloadavg failed");
4885 Long_t cpu_ticks1[4], cpu_ticks2[4];
4886 ReadDarwinCpu(cpu_ticks1);
4888 ReadDarwinCpu(cpu_ticks2);
4890 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
4891 (cpu_ticks1[0] + cpu_ticks1[3]);
4892 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
4893 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
4894 if (userticks < 0) userticks = 0;
4895 if (systicks < 0) systicks = 0;
4896 if (idleticks < 0) idleticks = 0;
4897 Long_t totalticks = userticks + systicks + idleticks;
4909static void GetDarwinMemInfo(
MemInfo_t *meminfo)
4911 static Int_t pshift = 0;
4913 vm_statistics_data_t vm_info;
4914 mach_msg_type_number_t count;
4919 count = HOST_VM_INFO_COUNT;
4920 kr = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_info, &count);
4921 if (kr != KERN_SUCCESS) {
4922 ::Error(
"TUnixSystem::GetDarwinMemInfo",
"host_statistics: %s", mach_error_string(kr));
4926 for (
int psize = getpagesize(); psize > 1; psize >>= 1)
4930 used = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.wire_count) << pshift;
4932 total = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.free_count + vm_info.wire_count) << pshift;
4935 swap_used = vm_info.pageouts << pshift;
4938 dirp = opendir(
"/private/var/vm");
4943 while ((dp = readdir(dirp)) != 0) {
4945 char fname [MAXNAMLEN];
4946 if (strncmp(dp->d_name,
"swapfile", 8))
4948 strlcpy(fname,
"/private/var/vm/",MAXNAMLEN);
4949 strlcat (fname, dp->d_name,MAXNAMLEN);
4950 if (stat(fname, &sb) < 0)
4952 swap_total += sb.st_size;
4972static void GetDarwinProcInfo(
ProcInfo_t *procinfo)
4975#define vm_region vm_region_64
4979#define GLOBAL_SHARED_TEXT_SEGMENT 0x90000000U
4980#define GLOBAL_SHARED_DATA_SEGMENT 0xA0000000U
4981#define SHARED_TEXT_REGION_SIZE 0x10000000
4982#define SHARED_DATA_REGION_SIZE 0x10000000
4985 if (getrusage(RUSAGE_SELF, &ru) < 0) {
4986 ::SysError(
"TUnixSystem::GetDarwinProcInfo",
"getrusage failed");
4989 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
4991 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
4994 task_basic_info_data_t ti;
4995 mach_msg_type_number_t count;
4998 task_t a_task = mach_task_self();
5000 count = TASK_BASIC_INFO_COUNT;
5001 kr = task_info(a_task, TASK_BASIC_INFO, (task_info_t)&ti, &count);
5002 if (kr != KERN_SUCCESS) {
5003 ::Error(
"TUnixSystem::GetDarwinProcInfo",
"task_info: %s", mach_error_string(kr));
5008 mach_port_t object_name;
5009 vm_address_t address;
5010 vm_region_top_info_data_t info;
5011 vm_size_t vprvt, rsize,
size;
5012 rsize = ti.resident_size;
5014 for (address = 0; ; address +=
size) {
5016 count = VM_REGION_TOP_INFO_COUNT;
5017 if (vm_region(a_task, &address, &
size,
5018 VM_REGION_TOP_INFO, (vm_region_info_t)&info, &count,
5019 &object_name) != KERN_SUCCESS) {
5024 if (address >= GLOBAL_SHARED_TEXT_SEGMENT &&
5025 address < (GLOBAL_SHARED_DATA_SEGMENT + SHARED_DATA_REGION_SIZE)) {
5030 if (info.share_mode == SM_EMPTY) {
5031 vm_region_basic_info_data_64_t b_info;
5032 count = VM_REGION_BASIC_INFO_COUNT_64;
5033 if (vm_region_64(a_task, &address,
5034 &
size, VM_REGION_BASIC_INFO,
5035 (vm_region_info_t)&b_info, &count,
5036 &object_name) != KERN_SUCCESS) {
5043 if (info.share_mode != SM_PRIVATE) {
5047 switch (info.share_mode) {
5049 if (info.ref_count == 1) {
5052 vprvt += info.private_pages_resident * getpagesize();
5071#if defined(R__LINUX)
5075static void GetLinuxSysInfo(
SysInfo_t *sysinfo)
5078 FILE *
f = fopen(
"/proc/cpuinfo",
"r");
5102 f = fopen(
"/proc/meminfo",
"r");
5127static void ReadLinuxCpu(
long *ticks)
5129 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
5132 FILE *
f = fopen(
"/proc/stat",
"r");
5136 sscanf(s.
Data(),
"%*s %ld %ld %ld %ld", &ticks[0], &ticks[3], &ticks[1], &ticks[2]);
5146 Double_t avg[3] = { -1., -1., -1. };
5148 if (getloadavg(avg,
sizeof(avg)) < 0) {
5149 ::Error(
"TUnixSystem::GetLinuxCpuInfo",
"getloadavg failed");
5158 Long_t cpu_ticks1[4], cpu_ticks2[4];
5159 ReadLinuxCpu(cpu_ticks1);
5161 ReadLinuxCpu(cpu_ticks2);
5163 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
5164 (cpu_ticks1[0] + cpu_ticks1[3]);
5165 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
5166 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
5167 if (userticks < 0) userticks = 0;
5168 if (systicks < 0) systicks = 0;
5169 if (idleticks < 0) idleticks = 0;
5170 Long_t totalticks = userticks + systicks + idleticks;
5182static void GetLinuxMemInfo(
MemInfo_t *meminfo)
5185 FILE *
f = fopen(
"/proc/meminfo",
"r");
5214static void GetLinuxProcInfo(
ProcInfo_t *procinfo)
5217 if (getrusage(RUSAGE_SELF, &ru) < 0) {
5218 ::SysError(
"TUnixSystem::GetLinuxProcInfo",
"getrusage failed");
5221 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
5223 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
5234 sscanf(s.
Data(),
"%ld %ld", &
total, &rss);
5248 if (!info)
return -1;
5252 if (!sysinfo.
fCpus) {
5253#if defined(R__MACOSX)
5254 GetDarwinSysInfo(&sysinfo);
5255#elif defined(R__LINUX)
5256 GetLinuxSysInfo(&sysinfo);
5257#elif defined(R__FBSD)
5258 GetFreeBSDSysInfo(&sysinfo);
5274 if (!info)
return -1;
5276#if defined(R__MACOSX)
5277 GetDarwinCpuInfo(info, sampleTime);
5278#elif defined(R__LINUX)
5279 GetLinuxCpuInfo(info, sampleTime);
5280#elif defined(R__FBSD)
5281 GetFreeBSDCpuInfo(info, sampleTime);
5293 if (!info)
return -1;
5295#if defined(R__MACOSX)
5296 GetDarwinMemInfo(info);
5297#elif defined(R__LINUX)
5298 GetLinuxMemInfo(info);
5310 if (!info)
return -1;
5312#if defined(R__MACOSX)
5313 GetDarwinProcInfo(info);
5314#elif defined(R__LINUX)
5315 GetLinuxProcInfo(info);
The file contains utilities which are foundational and could be used across the core component of ROO...
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
R__EXTERN TApplication * gApplication
void SysError(const char *location, const char *msgfmt,...)
Use this function in case a system (OS or GUI) related error occurred.
void Break(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
R__EXTERN TExceptionHandler * gExceptionHandler
static unsigned int total
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
R__EXTERN TInterpreter * gCling
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
char * StrDup(const char *str)
Duplicate the string str.
int EscChar(const char *src, char *dst, int dstlen, char *specchars, char escchar)
Escape specchars in src with escchar and copy to dst.
@ kSigSegmentationViolation
R__EXTERN const char * gProgName
R__EXTERN TVirtualMutex * gSystemMutex
R__EXTERN const char * gRootDir
R__EXTERN TSystem * gSystem
R__EXTERN TFileHandler * gXDisplay
R__EXTERN const char * gProgPath
static void sighandler(int sig)
Call the signal handler associated with the signal.
static const char * DynamicPath(const char *newpath=nullptr, Bool_t reset=kFALSE)
Get shared library search path. Static utility function.
static void SigHandler(ESignals sig)
Unix signal handler.
#define REAL_DIR_ENTRY(dp)
const char * kProtocolName
static struct Signalmap_t gSignalMap[kMAXSIGNALS]
static const char * GetExePath()
void(* SigHandler_t)(ESignals)
#define R__LOCKGUARD2(mutex)
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
virtual void HandleException(int sig)=0
ULong_t fds_bits[(((kFDSETSIZE)+((kNFDBITS) -1))/(kNFDBITS))]
TFdSet & operator=(const TFdSet &rhs)
TFdSet(const TFdSet &org)
virtual Bool_t HasReadInterest()
True if handler is interested in read events.
virtual Bool_t WriteNotify()
Notify when something can be written to the descriptor associated with this handler.
virtual Bool_t HasWriteInterest()
True if handler is interested in write events.
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
Bool_t Notify() override
Notify when event occurred on descriptor associated with this handler.
This class represents an Internet Protocol (IP) address.
void AddAlias(const char *alias)
Add alias to list of aliases.
void AddAddress(UInt_t addr)
Add alternative address to list of addresses.
UInt_t GetAddress() const
virtual const char * GetSTLIncludePath() const
TObject * Next() override
Return next object in the list. Returns 0 when no more objects in list.
TObject * At(Int_t idx) const override
Collectable string class.
virtual const char * GetName() const
Returns name of object.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Iterator of ordered collection.
TObject * Next() override
Return next object in collection.
Int_t Substitute(TString &s, const TString &replace, const TString &mods="", Int_t start=0, Int_t nMatchMax=10)
Substitute replaces the string s by a new string in which matching patterns are replaced by the repla...
static void ShutDown()
Shut down ROOT.
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
static const TString & GetLibDir()
Get the library directory in the installation. Static utility function.
Regular expression class.
Bool_t Notify() override
Notify when signal occurs.
ESignals GetSignal() const
Int_t Atoi() const
Return integer value of string.
Bool_t Gets(FILE *fp, Bool_t chop=kTRUE)
Read one line from the stream, including the \n, or until EOF.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Swap(TString &other)
TString & Remove(Ssiz_t pos)
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Long64_t Atoll() const
Return long long value of string.
Abstract base class defining a generic interface to the underlying Operating System.
virtual void Unload(const char *module)
Unload a shared library.
TSeqCollection * fFileHandler
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
TString & GetLastErrorString()
Return the thread local storage for the custom last error message.
virtual Func_t DynFindSymbol(const char *module, const char *entry)
Find specific entry point in specified library.
static void ResetErrno()
Static function resetting system error number.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
static Int_t GetErrno()
Static function returning system error number.
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
virtual void FreeDirectory(void *dirp)
Free a directory.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
virtual int GetPid()
Get process id.
virtual Long_t NextTimeOut(Bool_t mode)
Time when next timer of mode (synchronous=kTRUE or asynchronous=kFALSE) will time-out (in ms).
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
virtual const char * Getenv(const char *env)
Get environment variable.
TFdSet * fWritemask
Files that should be checked for read events.
TFdSet * fSignals
Files with writes waiting.
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
virtual int MakeDirectory(const char *name)
Make a directory.
virtual const char * ExpandFileName(const char *fname)
Expand a pathname getting rid of special shell characters like ~.
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
virtual void ListLibraries(const char *regexp="")
List the loaded shared libraries.
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
virtual Bool_t Init()
Initialize the OS interface.
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
TFdSet * fWriteready
Files with reads waiting.
virtual int ClosePipe(FILE *pipe)
Close the pipe.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
TSeqCollection * fSignalHandler
TFdSet * fReadready
Files that should be checked for write events.
TSystem * FindHelper(const char *path, void *dirptr=nullptr)
Create helper TSystem to handle file and directory operations that might be special for remote file a...
Int_t fNfd
Signals that were trapped.
std::atomic< Bool_t > fInsideNotify
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual const char * WorkingDirectory()
Return working directory.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
virtual TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
virtual void Setenv(const char *name, const char *value)
Set environment variable.
static const char * StripOffProto(const char *path, const char *proto)
Strip off protocol string from specified path.
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
virtual int Unlink(const char *name)
Unlink, i.e.
Basic time type with millisecond precision.
Handles synchronous and a-synchronous timer events.
Bool_t CheckTimer(const TTime &now)
Check if timer timed out.
void AddTimer(TTimer *ti) override
Add timer to list of system timers.
int RecvRaw(int sock, void *buffer, int length, int flag) override
Receive exactly length bytes into buffer.
int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp") override
Open a connection to a service on a server.
int GetMemInfo(MemInfo_t *info) const override
Returns ram and swap memory usage info into the MemInfo_t structure.
Bool_t IsPathLocal(const char *path) override
Returns TRUE if the url in 'path' points to the local file system.
int Symlink(const char *from, const char *to) override
Create a symlink from file1 to file2.
const char * HomeDirectory(const char *userName=nullptr) override
Return the user's home directory.
Int_t GetGid(const char *group=nullptr) override
Returns the group's id. If group = 0, returns current user's group.
static int UnixUdpConnect(const char *hostname, int port)
Creates a UDP socket connection Is called via the TSocket constructor.
int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE) override
Copy a file.
TTimer * RemoveTimer(TTimer *ti) override
Remove timer from list of system timers.
int AnnounceUdpService(int port, int backlog) override
Announce UDP service.
int AnnounceUnixService(int port, int backlog) override
Announce unix domain service on path "kServerPath/<port>".
static int UnixTcpConnect(const char *hostname, int port, int tcpwindowsize)
Open a TCP/IP connection to server and connect to a service (i.e.
Int_t SetFPEMask(Int_t mask=kDefaultMask) override
Set which conditions trigger a floating point exception.
static const char * UnixGetdirentry(void *dir)
Returns the next directory entry.
void Setenv(const char *name, const char *value) override
Set environment variable.
int ConnectService(const char *server, int port, int tcpwindowsize, const char *protocol="tcp")
Connect to service servicename on server servername.
Bool_t ChangeDirectory(const char *path) override
Change directory. Returns kTRUE in case of success, kFALSE otherwise.
static const char * UnixHomedirectory(const char *user=nullptr)
Returns the user's home directory.
char * GetServiceByPort(int port) override
Get name of internet service.
Bool_t CheckSignals(Bool_t sync)
Check if some signals were raised and call their Notify() member.
static int UnixMakedir(const char *name)
Make a Unix file system directory.
static void UnixSigAlarmInterruptsSyscalls(Bool_t set)
When the argument is true the SIGALRM signal handler is set so that interrupted syscalls will not be ...
Int_t GetFPEMask() override
Return the bitmap of conditions that trigger a floating point exception.
static int UnixUnixConnect(int port)
Connect to a Unix domain socket.
int GetSysInfo(SysInfo_t *info) const override
Returns static system info, like OS type, CPU type, number of CPUs RAM size, etc into the SysInfo_t s...
void Exit(int code, Bool_t mode=kTRUE) override
Exit the application.
int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1) override
Announce TCP/IP service.
void AddDynamicPath(const char *lib) override
Add a new directory to the dynamic path.
void SetDynamicPath(const char *lib) override
Set the dynamic path to a new value.
int ClosePipe(FILE *pipe) override
Close the pipe.
std::string GetHomeDirectory(const char *userName=nullptr) const override
Return the user's home directory.
Int_t Select(TList *active, Long_t timeout) override
Select on file descriptors.
void Unsetenv(const char *name) override
Unset environment variable.
virtual ~TUnixSystem()
Reset to original state.
void Abort(int code=0) override
Abort the application.
void Syslog(ELogLevel level, const char *mess) override
Send mess to syslog daemon.
UserGroup_t * GetGroupInfo(Int_t gid) override
Returns all group info in the UserGroup_t structure.
Int_t GetUid(const char *user=nullptr) override
Returns the user's id. If user = 0, returns current user's id.
Bool_t ExpandPathName(TString &patbuf) override
Expand a pathname getting rid of special shell characters like ~.
void Openlog(const char *name, Int_t options, ELogFacility facility) override
Open connection to system log daemon.
int AcceptConnection(int sock) override
Accept a connection.
TTime Now() override
Get current time in milliseconds since 0:00 Jan 1 1995.
static void UnixResetSignal(ESignals sig)
Restore old signal handler for specified signal.
int GetServiceByName(const char *service) override
Get port # of internet service.
const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists) override
Find location of file "wfil" in a search path.
void SigAlarmInterruptsSyscalls(Bool_t set) override
When the argument is true the SIGALRM signal handler is set so that interrupted syscalls will not be ...
static int UnixUdpService(int port, int backlog)
Open a socket, bind to it and start listening for UDP connections on the port.
int Utime(const char *file, Long_t modtime, Long_t actime) override
Set a files modification and access times.
const char * GetLinkedLibraries() override
Get list of shared libraries loaded at the start of the executable.
FILE * TempFileName(TString &base, const char *dir=nullptr) override
Create a secure temporary file by appending a unique 6 letter string to base.
const char * GetError() override
Return system error string.
std::string GetWorkingDirectory() const override
Return working directory.
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists) override
Returns FALSE if one can access a file using the specified access mode.
void DispatchOneEvent(Bool_t pendingOnly=kFALSE) override
Dispatch a single event.
int Chmod(const char *file, UInt_t mode) override
Set the file permission bits. Returns -1 in case or error, 0 otherwise.
const char * PrependPathName(const char *dir, TString &name) override
Concatenate a directory and a file name.
Bool_t DispatchTimers(Bool_t mode)
Handle and dispatch timers.
void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE) override
If ignore is true ignore the specified signal, else restore previous behaviour.
void ListSymbols(const char *module, const char *re="") override
List symbols in a shared library.
int Load(const char *module, const char *entry="", Bool_t system=kFALSE) override
Load a shared library.
void StackTrace() override
Print a stack trace.
TInetAddress GetHostByName(const char *server) override
Get Internet Protocol (IP) address of host.
int SendBuf(int sock, const void *buffer, int length) override
Send a buffer headed by a length indicator.
const char * HostName() override
Return the system's host name.
void CheckChilds()
Check if children have finished.
int RecvBuf(int sock, void *buffer, int length) override
Receive a buffer headed by a length indicator.
static int UnixUnixService(int port, int backlog)
Open a socket, bind to it and start listening for Unix domain connections to it.
UserGroup_t * GetUserInfo(Int_t uid) override
Returns all user info in the UserGroup_t structure.
void SetDisplay() override
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
TFileHandler * RemoveFileHandler(TFileHandler *fh) override
Remove a file handler from the list of file handlers.
static const char * UnixSigname(ESignals sig)
Return the signal name associated with a signal.
static Long64_t UnixNow()
Get current time in milliseconds since 0:00 Jan 1 1995.
static int UnixFSstat(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree)
Get info about a file system: id, bsize, bfree, blocks.
void ResetSignals() override
Reset signals handlers to previous behaviour.
TInetAddress GetSockName(int sock) override
Get Internet Protocol (IP) address of host and port #.
int Link(const char *from, const char *to) override
Create a link from file1 to file2.
int GetProcInfo(ProcInfo_t *info) const override
Returns cpu and memory used by this process into the ProcInfo_t structure.
int SetSockOpt(int sock, int option, int val) override
Set socket option.
static int UnixSetitimer(Long_t ms)
Set interval timer to time-out in ms milliseconds.
static int UnixSend(int sock, const void *buf, int len, int flag)
Send exactly length bytes from buffer.
TInetAddress GetPeerName(int sock) override
Get Internet Protocol (IP) address of remote host and port #.
static void UnixIgnoreSignal(ESignals sig, Bool_t ignore)
If ignore is true ignore the specified signal, else restore previous behaviour.
static int UnixTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize)
Open a socket, bind to it and start listening for TCP/IP connections on the port.
void DispatchSignals(ESignals sig)
Handle and dispatch signals.
void AddFileHandler(TFileHandler *fh) override
Add a file handler to the list of system file handlers.
void * OpenDirectory(const char *name) override
Open a Unix file system directory. Returns 0 if directory does not exist.
int Rename(const char *from, const char *to) override
Rename a file. Returns 0 when successful, -1 in case of failure.
const char * Getenv(const char *name) override
Get environment variable.
int GetPathInfo(const char *path, FileStat_t &buf) override
Get info about a file.
Int_t GetEffectiveGid() override
Returns the effective group id.
static int UnixSelect(Int_t nfds, TFdSet *readready, TFdSet *writeready, Long_t timeout)
Wait for events on the file descriptors specified in the readready and writeready masks or for timeou...
int GetPid() override
Get process id.
Int_t Exec(const char *shellcmd) override
Execute a command.
void ResetTimer(TTimer *ti) override
Reset a-sync timer.
TSignalHandler * RemoveSignalHandler(TSignalHandler *sh) override
Remove a signal handler from list of signal handlers.
static void UnixSignal(ESignals sig, SigHandler_t h)
Set a signal handler for a signal.
void CloseConnection(int sock, Bool_t force=kFALSE) override
Close socket.
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
Bool_t Init() override
Initialize Unix system interface.
void Unload(const char *module) override
Unload a shared library.
int Umask(Int_t mask) override
Set the process file creation mode mask.
static int UnixFilestat(const char *path, FileStat_t &buf)
Get info about a file.
static int UnixRecv(int sock, void *buf, int len, int flag)
Receive exactly length bytes into buffer.
Int_t GetEffectiveUid() override
Returns the effective user id.
void FillWithCwd(char *cwd) const
Fill buffer with current working directory.
static int UnixWaitchild()
Wait till child is finished.
int Unlink(const char *name) override
Unlink, i.e.
void ListLibraries(const char *regexp="") override
List all loaded shared libraries.
void Closelog() override
Close connection to system log daemon.
Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=nullptr) override
Redirect standard output (stdout, stderr) to the specified file.
void Sleep(UInt_t milliSec) override
Sleep milliSec milliseconds.
void ResetSignal(ESignals sig, Bool_t reset=kTRUE) override
If reset is true reset the signal handler for the specified signal to the default handler,...
const char * TempDirectory() const override
Return a user configured or systemwide directory to create temporary files in.
Func_t DynFindSymbol(const char *module, const char *entry) override
dynamic linking of module
const char * GetDynamicPath() override
Return the dynamic path (used to find shared libraries).
FILE * OpenPipe(const char *shellcmd, const char *mode) override
Open a pipe.
void FreeDirectory(void *dirp) override
Close a Unix file system directory.
static void UnixResetSignals()
Restore old signal handlers.
int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const override
Returns cpu load average and load info into the CpuInfo_t structure.
void AddSignalHandler(TSignalHandler *sh) override
Add a signal handler to list of system signal handlers.
static void * UnixOpendir(const char *name)
Open a directory.
int SendRaw(int sock, const void *buffer, int length, int flag) override
Send exactly length bytes from buffer.
const char * WorkingDirectory() override
Return working directory.
int GetSockOpt(int sock, int option, int *val) override
Get socket option.
const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE) override
Returns the path of a shared library (searches for library in the shared library search path).
void SetProgname(const char *name) override
Set the application name (from command line, argv[0]) and copy it in gProgName.
const char * GetDirEntry(void *dirp) override
Get next Unix file system directory entry. Returns 0 if no more entries.
int MakeDirectory(const char *name) override
Make a Unix file system directory.
int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree) override
Get info about a file system: id, bsize, bfree, blocks.
const std::string & GetFallbackRootSys()
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
const char * GetExePath()
Returns the executable path name, used e.g. by SetRootSys().
void SetRootSys()
Set the ROOTSYS env var based on the executable location.
struct sigaction * fOldHandler
struct utmp * fUtmpContents
struct utmp * SearchUtmpEntry(const char *tty)
#define org(otri, vertexptr)
#define sym(otri1, otri2)