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 *);
165#if defined(R__ARC4_STDLIB)
167#elif defined(R__ARC4_BSDLIB)
168#include <bsd/stdlib.h>
169#elif defined(R__GETRANDOM_CLIB)
170#include <sys/random.h>
175#define STRUCT_UTMP struct utmpx
178#define STRUCT_UTMP struct utmp
180#if !defined(UTMP_FILE) && defined(_PATH_UTMP)
181#define UTMP_FILE _PATH_UTMP
183#if defined(UTMPX_FILE)
185#define UTMP_FILE UTMPX_FILE
188#define UTMP_FILE "/etc/utmp"
192#if (defined(R__LINUX) || defined(R__HURD)) && !defined(R__WINGCC)
193# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
194# define HAVE_BACKTRACE_SYMBOLS_FD
198#if defined(R__MACOSX) || defined(R__FBSD)
199# define HAVE_BACKTRACE_SYMBOLS_FD
203#ifdef HAVE_BACKTRACE_SYMBOLS_FD
204# include <execinfo.h>
213#ifdef HAVE_BACKTRACE_SYMBOLS_FD
216 static const int kMAX_BACKTRACE_DEPTH = 128;
220#if (defined(R__LINUX) && !defined(R__WINGCC))
222#include <sys/prctl.h>
225#if defined(R__MACOSX) && defined(__SSE2__)
226#include <xmmintrin.h>
229#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
230 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
237#include <mach/thread_status.h>
239#define fegetenvd(x) asm volatile("mffs %0" : "=f" (x));
240#define fesetenvd(x) asm volatile("mtfsf 255,%0" : : "f" (x));
243 FE_ENABLE_INEXACT = 0x00000008,
244 FE_ENABLE_DIVBYZERO = 0x00000010,
245 FE_ENABLE_UNDERFLOW = 0x00000020,
246 FE_ENABLE_OVERFLOW = 0x00000040,
247 FE_ENABLE_INVALID = 0x00000080,
248 FE_ENABLE_ALL_EXCEPT = 0x000000F8
252#if defined(R__MACOSX) && !defined(__SSE2__) && \
253 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
265 template<
typename U = T,
typename std::enable_if<std::is_member_po
inter<decltype(&U::ut_name)>::value,
int>::type = 0>
266 static char getValue(U* ue,
int) {
267 return ue->ut_name[0];
270 template<
typename U = T,
typename std::enable_if<std::is_member_po
inter<decltype(&U::ut_user)>::value,
int>::type = 0>
271 static char getValue(U* ue,
long) {
272 return ue->ut_user[0];
278 return ut_name<STRUCT_UTMP>::getValue(ue, 0);
297 if (get_ut_name(ue) && !strncmp(tty, ue->ut_line,
sizeof(ue->ut_line)))
309 struct stat file_stats;
320 if (fstat(fileno(utmp), &file_stats) == -1) {
324 size = file_stats.st_size;
338 if (fclose(utmp) != EOF && n_read ==
size) {
357# define HOWMANY(x, y) (((x)+((y)-1))/(y))
417 TTHREAD_TLS_DECL(
TString,exepath);
419#if defined(R__MACOSX)
420 exepath = _dyld_get_image_name(0);
421#elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__FBSD)
426 int ret = readlink(
"/proc/self/exe", buf,
kMAXPATHLEN);
427#elif defined(R__SOLARIS)
428 int ret = readlink(
"/proc/self/path/a.out", buf,
kMAXPATHLEN);
429#elif defined(R__FBSD)
430 procstat* ps = procstat_open_sysctl();
431 kinfo_proc* kp = kinfo_getproc(getpid());
435 procstat_getpathname(ps, kp, buf,
sizeof(buf));
449 if (
p.BeginsWith(
"/"))
451 else if (
p.Contains(
"/")) {
467#if defined(HAVE_DLADDR) && !defined(R__MACOSX)
477 if (dladdr(addr, &info) && info.dli_fname && info.dli_fname[0]) {
479 if (!realpath(info.dli_fname, respath)) {
481 ::SysError(
"TUnixSystem::SetRootSys",
"error getting realpath of libCore, please set ROOTSYS in the shell");
493#if defined(R__MACOSX)
498static void DylibAdded(
const struct mach_header *mh, intptr_t )
507 gLinkedDylibs = linkedDylibs;
511 TString lib = _dyld_get_image_name(i++);
513 TRegexp sovers =
"libCore\\.[0-9]+\\.*[0-9]*\\.*[0-9]*\\.so";
514 TRegexp dyvers =
"libCore\\.[0-9]+\\.*[0-9]*\\.*[0-9]*\\.dylib";
522 if (!realpath(lib, respath)) {
524 ::SysError(
"TUnixSystem::DylibAdded",
"error getting realpath of libCore, please set ROOTSYS in the shell");
538 if (lib.
EndsWith(
"/libSystem.B.dylib")) {
540 if (linkedDylibs.
IsNull()) {
550 sovers =
"\\.[0-9]+\\.*[0-9]*\\.so";
556 dyvers =
"\\.[0-9]+\\.*[0-9]*\\.dylib";
557 idx = lib.
Index(dyvers);
563 if (linkedDylibs.
Length())
619#if defined(R__MACOSX)
622 _dyld_register_func_for_add_image(DylibAdded);
623#elif defined(HAVE_DLADDR)
666 char *tty = ::ttyname(0);
675 if (utmp_entry->ut_host[0]) {
677 for (
unsigned n = 0; (
n <
sizeof(utmp_entry->ut_host)) && utmp_entry->ut_host[
n];
n++)
678 disp.
Append(utmp_entry->ut_host[
n]);
682 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s", disp.
Data());
685 else if (utmp_entry->ut_addr) {
687 struct sockaddr_in addr;
688 addr.sin_family = AF_INET;
690 memcpy(&addr.sin_addr, &utmp_entry->ut_addr,
sizeof(addr.sin_addr));
691 memset(&addr.sin_zero[0], 0,
sizeof(addr.sin_zero));
692 struct sockaddr *sa = (
struct sockaddr *) &addr;
694 char hbuf[NI_MAXHOST + 4];
695 if (getnameinfo(sa,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, NI_NAMEREQD) == 0) {
696 assert( strlen(hbuf) < NI_MAXHOST );
697 strlcat(hbuf,
":0.0",
sizeof(hbuf));
699 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
707 if (!
gROOT->IsBatch() && !getenv(
"DISPLAY")) {
708 Error(
"SetDisplay",
"Can't figure out DISPLAY, set it manually\n"
709 "In case you run a remote ssh session, restart your ssh session with:\n"
710 "=========> ssh -Y");
725#if defined(R__SOLARIS) || defined (R__LINUX) || defined(R__AIX) || \
726 defined(R__FBSD) || defined(R__OBSD) || defined(R__HURD)
727 return strerror(err);
729 if (err < 0 || err >= sys_nerr)
730 return Form(
"errno out of range %d", err);
731 return sys_errlist[err];
742#if defined(R__ARC4_STDLIB) || defined(R__ARC4_BSDLIB)
743 arc4random_buf(buf,
len);
745#elif defined(R__GETRANDOM_CLIB)
746 return getrandom(buf,
len, GRND_NONBLOCK);
747#elif defined(R__USE_URANDOM)
748 std::ifstream urandom{
"/dev/urandom"};
751 urandom.read(
reinterpret_cast<char *
>(buf),
len);
754#error "Reliable cryptographic random function not defined"
766#if defined(R__SOLARIS)
767 sysinfo(SI_HOSTNAME, hn,
sizeof(hn));
769 gethostname(hn,
sizeof(hn));
789 if (
h->HasReadInterest()) {
793 if (
h->HasWriteInterest()) {
806 if (!
h)
return nullptr;
819 int fd = th->
GetFd();
851 if (!
h)
return nullptr;
920#if defined(R__LINUX) && !defined(__powerpc__)
921#if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
923#if __GLIBC_MINOR__>=3
925 Int_t oldmask = fegetexcept();
932 Int_t oldmask = ~oldenv;
934 Int_t oldmask = ~oldenv.__control_word;
948#if defined(R__MACOSX) && defined(__SSE2__)
950 Int_t oldmask = ~_MM_GET_EXCEPTION_MASK();
959#if defined(R__MACOSX) && !defined(__SSE2__) && \
960 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
965 Int_t oldmask = ~oldenv.__fpscr;
966#elif defined(__arm64__)
967 Int_t oldmask = ~oldenv.__fpcr;
969 Int_t oldmask = ~oldenv.__control;
979#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
980 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
1005#if defined(R__LINUX) && !defined(__powerpc__)
1006#if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
1016#if __GLIBC_MINOR__>=3
1019 feclearexcept(FE_ALL_EXCEPT);
1020 fedisableexcept(FE_ALL_EXCEPT);
1021 feenableexcept(newm);
1030 cur.__control_word &= ~newm;
1038#if defined(R__MACOSX) && defined(__SSE2__)
1047 _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~newm);
1050#if defined(R__MACOSX) && !defined(__SSE2__) && \
1051 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
1062 cur.__fpscr &= ~newm;
1063#elif defined(__arm64__)
1064 cur.__fpcr &= ~newm;
1066 cur.__control &= ~newm;
1071#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
1072 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
1083 curmask = (curmask & ~FE_ENABLE_ALL_EXCEPT) | newm;
1095 Bool_t pollOnce = pendingOnly;
1104 if (!pendingOnly)
return;
1110 if (!pendingOnly)
return;
1115 if (pendingOnly && !pollOnce)
1121 if (!pendingOnly)
return;
1152 if (mxfd == 0 && nextto == -1)
1159 for (fd = 0; fd < mxfd; fd++) {
1163 if (rc < 0 && rc != -2) {
1164 SysError(
"DispatchOneEvent",
"select: read error on %d", fd);
1170 if (rc < 0 && rc != -2) {
1171 SysError(
"DispatchOneEvent",
"select: write error on %d", fd);
1188 tv.tv_sec = milliSec / 1000;
1189 tv.tv_usec = (milliSec % 1000) * 1000;
1191 select(0,
nullptr,
nullptr,
nullptr, &tv);
1213 if (
h->HasReadInterest()) {
1217 if (
h->HasWriteInterest()) {
1221 h->ResetReadyMask();
1260 if (
h->HasReadInterest())
1262 if (
h->HasWriteInterest())
1264 h->ResetReadyMask();
1294 if (sync == sh->
IsSync()) {
1296 if ((
fSignals->
IsSet(sig) && sigdone == -1) || sigdone == sig) {
1297 if (sigdone == -1) {
1322 TIter next(zombieHandler);
1323 register UnixPtty *pty;
1324 while ((pty = (UnixPtty*) next()))
1325 if (pty->GetPid() == pid) {
1326 zombieHandler->RemovePtr(pty);
1345 if ((fd <= fMaxrfd && fReadready->IsSet(fd) && fddone == -1) ||
1346 (fddone == fd && read)) {
1356 if ((fd <= fMaxwfd && fWriteready->IsSet(fd) && fddone == -1) ||
1357 (fddone == fd && !read)) {
1413 ::closedir((DIR*)dirp);
1467 return std::string(cwd);
1476 Error(
"WorkingDirectory",
"getcwd() failed");
1495 if (res)
return std::string(res);
1496 else return std::string();
1528 const bool hasSuffix = suffix && *suffix;
1533 char *arg =
StrDup(base);
1534 int fd = hasSuffix ? mkstemps(arg, strlen(suffix)) : mkstemp(arg);
1542 FILE *fp = fdopen(fd,
"w+");
1544 SysError(
"TempFileName",
"converting filedescriptor (%d)", fd);
1554 if (
name.IsNull() ||
name ==
".") {
1557 if (dir[strlen(dir) - 1] !=
'/')
1563 if (!dir || !dir[0])
1565 else if (dir[strlen(dir) - 1] !=
'/')
1603 FILE *from = fopen(
f,
"r");
1607 FILE *to = fopen(t,
"w");
1613 const int bufsize = 1024;
1616 while (!ret && !feof(from)) {
1617 size_t numread = fread (buf,
sizeof(
char), bufsize, from);
1618 size_t numwritten = fwrite(buf,
sizeof(
char), numread, to);
1619 if (numread != numwritten)
1634 int ret = ::rename(
f, t);
1679 return UnixFSstat(path,
id, bsize, blocks, bfree);
1688 return ::link(from, to);
1698 return ::symlink((
char*)from, (
char*)to);
1700 return ::symlink(from, to);
1714#if defined(R__SEEK64)
1715 struct stat64 finfo;
1716 if (lstat64(
name, &finfo) < 0)
1719 if (lstat(
name, &finfo) < 0)
1723 if (S_ISDIR(finfo.st_mode))
1724 return ::rmdir(
name);
1726 return ::unlink(
name);
1735 kShellEscape =
'\\',
1736 *kShellStuff =
"(){}<>\"'",
1751 const char *
p, *patbuf = (
const char *)path;
1754 while (*patbuf ==
' ')
1758 for (
p = patbuf; *
p;
p++)
1783 const char *patbuf = (
const char *)patbuf0;
1792 while (*patbuf ==
' ')
1796 for (
p = patbuf; *
p;
p++)
1808 EscChar(patbuf, stuffedPat,
sizeof(stuffedPat), (
char*)kShellStuff, kShellEscape);
1813 if (stuffedPat[0] ==
'~') {
1814 if (stuffedPat[1] !=
'\0' && stuffedPat[1] !=
'/') {
1816 for (
p = &stuffedPat[1],
q =
name; *
p && *
p !=
'/';)
1833 cmd += &stuffedPat[1];
1838 if ((pf = ::popen(cmd.Data(),
"r")) == 0) {
1849 for (ch = fgetc(pf); ch != EOF && ch !=
' ' && ch !=
'\n'; ch = fgetc(pf)) {
1855 if (cnt == 0 && ch == EOF)
goto again;
1861 if (ch ==
' ' || ch ==
'\t') {
1895 return ::chmod(file,
mode);
1903 return ::umask(
mask);
1916 t.actime = (time_t)actime;
1917 t.modtime = (time_t)modtime;
1918 return ::utime(file, &t);
1931 show.
Form(
"Which: %s =", wfil.
Data());
1935 if (wfil[0] ==
'/') {
1936#if defined(R__SEEK64)
1937 struct stat64 finfo;
1938 if (access(wfil.
Data(),
mode) == 0 &&
1939 stat64(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1942 if (access(wfil.
Data(),
mode) == 0 &&
1943 stat(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1960 for (
const char* ptr = search; *ptr;) {
1962 if (*ptr !=
'/' && *ptr !=
'$' && *ptr !=
'~')
1964 const char* posEndOfPart = strchr(ptr,
':');
1966 name.Append(ptr, posEndOfPart - ptr);
1967 ptr = posEndOfPart + 1;
1973 if (!
name.EndsWith(
"/"))
1978#if defined(R__SEEK64)
1979 struct stat64 finfo;
1980 if (access(
name.Data(),
mode) == 0 &&
1981 stat64(
name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1984 if (access(
name.Data(),
mode) == 0 &&
1985 stat(
name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
2007 if (!user || !user[0])
2010 struct passwd *apwd = getpwnam(user);
2057 static UserInfoCache_t gUserInfo;
2059 UserInfoCache_t::const_iterator iUserInfo = gUserInfo.find(uid);
2060 if (iUserInfo != gUserInfo.end())
2063 struct passwd *apwd = getpwuid(uid);
2076 gUserInfo[uid] = *ug;
2101 struct group *grp = getgrgid(gid);
2139 return ::getenv(
name);
2157 return ::system(shellcmd);
2165 return ::popen(command,
mode);
2173 return ::pclose(pipe);
2211#include <mach/mach.h>
2219 typedef CSTypeRef CSSymbolicatorRef;
2220 typedef CSTypeRef CSSourceInfoRef;
2221 typedef CSTypeRef CSSymbolOwnerRef;
2222 typedef CSTypeRef CSSymbolRef;
2224 CSSymbolicatorRef CSSymbolicatorCreateWithPid(pid_t pid);
2225 CSSymbolRef CSSymbolicatorGetSymbolWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2226 CSSourceInfoRef CSSymbolicatorGetSourceInfoWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2227 const char* CSSymbolGetName(CSSymbolRef sym);
2228 CSSymbolOwnerRef CSSymbolGetSymbolOwner(CSSymbolRef sym);
2229 const char* CSSymbolOwnerGetPath(CSSymbolOwnerRef symbol);
2230 const char* CSSourceInfoGetPath(CSSourceInfoRef info);
2231 int CSSourceInfoGetLineNumber(CSSourceInfoRef info);
2234bool CSTypeRefIdValid(CSTypeRef ref) {
2235 return ref.csCppData || ref.csCppObj;
2238void macosx_backtrace() {
2239void* addrlist[kMAX_BACKTRACE_DEPTH];
2241 int numstacks = backtrace( addrlist,
sizeof( addrlist ) /
sizeof(
void* ));
2243 CSSymbolicatorRef symbolicator = CSSymbolicatorCreateWithPid(getpid());
2246 static const int skipFrames = 2;
2247 for (
int i = skipFrames; i < numstacks; ++i) {
2249 CSSymbolRef sym = CSSymbolicatorGetSymbolWithAddressAtTime(symbolicator,
2250 (vm_address_t)addrlist[i],
2252 CSSymbolOwnerRef symOwner = CSSymbolGetSymbolOwner(sym);
2254 if (
const char* libPath = CSSymbolOwnerGetPath(symOwner)) {
2255 printf(
"[%s]", libPath);
2257 printf(
"[<unknown binary>]");
2260 if (
const char* symname = CSSymbolGetName(sym)) {
2261 printf(
" %s", symname);
2264 CSSourceInfoRef sourceInfo
2265 = CSSymbolicatorGetSourceInfoWithAddressAtTime(symbolicator,
2266 (vm_address_t)addrlist[i],
2268 if (
const char* sourcePath = CSSourceInfoGetPath(sourceInfo)) {
2269 printf(
" %s:%d", sourcePath, (
int)CSSourceInfoGetLineNumber(sourceInfo));
2271 printf(
" (no debug info)");
2288 gdbscript = gdbscript.
Strip();
2289 if (gdbscript !=
"") {
2291 fprintf(stderr,
"Root.StacktraceScript %s does not exist\n", gdbscript.
Data());
2295 if (gdbscript ==
"") {
2296 gdbscript =
"gdb-backtrace.sh";
2299 fprintf(stderr,
"Error in <TUnixSystem::StackTrace> script %s is missing\n", gdbscript.
Data());
2306 gdbmess = gdbmess.
Strip();
2314 int fd = STDERR_FILENO;
2316 const char *message =
" Generating stack trace...\n";
2318 if (fd && message) { }
2321 Getlinem(kCleanUp,
nullptr);
2323#if defined(USE_GDB_STACK_TRACE)
2326 fprintf(stderr,
"gdb not found, need it for stack trace\n");
2331 TString gdbmessf =
"gdb-message";
2332 if (gdbmess !=
"") {
2334 fprintf(
f,
"%s\n", gdbmess.
Data());
2342 if (gdbmess !=
"") {
2344 gdbscript += gdbmessf;
2346 gdbscript +=
" 1>&2";
2351#elif defined(R__AIX)
2352 TString script =
"procstack ";
2356#elif defined(R__SOLARIS)
2367#elif defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_DLADDR)
2375 const char *cppfilt =
"c++filt";
2376 const char *cppfiltarg =
"";
2378 const char *format1 =
" 0x%016lx in %.200s %s 0x%lx from %.200s\n";
2380 const char *format2 =
" 0x%016lx in %.200s\n";
2382 const char *format2 =
" 0x%016lx in %.200s at %.200s from %.200s\n";
2384 const char *format3 =
" 0x%016lx in %.200s from %.200s\n";
2385 const char *format4 =
" 0x%016lx in <unknown function>\n";
2387 const char *format1 =
" 0x%08lx in %.200s %s 0x%lx from %.200s\n";
2389 const char *format2 =
" 0x%08lx in %.200s\n";
2391 const char *format2 =
" 0x%08lx in %.200s at %.200s from %.200s\n";
2393 const char *format3 =
" 0x%08lx in %.200s from %.200s\n";
2394 const char *format4 =
" 0x%08lx in <unknown function>\n";
2406 while (help.
Gets(
p)) {
2408 cppfiltarg =
"--format=gnu-v3";
2410 }
else if (help.
Index(
"gnu-new-abi") !=
kNPOS) {
2411 cppfiltarg =
"--format=gnu-new-abi";
2420#if (defined(R__LINUX) && !defined(R__WINGCC))
2423#ifdef PR_SET_PTRACER
2424 prctl(PR_SET_PTRACER, getpid(), 0, 0, 0);
2430 TString gdbmessf =
"gdb-message";
2431 if (gdbmess !=
"") {
2433 fprintf(
f,
"%s\n", gdbmess.
Data());
2443 if (gdbmess !=
"") {
2445 gdbscript += gdbmessf;
2447 gdbscript +=
" 1>&2";
2460 if (write(fd, message, strlen(message)) < 0)
2465 TString tmpf1 =
"gdb-backtrace";
2466 std::ofstream file1;
2472 Error(
"StackTrace",
"could not open file %s", tmpf1.
Data());
2484 void *trace[kMAX_BACKTRACE_DEPTH];
2485 int depth = backtrace(trace, kMAX_BACKTRACE_DEPTH);
2486 for (
int n = 5;
n < depth;
n++) {
2490 if (dladdr(trace[
n], &info) && info.dli_fname && info.dli_fname[0]) {
2491 const char *libname = info.dli_fname;
2492 const char *symname = (info.dli_sname && info.dli_sname[0]) ?
2493 info.dli_sname :
"<unknown>";
2496 Bool_t gte = (addr >= symaddr);
2497 ULong_t diff = (gte) ? addr - symaddr : symaddr - addr;
2498 if (addr2line && symaddr) {
2502#if defined(MAC_OS_X_VERSION_10_10)
2503 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2504#elif defined(MAC_OS_X_VERSION_10_9)
2506 snprintf(buffer,
sizeof(buffer),
"%s -d -p %d 0x%016lx", addr2line,
GetPid(), addr);
2508 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2517 if (
name.Contains(
".so") ||
name.Contains(
".sl")) noShare =
kFALSE;
2518 if (noShare)
offset = addr;
2519 if (noPath)
name =
"`which " +
name +
"`";
2520 snprintf(buffer,
sizeof(buffer),
"%s -e %s 0x%016lx", addr2line,
name.Data(),
offset);
2522 if (FILE *pf = ::popen(buffer,
"r")) {
2524 if (fgets(buf, 2048, pf)) {
2525 buf[strlen(buf)-1] = 0;
2526 if (strncmp(buf,
"??", 2)) {
2528 snprintf(buffer,
sizeof(buffer), format2, addr, buf);
2530 snprintf(buffer,
sizeof(buffer), format2, addr, symname, buf, libname);
2538 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2539 gte ?
"+" :
"-", diff, libname);
2542 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2543 gte ?
"+" :
"-", diff, libname);
2545 snprintf(buffer,
sizeof(buffer), format3, addr, symname, libname);
2548 snprintf(buffer,
sizeof(buffer), format4, addr);
2554 if (write(fd, buffer, ::strlen(buffer)) < 0)
2559 TString tmpf2 =
"gdb-backtrace";
2563 snprintf(buffer,
sizeof(buffer),
"%s %s < %s > %s", filter, cppfiltarg, tmpf1.
Data(), tmpf2.
Data());
2565 std::ifstream file2(tmpf2);
2569 line.ReadString(file2);
2570 if (write(fd,
line.Data(),
line.Length()) < 0)
2578 delete [] addr2line;
2581#elif defined(HAVE_EXCPT_H) && defined(HAVE_PDSC_H) && \
2582 defined(HAVE_RLD_INTERFACE_H)
2591 exc_capture_context (&context);
2592 while (!rc && context.sc_pc) {
2594 pdsc_crd *func, *base, *crd
2595 = exc_remote_lookup_function_entry(0, 0, context.sc_pc, 0, &func, &base);
2596 Elf32_Addr addr = PDSC_CRD_BEGIN_ADDRESS(base, func);
2598 const char *
name =
"<unknown function>";
2599 sprintf(buffer,
" 0x%012lx %.200s + 0x%lx\n",
2600 context.sc_pc,
name, context.sc_pc - addr);
2601 write(fd, buffer, ::strlen(buffer));
2602 rc = exc_virtual_unwind(0, &context);
2647 ::openlog(
name, options, fac);
2657 ::syslog(level,
"%s", mess);
2697 const char *tty = ttyname(STDOUT_FILENO);
2701 if ((xh->
fStdOutDup = dup(STDOUT_FILENO)) < 0) {
2709 const char *tty = ttyname(STDERR_FILENO);
2713 if ((xh->
fStdErrDup = dup(STDERR_FILENO)) < 0) {
2715 if (outdone && dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2716 Warning(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2725 const char *
m = (
mode[0] ==
'a' ||
mode[0] ==
'w') ?
mode :
"a";
2738 if (freopen(file,
m, stdout) ==
nullptr) {
2742 if (freopen(file,
m, stderr) ==
nullptr) {
2758 if (close(STDOUT_FILENO) != 0) {
2760 "problems closing STDOUT_FILENO (%d) before 'dup2' (errno: %d)",
2764 if (dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2765 SysError(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2771 "problems closing temporary 'out' descriptor %d (errno: %d)",
2784 if (close(STDERR_FILENO) != 0) {
2786 "problems closing STDERR_FILENO (%d) before 'dup2' (errno: %d)",
2790 if (dup2(xh->
fStdErrDup, STDERR_FILENO) < 0) {
2791 SysError(
"RedirectOutput",
"could not restore stderr (back to original redirected"
2797 "problems closing temporary 'err' descriptor %d (errno: %d)",
2842 Error(
"ListSymbols",
"not yet implemented");
2864 if (!linkedLibs.
IsNull())
2870#if !defined(R__MACOSX)
2876#if defined(R__MACOSX)
2878 linkedLibs = gLinkedDylibs;
2882 while (otool.
Gets(
p)) {
2887 if (!linkedLibs.
IsNull())
2889 linkedLibs += dylib;
2897#elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__AIX)
2898#if defined(R__WINGCC )
2899 const char *cLDD=
"cygcheck";
2900 const char *cSOEXT=
".dll";
2901 size_t lenexe = strlen(exe);
2902 if (strcmp(exe + lenexe - 4,
".exe")
2903 && strcmp(exe + lenexe - 4,
".dll")) {
2906 char* longerexe =
new char[lenexe + 5];
2907 strlcpy(longerexe, exe,lenexe+5);
2908 strlcat(longerexe,
".exe",lenexe+5);
2910 #error "unsupported platform, fix memory leak to use it"
2912 TRegexp sovers =
"\\.so\\.[0-9]+";
2914 const char *cLDD=
"ldd";
2916 const char *cSOEXT=
".a";
2917 TRegexp sovers =
"\\.a\\.[0-9]+";
2919 const char *cSOEXT=
".so";
2920 TRegexp sovers =
"\\.so\\.[0-9]+";
2926 while (ldd.
Gets(
p)) {
2945 if (!linkedLibs.
IsNull())
2947 linkedLibs += solib;
3020 if (!ti)
return nullptr;
3049 struct addrinfo hints;
3050 struct addrinfo *
result, *rp;
3051 memset(&hints, 0,
sizeof(
struct addrinfo));
3052 hints.ai_family = AF_INET;
3053 hints.ai_socktype = 0;
3054 hints.ai_protocol = 0;
3055 hints.ai_flags = AI_CANONNAME;
3060 size_t lenHostname = strlen(hostname);
3061 std::string hostnameWithoutLocal{hostname};
3062 if (lenHostname > 6 && !strcmp(hostname + lenHostname - 6,
".local")) {
3063 hostnameWithoutLocal.erase(lenHostname - 6);
3064 hostname = hostnameWithoutLocal.c_str();
3069 int rc = getaddrinfo(hostname,
nullptr, &hints, &
result);
3071 if (rc == EAI_NONAME) {
3072 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host '%s'", hostname);
3075 Error(
"GetHostByName",
"getaddrinfo failed for '%s': %s", hostname, gai_strerror(rc));
3081 std::string hostcanon(
result->ai_canonname ?
result->ai_canonname : hostname);
3084 ia.
fAddresses[0] = ntohl(((
struct sockaddr_in *)(
result->ai_addr))->sin_addr.s_addr);
3086 if (hostcanon.compare(hostname) != 0) ia.
AddAlias(hostname);
3089 char tmp[
sizeof(
struct in_addr)];
3090 if (inet_pton(AF_INET, hostcanon.data(), tmp) == 1) {
3091 char hbuf[NI_MAXHOST];
3092 if (getnameinfo(
result->ai_addr,
result->ai_addrlen, hbuf,
sizeof(hbuf),
nullptr, 0, 0) == 0)
3098 for (; rp !=
nullptr; rp = rp->ai_next) {
3099 UInt_t arp = ntohl(((
struct sockaddr_in *)(rp->ai_addr))->sin_addr.s_addr);
3113 struct sockaddr addr;
3114 socklen_t
len =
sizeof(addr);
3117 if (getsockname(sock, &addr, &
len) == -1) {
3118 SysError(
"GetSockName",
"getsockname failed");
3122 if (addr.sa_family != AF_INET)
return ia;
3124 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3125 ia.
fPort = ntohs(addrin->sin_port);
3126 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3128 char hbuf[NI_MAXHOST];
3129 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3130 Error(
"GetSockName",
"getnameinfo failed");
3143 struct sockaddr addr;
3144 socklen_t
len =
sizeof(addr);
3147 if (getpeername(sock, &addr, &
len) == -1) {
3148 SysError(
"GetPeerName",
"getpeername failed");
3152 if (addr.sa_family != AF_INET)
return ia;
3154 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3155 ia.
fPort = ntohs(addrin->sin_port);
3156 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3158 char hbuf[NI_MAXHOST];
3159 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3160 Error(
"GetPeerName",
"getnameinfo failed");
3175 if ((sp = getservbyname(servicename,
kProtocolName)) ==
nullptr) {
3176 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
3180 return ntohs(sp->s_port);
3190 if ((sp = getservbyport(htons(port),
kProtocolName)) ==
nullptr) {
3193 return Form(
"%d", port);
3202 int tcpwindowsize,
const char *protocol)
3204 if (!strcmp(servername,
"unix")) {
3210 if (!strcmp(protocol,
"udp")){
3280 while ((soc = ::accept(sock,
nullptr,
nullptr)) == -1 &&
GetErrno() == EINTR)
3287 SysError(
"AcceptConnection",
"accept");
3300 if (sock < 0)
return;
3302#if !defined(R__AIX) || defined(_AIX41) || defined(_AIX43)
3304 ::shutdown(sock, 2);
3307 while (::close(sock) == -1 &&
GetErrno() == EINTR)
3320 if (
UnixRecv(sock, &header,
sizeof(header), 0) > 0) {
3321 int count = ntohl(header);
3324 Error(
"RecvBuf",
"record header exceeds buffer size");
3326 }
else if (count > 0) {
3327 if (
UnixRecv(sock, buf, count, 0) < 0) {
3328 Error(
"RecvBuf",
"cannot receive buffer");
3345 if (
UnixSend(sock, &header,
sizeof(header), 0) < 0) {
3346 Error(
"SendBuf",
"cannot send header");
3351 Error(
"SendBuf",
"cannot send buffer");
3393 Error(
"RecvRaw",
"cannot receive buffer");
3428 Error(
"SendRaw",
"cannot send buffer");
3439 if (sock < 0)
return -1;
3443 if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == -1) {
3444 SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
3449 if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == -1) {
3450 SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
3455 if (setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == -1) {
3456 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
3461 if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == -1) {
3462 SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
3467 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == -1) {
3468 SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
3473 if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == -1) {
3474 SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
3479 if (ioctl(sock, FIONBIO, (
char*)&val) == -1) {
3480 SysError(
"SetSockOpt",
"ioctl(FIONBIO)");
3486 if (ioctl(sock, SIOCSPGRP, (
char*)&val) == -1) {
3487 SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
3491 Error(
"SetSockOpt",
"ioctl(SIOCGPGRP) not supported on cygwin/gcc");
3498 Error(
"SetSockOpt",
"illegal option (%d)", opt);
3509 if (sock < 0)
return -1;
3511 socklen_t optlen =
sizeof(*val);
3515 if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == -1) {
3516 SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
3521 if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == -1) {
3522 SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
3527 if (getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == -1) {
3528 SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
3533 if (getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == -1) {
3534 SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
3539 if (getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == -1) {
3540 SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
3545 if (getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == -1) {
3546 SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
3552 if ((flg = fcntl(sock, F_GETFL, 0)) == -1) {
3553 SysError(
"GetSockOpt",
"fcntl(F_GETFL)");
3556 *val = flg & O_NDELAY;
3559#if !defined(R__LYNXOS) && !defined(R__WINGCC)
3560 if (ioctl(sock, SIOCGPGRP, (
char*)val) == -1) {
3561 SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
3565 Error(
"GetSockOpt",
"ioctl(SIOCGPGRP) not supported on LynxOS and cygwin/gcc");
3570#if !defined(R__LYNXOS)
3571 if (ioctl(sock, SIOCATMARK, (
char*)val) == -1) {
3572 SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
3576 Error(
"GetSockOpt",
"ioctl(SIOCATMARK) not supported on LynxOS");
3581#if !defined(R__LYNXOS)
3582 if (ioctl(sock, FIONREAD, (
char*)val) == -1) {
3583 SysError(
"GetSockOpt",
"ioctl(FIONREAD)");
3587 Error(
"GetSockOpt",
"ioctl(FIONREAD) not supported on LynxOS");
3592 Error(
"GetSockOpt",
"illegal option (%d)", opt);
3613 { SIGBUS,
nullptr,
nullptr,
"bus error" },
3614 { SIGSEGV,
nullptr,
nullptr,
"segmentation violation" },
3615 { SIGSYS,
nullptr,
nullptr,
"bad argument to system call" },
3616 { SIGPIPE,
nullptr,
nullptr,
"write on a pipe with no one to read it" },
3617 { SIGILL,
nullptr,
nullptr,
"illegal instruction" },
3618 { SIGABRT,
nullptr,
nullptr,
"abort" },
3619 { SIGQUIT,
nullptr,
nullptr,
"quit" },
3620 { SIGINT,
nullptr,
nullptr,
"interrupt" },
3621 { SIGWINCH,
nullptr,
nullptr,
"window size change" },
3622 { SIGALRM,
nullptr,
nullptr,
"alarm clock" },
3623 { SIGCHLD,
nullptr,
nullptr,
"death of a child" },
3624 { SIGURG,
nullptr,
nullptr,
"urgent data arrived on an I/O channel" },
3625 { SIGFPE,
nullptr,
nullptr,
"floating point exception" },
3626 { SIGTERM,
nullptr,
nullptr,
"termination signal" },
3627 { SIGUSR1,
nullptr,
nullptr,
"user-defined signal 1" },
3628 { SIGUSR2,
nullptr,
nullptr,
"user-defined signal 2" }
3686 Break(
"TUnixSystem::DispatchSignals",
"%s: printing stacktrace",
UnixSigname(sig));
3709 struct sigaction sigact;
3716#elif defined(R__SOLARIS)
3718#elif defined(R__LYNXOS)
3722 sigact.sa_handler = (void (*)(...))
sighandler;
3727 sigemptyset(&sigact.sa_mask);
3728 sigact.sa_flags = 0;
3729#if defined(SA_RESTART)
3730 sigact.sa_flags |= SA_RESTART;
3732 if (sigaction(
gSignalMap[sig].fCode, &sigact,
3734 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3745 TTHREAD_TLS_ARRAY(
struct sigaction,
kMAXSIGNALS,oldsigact);
3747 if (ignore != ignoreSig[sig]) {
3748 ignoreSig[sig] = ignore;
3750 struct sigaction sigact;
3752 sigact.sa_handler = (void (*)())SIG_IGN;
3753#elif defined(R__SOLARIS)
3754 sigact.sa_handler = (void (*)(
int))SIG_IGN;
3756 sigact.sa_handler = SIG_IGN;
3758 sigemptyset(&sigact.sa_mask);
3759 sigact.sa_flags = 0;
3760 if (sigaction(
gSignalMap[sig].fCode, &sigact, &oldsigact[sig]) < 0)
3761 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3763 if (sigaction(
gSignalMap[sig].fCode, &oldsigact[sig],
nullptr) < 0)
3764 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3780 struct sigaction sigact;
3783#elif defined(R__SOLARIS)
3785#elif defined(R__LYNXOS)
3789 sigact.sa_handler = (void (*)(...))
sighandler;
3794 sigemptyset(&sigact.sa_mask);
3795 sigact.sa_flags = 0;
3797#if defined(SA_INTERRUPT)
3798 sigact.sa_flags |= SA_INTERRUPT;
3801#if defined(SA_RESTART)
3802 sigact.sa_flags |= SA_RESTART;
3806 ::SysError(
"TUnixSystem::UnixSigAlarmInterruptsSyscalls",
"sigaction");
3826 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3849 static std::atomic<time_t> jan95{0};
3860 jan95 = mktime(&tp);
3861 if ((
int)jan95 == -1) {
3862 ::SysError(
"TUnixSystem::UnixNow",
"error converting 950001 0:00 to time_t");
3868 gettimeofday(&t,
nullptr);
3877 struct itimerval itv;
3878 itv.it_value.tv_sec = 0;
3879 itv.it_value.tv_usec = 0;
3880 itv.it_interval.tv_sec = 0;
3881 itv.it_interval.tv_usec = 0;
3883 itv.it_value.tv_sec = time_t(ms / 1000);
3884 itv.it_value.tv_usec = time_t((ms % 1000) * 1000);
3886 int st = setitimer(ITIMER_REAL, &itv,
nullptr);
3888 ::SysError(
"TUnixSystem::UnixSetitimer",
"setitimer");
3906 fd_set *rd = (readready) ? (fd_set*)readready->
GetBits() :
nullptr;
3907 fd_set *wr = (writeready) ? (fd_set*)writeready->
GetBits() :
nullptr;
3911 tv.tv_sec =
Int_t(timeout / 1000);
3912 tv.tv_usec = (timeout % 1000) * 1000;
3913 retcode = select(nfds, rd, wr,
nullptr, &tv);
3915 retcode = select(nfds, rd, wr,
nullptr,
nullptr);
3917 if (retcode == -1) {
3948 pw = getpwnam(
name);
3957 pw = getpwuid(getuid());
3962 }
else if (pw && pw->
pw_dir) {
3990 if (stat(edir, &finfo) < 0)
3993 if (!S_ISDIR(finfo.st_mode))
3996 return (
void*) opendir(edir);
3999#if defined(_POSIX_SOURCE)
4002# define REAL_DIR_ENTRY(dp) 1
4004# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
4012 DIR *dirp = (DIR*)dirp1;
4044#if defined(R__SEEK64)
4046 if (path && lstat64(path, &sbuf) == 0) {
4049 if (path && lstat(path, &sbuf) == 0) {
4051 buf.
fIsLink = S_ISLNK(sbuf.st_mode);
4053#if defined(R__SEEK64)
4054 if (stat64(path, &sbuf) == -1) {
4056 if (stat(path, &sbuf) == -1) {
4061 buf.
fDev = sbuf.st_dev;
4062 buf.
fIno = sbuf.st_ino;
4063 buf.
fMode = sbuf.st_mode;
4064 buf.
fUid = sbuf.st_uid;
4065 buf.
fGid = sbuf.st_gid;
4066 buf.
fSize = sbuf.st_size;
4067 buf.
fMtime = sbuf.st_mtime;
4086 struct statfs statfsbuf;
4087#if (defined(R__SOLARIS) && !defined(R__LINUX))
4088 if (statfs(path, &statfsbuf,
sizeof(
struct statfs), 0) == 0) {
4089 *
id = statfsbuf.f_fstyp;
4090 *bsize = statfsbuf.f_bsize;
4091 *blocks = statfsbuf.f_blocks;
4092 *bfree = statfsbuf.f_bfree;
4094 if (statfs((
char*)path, &statfsbuf) == 0) {
4100 if (!strcmp(statfsbuf.f_fstypename, MOUNT_FFS) ||
4101 !strcmp(statfsbuf.f_fstypename, MOUNT_MFS))
4103 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NFS))
4105 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_MSDOS))
4107 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_EXT2FS))
4109 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_CD9660))
4111 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NCPFS))
4116 *
id = statfsbuf.f_type;
4118 *bsize = statfsbuf.f_bsize;
4119 *blocks = statfsbuf.f_blocks;
4120 *bfree = statfsbuf.f_bavail;
4133 return (
int) waitpid(0, &status, WNOHANG);
4154 sport = htons(port);
4157 if (!addr.
IsValid())
return -1;
4160 struct sockaddr_in server;
4161 memset(&server, 0,
sizeof(server));
4162 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4164 server.sin_port = sport;
4168 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4169 ::SysError(
"TUnixSystem::UnixTcpConnect",
"socket (%s:%d)",
4174 if (tcpwindowsize > 0) {
4179 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4183 ::SysError(
"TUnixSystem::UnixTcpConnect",
"connect (%s:%d)",
4205 sport = htons(port);
4208 if (!addr.
IsValid())
return -1;
4211 struct sockaddr_in server;
4212 memset(&server, 0,
sizeof(server));
4213 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4215 server.sin_port = sport;
4219 if ((sock =
socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4220 ::SysError(
"TUnixSystem::UnixUdpConnect",
"socket (%s:%d)",
4225 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4229 ::SysError(
"TUnixSystem::UnixUdpConnect",
"connect (%s:%d)",
4251 if (!sockpath || strlen(sockpath) <= 0) {
4252 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket path undefined");
4257 struct sockaddr_un unserver;
4258 unserver.sun_family = AF_UNIX;
4260 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4261 ::Error(
"TUnixSystem::UnixUnixConnect",
"socket path %s, longer than max allowed length (%u)",
4262 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4265 strlcpy(unserver.sun_path, sockpath,
sizeof(unserver.sun_path));
4268 if ((sock =
socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4269 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket");
4273 while (connect(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2) == -1) {
4277 ::SysError(
"TUnixSystem::UnixUnixConnect",
"connect");
4300 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4301 short sport, tryport = kSOCKET_MINPORT;
4304 if (port == 0 && reuse) {
4305 ::Error(
"TUnixSystem::UnixTcpService",
"cannot do a port scan while reuse is true");
4312 sport = htons(port);
4316 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4317 ::SysError(
"TUnixSystem::UnixTcpService",
"socket");
4324 if (tcpwindowsize > 0) {
4329 struct sockaddr_in inserver;
4330 memset(&inserver, 0,
sizeof(inserver));
4331 inserver.sin_family = AF_INET;
4332 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4333 inserver.sin_port = sport;
4337 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4338 ::SysError(
"TUnixSystem::UnixTcpService",
"bind");
4345 inserver.sin_port = htons(tryport);
4346 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4348 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4350 ::SysError(
"TUnixSystem::UnixTcpService",
"bind (port scan)");
4357 if (::listen(sock, backlog)) {
4358 ::SysError(
"TUnixSystem::UnixTcpService",
"listen");
4375 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4376 short sport, tryport = kSOCKET_MINPORT;
4382 sport = htons(port);
4386 if ((sock =
socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4387 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
4391 struct sockaddr_in inserver;
4392 memset(&inserver, 0,
sizeof(inserver));
4393 inserver.sin_family = AF_INET;
4394 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4395 inserver.sin_port = sport;
4399 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4400 ::SysError(
"TUnixSystem::UnixUdpService",
"bind");
4407 inserver.sin_port = htons(tryport);
4408 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4410 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4412 ::SysError(
"TUnixSystem::UnixUdpService",
"bind (port scan)");
4419 if (::listen(sock, backlog)) {
4420 ::SysError(
"TUnixSystem::UnixUdpService",
"listen");
4437 oldumask = umask(0);
4449 unlink(sockpath.
Data());
4460 if (!sockpath || strlen(sockpath) <= 0) {
4461 ::SysError(
"TUnixSystem::UnixUnixService",
"socket path undefined");
4465 struct sockaddr_un unserver;
4469 memset(&unserver, 0,
sizeof(unserver));
4470 unserver.sun_family = AF_UNIX;
4472 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4473 ::Error(
"TUnixSystem::UnixUnixService",
"socket path %s, longer than max allowed length (%u)",
4474 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4477 strlcpy(unserver.sun_path, sockpath,
sizeof(unserver.sun_path));
4480 if ((sock =
socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4481 ::SysError(
"TUnixSystem::UnixUnixService",
"socket");
4485 if (::bind(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2)) {
4486 ::SysError(
"TUnixSystem::UnixUnixService",
"bind");
4492 if (::listen(sock, backlog)) {
4493 ::SysError(
"TUnixSystem::UnixUnixService",
"listen");
4512 if (sock < 0)
return -1;
4519 if (flag == MSG_PEEK)
4523 char *buf = (
char *)buffer;
4526 if ((nrecv = recv(sock, buf+
n,
length-
n, flag)) <= 0) {
4529 if (flag == MSG_OOB) {
4560 if (sock < 0)
return -1;
4569 const char *buf = (
const char *)buffer;
4572 if ((nsent = send(sock, buf+
n,
length-
n, flag)) <= 0) {
4600 static std::atomic<bool> initialized(
kFALSE);
4601 static std::atomic<bool> seenCling(
kFALSE);
4605 if (newpath ==
nullptr && !reset && (seenCling || (initialized &&
gCling ==
nullptr)))
4606 return dynpath_full;
4611 dynpath_full = newpath;
4613 initialized =
kTRUE;
4621 return dynpath_full;
4627 if (!reset && (seenCling || (initialized &&
gCling ==
nullptr)))
4628 return dynpath_full;
4637 static TString dynpath_envpart;
4638 static TString dynpath_syspart;
4640 if (reset || !initialized) {
4649 #if defined (R__AIX)
4651 #elif defined(R__MACOSX)
4663 if (!dynpath_envpart.
IsNull())
4664 dynpath_envpart +=
":";
4665 dynpath_envpart += ldpath;
4667 if (!rdynpath.
IsNull()) {
4668 if (!dynpath_envpart.
IsNull())
4669 dynpath_envpart +=
":";
4670 dynpath_envpart += rdynpath;
4676 #if defined(R__WINGCC) || defined(R__MACOSX)
4678 dynpath_syspart =
"/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:";
4679 dynpath_syspart +=
"/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:";
4682 std::string cmd(
"LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls 2>&1");
4683 FILE *pf = popen(cmd.c_str (),
"r");
4687 if (fgets(buffer, 128, pf) != NULL)
4691 std::size_t from =
result.find(
"search path=",
result.find(
"(LD_LIBRARY_PATH)"));
4692 std::size_t to =
result.find(
"(system search path)");
4693 if (from != std::string::npos && to != std::string::npos) {
4695 std::string sys_path =
result.substr(from, to-from);
4696 sys_path.erase(std::remove_if(sys_path.begin(), sys_path.end(), isspace), sys_path.end());
4697 dynpath_syspart = sys_path.c_str();
4704 if (!initialized || (!seenCling &&
gCling)) {
4705 dynpath_full = dynpath_envpart;
4706 if (!dynpath_full.
EndsWith(
":")) dynpath_full +=
":";
4709 if (!dynpath_full.
EndsWith(
":")) dynpath_full +=
":";
4713 dynpath_full += dynpath_syspart;
4714 initialized =
kTRUE;
4716 if (
gDebug > 0) std::cout <<
"dynpath = " << dynpath_full.
Data() << std::endl;
4719 return dynpath_full;
4763 char buf[PATH_MAX + 1];
4764 char *res = realpath(sLib.
Data(), buf);
4765 if (res) sLib = buf;
4771 const char* lib = sLib.
Data();
4773 if (
len > 3 && (!strcmp(lib+
len-3,
".so") ||
4774 !strcmp(lib+
len-3,
".dl") ||
4775 !strcmp(lib+
len-4,
".dll") ||
4776 !strcmp(lib+
len-4,
".DLL") ||
4777 !strcmp(lib+
len-6,
".dylib") ||
4778 !strcmp(lib+
len-3,
".sl") ||
4779 !strcmp(lib+
len-2,
".a"))) {
4784 Error(
"FindDynamicLibrary",
4788 static const char* exts[] = {
4789 ".so",
".dll",
".dylib",
".sl",
".dl",
".a",
nullptr };
4790 const char** ext = exts;
4802 Error(
"FindDynamicLibrary",
4803 "%s[.so | .dll | .dylib | .sl | .dl | .a] does not exist in %s",
4815static void GetFreeBSDSysInfo(
SysInfo_t *sysinfo)
4820 "hw.realmem dev.cpu.0.freq",
"r");
4839 Error(
"ListSymbols",
"not yet implemented");
4843#if defined(R__MACOSX)
4844#include <sys/resource.h>
4845#include <mach/mach.h>
4846#include <mach/mach_error.h>
4851static void GetDarwinSysInfo(
SysInfo_t *sysinfo)
4853 FILE *
p =
gSystem->
OpenPipe(
"sysctl -n kern.ostype hw.model hw.ncpu hw.cpufrequency "
4854 "hw.busfrequency hw.l2cachesize hw.memsize",
"r");
4887static void ReadDarwinCpu(
long *ticks)
4889 mach_msg_type_number_t count;
4891 host_cpu_load_info_data_t cpu;
4893 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
4895 count = HOST_CPU_LOAD_INFO_COUNT;
4896 kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpu, &count);
4897 if (kr != KERN_SUCCESS) {
4898 ::Error(
"TUnixSystem::ReadDarwinCpu",
"host_statistics: %s", mach_error_string(kr));
4900 ticks[0] = cpu.cpu_ticks[CPU_STATE_USER];
4901 ticks[1] = cpu.cpu_ticks[CPU_STATE_SYSTEM];
4902 ticks[2] = cpu.cpu_ticks[CPU_STATE_IDLE];
4903 ticks[3] = cpu.cpu_ticks[CPU_STATE_NICE];
4911static void GetDarwinCpuInfo(
CpuInfo_t *cpuinfo,
Int_t sampleTime)
4914 if (getloadavg(avg,
sizeof(avg)) < 0) {
4915 ::Error(
"TUnixSystem::GetDarwinCpuInfo",
"getloadavg failed");
4922 Long_t cpu_ticks1[4], cpu_ticks2[4];
4923 ReadDarwinCpu(cpu_ticks1);
4925 ReadDarwinCpu(cpu_ticks2);
4927 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
4928 (cpu_ticks1[0] + cpu_ticks1[3]);
4929 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
4930 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
4931 if (userticks < 0) userticks = 0;
4932 if (systicks < 0) systicks = 0;
4933 if (idleticks < 0) idleticks = 0;
4934 Long_t totalticks = userticks + systicks + idleticks;
4946static void GetDarwinMemInfo(
MemInfo_t *meminfo)
4948 static Int_t pshift = 0;
4950 mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
4951 vm_statistics_data_t vm_info;
4952 kern_return_t kr = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_info, &count);
4953 if (kr != KERN_SUCCESS) {
4954 ::Error(
"TUnixSystem::GetDarwinMemInfo",
"host_statistics: %s", mach_error_string(kr));
4958 for (
int psize = getpagesize(); psize > 1; psize >>= 1)
4963 DIR *dirp = opendir(
"/private/var/vm");
4969 while ((dp = readdir(dirp)) != 0) {
4971 char fname [MAXNAMLEN];
4972 if (strncmp(dp->d_name,
"swapfile", 8))
4974 strlcpy(fname,
"/private/var/vm/",MAXNAMLEN);
4975 strlcat (fname, dp->d_name,MAXNAMLEN);
4976 if (stat(fname, &sb) < 0)
4978 swap_total += sb.st_size;
4982 Long64_t used = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.wire_count) << pshift;
4984 Long64_t total = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.free_count + vm_info.wire_count) << pshift;
4985 Long64_t avail = (
Long64_t)(vm_info.inactive_count + vm_info.free_count) << pshift;
4988 Long64_t swap_used = vm_info.pageouts << pshift;
5007static void GetDarwinProcInfo(
ProcInfo_t *procinfo)
5010#define vm_region vm_region_64
5014#define GLOBAL_SHARED_TEXT_SEGMENT 0x90000000U
5015#define GLOBAL_SHARED_DATA_SEGMENT 0xA0000000U
5016#define SHARED_TEXT_REGION_SIZE 0x10000000
5017#define SHARED_DATA_REGION_SIZE 0x10000000
5020 if (getrusage(RUSAGE_SELF, &ru) < 0) {
5021 ::SysError(
"TUnixSystem::GetDarwinProcInfo",
"getrusage failed");
5024 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
5026 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
5029 task_basic_info_data_t ti;
5030 mach_msg_type_number_t count;
5033 task_t a_task = mach_task_self();
5035 count = TASK_BASIC_INFO_COUNT;
5036 kr = task_info(a_task, TASK_BASIC_INFO, (task_info_t)&ti, &count);
5037 if (kr != KERN_SUCCESS) {
5038 ::Error(
"TUnixSystem::GetDarwinProcInfo",
"task_info: %s", mach_error_string(kr));
5043 mach_port_t object_name;
5044 vm_address_t address;
5045 vm_region_top_info_data_t info;
5046 vm_size_t vprvt, rsize,
size;
5047 rsize = ti.resident_size;
5049 for (address = 0; ; address +=
size) {
5051 count = VM_REGION_TOP_INFO_COUNT;
5052 if (vm_region(a_task, &address, &
size,
5053 VM_REGION_TOP_INFO, (vm_region_info_t)&info, &count,
5054 &object_name) != KERN_SUCCESS) {
5059 if (address >= GLOBAL_SHARED_TEXT_SEGMENT &&
5060 address < (GLOBAL_SHARED_DATA_SEGMENT + SHARED_DATA_REGION_SIZE)) {
5065 if (info.share_mode == SM_EMPTY) {
5066 vm_region_basic_info_data_64_t b_info;
5067 count = VM_REGION_BASIC_INFO_COUNT_64;
5068 if (vm_region_64(a_task, &address,
5069 &
size, VM_REGION_BASIC_INFO,
5070 (vm_region_info_t)&b_info, &count,
5071 &object_name) != KERN_SUCCESS) {
5078 if (info.share_mode != SM_PRIVATE) {
5082 switch (info.share_mode) {
5084 if (info.ref_count == 1) {
5087 vprvt += info.private_pages_resident * getpagesize();
5106#if defined(R__LINUX)
5110static void GetLinuxSysInfo(
SysInfo_t *sysinfo)
5113 FILE *
f = fopen(
"/proc/cpuinfo",
"r");
5137 f = fopen(
"/proc/meminfo",
"r");
5162static void ReadLinuxCpu(
long *ticks)
5164 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
5167 FILE *
f = fopen(
"/proc/stat",
"r");
5171 sscanf(s.
Data(),
"%*s %ld %ld %ld %ld", &ticks[0], &ticks[3], &ticks[1], &ticks[2]);
5181 Double_t avg[3] = { -1., -1., -1. };
5183 if (getloadavg(avg,
sizeof(avg)) < 0) {
5184 ::Error(
"TUnixSystem::GetLinuxCpuInfo",
"getloadavg failed");
5193 Long_t cpu_ticks1[4], cpu_ticks2[4];
5194 ReadLinuxCpu(cpu_ticks1);
5196 ReadLinuxCpu(cpu_ticks2);
5198 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
5199 (cpu_ticks1[0] + cpu_ticks1[3]);
5200 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
5201 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
5202 if (userticks < 0) userticks = 0;
5203 if (systicks < 0) systicks = 0;
5204 if (idleticks < 0) idleticks = 0;
5205 Long_t totalticks = userticks + systicks + idleticks;
5217static void GetLinuxMemInfo(
MemInfo_t *meminfo)
5220 FILE *
f = fopen(
"/proc/meminfo",
"r");
5276 meminfo->
fMemUsed = (meminfo->
fMemTotal >= usedDiff) ? meminfo->
fMemTotal - usedDiff : meminfo->fMemTotal - meminfo->fMemFree;
5286static void GetLinuxProcInfo(
ProcInfo_t *procinfo)
5289 if (getrusage(RUSAGE_SELF, &ru) < 0) {
5290 ::SysError(
"TUnixSystem::GetLinuxProcInfo",
"getrusage failed");
5293 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
5295 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
5306 sscanf(s.
Data(),
"%ld %ld", &
total, &rss);
5320 if (!info)
return -1;
5324 if (!sysinfo.
fCpus) {
5325#if defined(R__MACOSX)
5326 GetDarwinSysInfo(&sysinfo);
5327#elif defined(R__LINUX)
5328 GetLinuxSysInfo(&sysinfo);
5329#elif defined(R__FBSD)
5330 GetFreeBSDSysInfo(&sysinfo);
5346 if (!info)
return -1;
5348#if defined(R__MACOSX)
5349 GetDarwinCpuInfo(info, sampleTime);
5350#elif defined(R__LINUX)
5351 GetLinuxCpuInfo(info, sampleTime);
5352#elif defined(R__FBSD)
5353 GetFreeBSDCpuInfo(info, sampleTime);
5365 if (!info)
return -1;
5367#if defined(R__MACOSX)
5368 GetDarwinMemInfo(info);
5369#elif defined(R__LINUX)
5370 GetLinuxMemInfo(info);
5382 if (!info)
return -1;
5384#if defined(R__MACOSX)
5385 GetDarwinProcInfo(info);
5386#elif defined(R__LINUX)
5387 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
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 org
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.
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.
FILE * TempFileName(TString &base, const char *dir=nullptr, const char *suffix=nullptr) override
Create a secure temporary file by appending a unique 6 letter string to base.
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.
Int_t GetCryptoRandom(void *buf, Int_t len) override
Return cryptographic random number Fill provided buffer with random values Returns number of bytes wr...
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)