20#include "RConfigure.h"
47#if defined(R__SUN) || defined(R__AIX) || \
48 defined(R__LINUX) || defined(R__SOLARIS) || \
49 defined(R__FBSD) || defined(R__OBSD) || \
50 defined(R__MACOSX) || defined(R__HURD)
58#if defined(ULTRIX) || defined(R__SUN)
61#if defined(R__AIX) || defined(R__LINUX) || \
62 defined(R__FBSD) || defined(R__OBSD) || \
63 defined(R__LYNXOS) || defined(R__MACOSX) || defined(R__HURD)
64# include <sys/ioctl.h>
66#if defined(R__AIX) || defined(R__SOLARIS)
67# include <sys/select.h>
70# include <mach-o/dyld.h>
71# include <sys/mount.h>
72 extern "C" int statfs(
const char *
file,
struct statfs *buffer);
73#elif defined(R__LINUX) || defined(R__HURD)
75#elif defined(R__FBSD) || defined(R__OBSD)
76# include <sys/param.h>
77# include <sys/mount.h>
79# include <sys/statfs.h>
91#include <sys/resource.h>
96#include <sys/socket.h>
97#include <netinet/in.h>
98#include <netinet/tcp.h>
100# define _XOPEN_EXTENDED_SOURCE
101# include <arpa/inet.h>
102# undef _XOPEN_EXTENDED_SOURCE
103# if !defined(_AIX41) && !defined(_AIX43)
105# define HASNOT_INETATON
108# include <arpa/inet.h>
113#if defined(R__SOLARIS)
114# include <sys/systeminfo.h>
115# include <sys/filio.h>
116# include <sys/sockio.h>
117# define HASNOT_INETATON
119# define INADDR_NONE (UInt_t)-1
123#if defined(R__SOLARIS)
128#if defined(MAC_OS_X_VERSION_10_5)
134# include <sys/param.h>
135# if __FreeBSD_version >= 900007
140#if defined(R__AIX) || defined(R__FBSD) || \
141 defined(R__OBSD) || defined(R__LYNXOS) || \
142 (defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5))
146#if (defined(R__AIX) && !defined(_AIX43)) || \
147 (defined(R__SUNGCC3) && !defined(__arch64__))
149#elif defined(R__GLIBC) || defined(R__FBSD) || \
150 (defined(R__SUNGCC3) && defined(__arch64__)) || \
151 defined(R__OBSD) || defined(MAC_OS_X_VERSION_10_4) || \
152 (defined(R__AIX) && defined(_AIX43)) || \
153 (defined(R__SOLARIS) && defined(_SOCKLEN_T))
154# define USE_SOCKLEN_T
157#if defined(R__LYNXOS)
159 extern int putenv(
const char *);
160 extern int inet_aton(
const char *,
struct in_addr *);
166#define STRUCT_UTMP struct utmpx
169#define STRUCT_UTMP struct utmp
171#if !defined(UTMP_FILE) && defined(_PATH_UTMP)
172#define UTMP_FILE _PATH_UTMP
174#if defined(UTMPX_FILE)
176#define UTMP_FILE UTMPX_FILE
179#define UTMP_FILE "/etc/utmp"
183#if (defined(R__LINUX) || defined(R__HURD)) && !defined(R__WINGCC)
184# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
185# define HAVE_BACKTRACE_SYMBOLS_FD
189#if defined(R__MACOSX)
190# define HAVE_BACKTRACE_SYMBOLS_FD
194#ifdef HAVE_BACKTRACE_SYMBOLS_FD
195# include <execinfo.h>
204#ifdef HAVE_BACKTRACE_SYMBOLS_FD
207 static const int kMAX_BACKTRACE_DEPTH = 128;
211#if (defined(R__LINUX) && !defined(R__WINGCC))
212#include <fpu_control.h>
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);
278 TUtmpContent() : fUtmpContents(0), fEntries(0) {}
279 ~TUtmpContent() {
free(fUtmpContents); }
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;
323 if (!fUtmpContents) {
328 n_read = fread(fUtmpContents, 1, size, utmp);
330 if (fclose(utmp) != EOF && n_read == size) {
349# define HOWMANY(x, y) (((x)+((y)-1))/(y))
364 TFdSet() { memset(fds_bits, 0,
sizeof(fds_bits)); }
365 TFdSet(
const TFdSet &
org) { memcpy(fds_bits,
org.fds_bits,
sizeof(
org.fds_bits)); }
366 TFdSet &
operator=(
const TFdSet &rhs) {
if (
this != &rhs) { memcpy(fds_bits, rhs.fds_bits,
sizeof(rhs.fds_bits));}
return *
this; }
367 void Zero() { memset(fds_bits, 0,
sizeof(fds_bits)); }
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 int ret = readlink(
"/proc/curproc/file", buf,
kMAXPATHLEN);
450#if defined(HAVE_DLADDR) && !defined(R__MACOSX)
460 if (dladdr(addr, &info) && info.dli_fname && info.dli_fname[0]) {
462 if (!realpath(info.dli_fname, respath)) {
464 ::SysError(
"TUnixSystem::SetRootSys",
"error getting realpath of libCore, please set ROOTSYS in the shell");
476#if defined(R__MACOSX)
481static void DylibAdded(
const struct mach_header *mh, intptr_t )
490 gLinkedDylibs = linkedDylibs;
494 TString lib = _dyld_get_image_name(i++);
496 TRegexp sovers =
"libCore\\.[0-9]+\\.*[0-9]*\\.*[0-9]*\\.so";
497 TRegexp dyvers =
"libCore\\.[0-9]+\\.*[0-9]*\\.*[0-9]*\\.dylib";
505 if (!realpath(lib, respath)) {
507 ::SysError(
"TUnixSystem::DylibAdded",
"error getting realpath of libCore, please set ROOTSYS in the shell");
521 if (lib.
EndsWith(
"/libSystem.B.dylib"))
526 sovers =
"\\.[0-9]+\\.*[0-9]*\\.so";
532 dyvers =
"\\.[0-9]+\\.*[0-9]*\\.dylib";
533 idx = lib.
Index(dyvers);
539 if (linkedDylibs.
Length())
594#if defined(R__MACOSX)
597 _dyld_register_func_for_add_image(DylibAdded);
598#elif defined(HAVE_DLADDR)
641 char *tty = ::ttyname(0);
648 STRUCT_UTMP *utmp_entry = utmp.SearchUtmpEntry(tty);
650 if (utmp_entry->ut_host[0]) {
651 if (strchr(utmp_entry->ut_host,
':')) {
652 Setenv(
"DISPLAY", utmp_entry->ut_host);
653 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
654 utmp_entry->ut_host);
657 snprintf(disp,
sizeof(disp),
"%s:0.0", utmp_entry->ut_host);
659 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
664 else if (utmp_entry->ut_addr) {
666 struct sockaddr_in addr;
667 addr.sin_family = AF_INET;
669 memcpy(&addr.sin_addr, &utmp_entry->ut_addr,
sizeof(addr.sin_addr));
670 memset(&addr.sin_zero[0], 0,
sizeof(addr.sin_zero));
671 struct sockaddr *sa = (
struct sockaddr *) &addr;
673 char hbuf[NI_MAXHOST + 4];
674 if (getnameinfo(sa,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, NI_NAMEREQD) == 0) {
675 assert( strlen(hbuf) < NI_MAXHOST );
676 strcat(hbuf,
":0.0");
678 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
686 if (!
gROOT->IsBatch() && !getenv(
"DISPLAY")) {
687 Error(
"SetDisplay",
"Can't figure out DISPLAY, set it manually\n"
688 "In case you run a remote ssh session, restart your ssh session with:\n"
689 "=========> ssh -Y");
704#if defined(R__SOLARIS) || defined (R__LINUX) || defined(R__AIX) || \
705 defined(R__FBSD) || defined(R__OBSD) || defined(R__HURD)
706 return strerror(err);
708 if (err < 0 || err >= sys_nerr)
709 return Form(
"errno out of range %d", err);
710 return sys_errlist[err];
721#if defined(R__SOLARIS)
722 sysinfo(SI_HOSTNAME, hn,
sizeof(hn));
724 gethostname(hn,
sizeof(hn));
744 if (
h->HasReadInterest()) {
748 if (
h->HasWriteInterest()) {
774 int fd = th->
GetFd();
875#if defined(R__LINUX) && !defined(__powerpc__)
876#if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
878#if __GLIBC_MINOR__>=3
880 Int_t oldmask = fegetexcept();
887 Int_t oldmask = ~oldenv;
889 Int_t oldmask = ~oldenv.__control_word;
893 if (oldmask & FE_INVALID ) mask |=
kInvalid;
894 if (oldmask & FE_DIVBYZERO) mask |=
kDivByZero;
895 if (oldmask & FE_OVERFLOW ) mask |=
kOverflow;
896 if (oldmask & FE_UNDERFLOW) mask |=
kUnderflow;
898 if (oldmask & FE_INEXACT ) mask |=
kInexact;
903#if defined(R__MACOSX) && defined(__SSE2__)
905 Int_t oldmask = ~_MM_GET_EXCEPTION_MASK();
907 if (oldmask & _MM_MASK_INVALID ) mask |=
kInvalid;
908 if (oldmask & _MM_MASK_DIV_ZERO ) mask |=
kDivByZero;
909 if (oldmask & _MM_MASK_OVERFLOW ) mask |=
kOverflow;
910 if (oldmask & _MM_MASK_UNDERFLOW) mask |=
kUnderflow;
911 if (oldmask & _MM_MASK_INEXACT ) mask |=
kInexact;
914#if defined(R__MACOSX) && !defined(__SSE2__) && \
915 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
920 Int_t oldmask = ~oldenv.__fpscr;
921#elif defined(__arm64__)
922 Int_t oldmask = ~oldenv.__fpcr;
924 Int_t oldmask = ~oldenv.__control;
927 if (oldmask & FE_INVALID ) mask |=
kInvalid;
928 if (oldmask & FE_DIVBYZERO) mask |=
kDivByZero;
929 if (oldmask & FE_OVERFLOW ) mask |=
kOverflow;
930 if (oldmask & FE_UNDERFLOW) mask |=
kUnderflow;
931 if (oldmask & FE_INEXACT ) mask |=
kInexact;
934#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
935 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
940 if (oldmask & FE_ENABLE_INVALID ) mask |=
kInvalid;
941 if (oldmask & FE_ENABLE_DIVBYZERO) mask |=
kDivByZero;
942 if (oldmask & FE_ENABLE_OVERFLOW ) mask |=
kOverflow;
943 if (oldmask & FE_ENABLE_UNDERFLOW) mask |=
kUnderflow;
944 if (oldmask & FE_ENABLE_INEXACT ) mask |=
kInexact;
960#if defined(R__LINUX) && !defined(__powerpc__)
961#if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
963 if (mask &
kInvalid ) newm |= FE_INVALID;
965 if (mask &
kOverflow ) newm |= FE_OVERFLOW;
968 if (mask &
kInexact ) newm |= FE_INEXACT;
971#if __GLIBC_MINOR__>=3
974 feclearexcept(FE_ALL_EXCEPT);
975 fedisableexcept(FE_ALL_EXCEPT);
976 feenableexcept(newm);
985 cur.__control_word &= ~newm;
993#if defined(R__MACOSX) && defined(__SSE2__)
996 if (mask &
kInvalid ) newm |= _MM_MASK_INVALID;
997 if (mask &
kDivByZero) newm |= _MM_MASK_DIV_ZERO;
998 if (mask &
kOverflow ) newm |= _MM_MASK_OVERFLOW;
999 if (mask &
kUnderflow) newm |= _MM_MASK_UNDERFLOW;
1000 if (mask &
kInexact ) newm |= _MM_MASK_INEXACT;
1002 _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~newm);
1005#if defined(R__MACOSX) && !defined(__SSE2__) && \
1006 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
1008 if (mask &
kInvalid ) newm |= FE_INVALID;
1010 if (mask &
kOverflow ) newm |= FE_OVERFLOW;
1012 if (mask &
kInexact ) newm |= FE_INEXACT;
1017 cur.__fpscr &= ~newm;
1018#elif defined(__arm64__)
1019 cur.__fpcr &= ~newm;
1021 cur.__control &= ~newm;
1026#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
1027 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
1030 if (mask &
kInvalid ) newm |= FE_ENABLE_INVALID;
1031 if (mask &
kDivByZero) newm |= FE_ENABLE_DIVBYZERO;
1032 if (mask &
kOverflow ) newm |= FE_ENABLE_OVERFLOW;
1033 if (mask &
kUnderflow) newm |= FE_ENABLE_UNDERFLOW;
1034 if (mask &
kInexact ) newm |= FE_ENABLE_INEXACT;
1038 curmask = (curmask & ~FE_ENABLE_ALL_EXCEPT) | newm;
1050 Bool_t pollOnce = pendingOnly;
1059 if (!pendingOnly)
return;
1065 if (!pendingOnly)
return;
1070 if (pendingOnly && !pollOnce)
1076 if (!pendingOnly)
return;
1107 if (mxfd == 0 && nextto == -1)
1114 for (fd = 0; fd < mxfd; fd++) {
1118 if (rc < 0 && rc != -2) {
1119 SysError(
"DispatchOneEvent",
"select: read error on %d", fd);
1125 if (rc < 0 && rc != -2) {
1126 SysError(
"DispatchOneEvent",
"select: write error on %d", fd);
1143 tv.tv_sec = milliSec / 1000;
1144 tv.tv_usec = (milliSec % 1000) * 1000;
1146 select(0, 0, 0, 0, &tv);
1168 if (
h->HasReadInterest()) {
1172 if (
h->HasWriteInterest()) {
1176 h->ResetReadyMask();
1215 if (
h->HasReadInterest())
1217 if (
h->HasWriteInterest())
1219 h->ResetReadyMask();
1249 if (sync == sh->
IsSync()) {
1251 if ((
fSignals->IsSet(sig) && sigdone == -1) || sigdone == sig) {
1252 if (sigdone == -1) {
1277 TIter next(zombieHandler);
1278 register UnixPtty *pty;
1279 while ((pty = (UnixPtty*) next()))
1280 if (pty->GetPid() == pid) {
1281 zombieHandler->RemovePtr(pty);
1300 if ((fd <= fMaxrfd && fReadready->IsSet(fd) && fddone == -1) ||
1301 (fddone == fd && read)) {
1311 if ((fd <= fMaxwfd && fWriteready->IsSet(fd) && fddone == -1) ||
1312 (fddone == fd && !read)) {
1368 ::closedir((DIR*)dirp);
1422 return std::string(cwd);
1431 Error(
"WorkingDirectory",
"getcwd() failed");
1450 if (res)
return std::string(res);
1451 else return std::string();
1483 char *arg =
StrDup(base);
1484 int fd = mkstemp(arg);
1492 FILE *fp = fdopen(fd,
"w+");
1494 SysError(
"TempFileName",
"converting filedescriptor (%d)", fd);
1504 if (
name.IsNull() ||
name ==
".") {
1507 if (dir[strlen(dir) - 1] !=
'/')
1513 if (!dir || !dir[0]) dir =
"/";
1514 else if (dir[strlen(dir) - 1] !=
'/')
1552 FILE *from = fopen(
f,
"r");
1556 FILE *to = fopen(t,
"w");
1562 const int bufsize = 1024;
1565 while (!ret && !feof(from)) {
1566 size_t numread = fread (buf,
sizeof(
char), bufsize, from);
1567 size_t numwritten = fwrite(buf,
sizeof(
char), numread, to);
1568 if (numread != numwritten)
1583 int ret = ::rename(
f, t);
1628 return UnixFSstat(path,
id, bsize, blocks, bfree);
1637 return ::link(from, to);
1647 return ::symlink((
char*)from, (
char*)to);
1649 return ::symlink(from, to);
1663#if defined(R__SEEK64)
1664 struct stat64 finfo;
1665 if (lstat64(
name, &finfo) < 0)
1668 if (lstat(
name, &finfo) < 0)
1672 if (S_ISDIR(finfo.st_mode))
1673 return ::rmdir(
name);
1675 return ::unlink(
name);
1684 kShellEscape =
'\\',
1685 *kShellStuff =
"(){}<>\"'",
1700 const char *p, *patbuf = (
const char *)path;
1703 while (*patbuf ==
' ')
1707 for (p = patbuf; *p; p++)
1732 const char *patbuf = (
const char *)patbuf0;
1741 while (*patbuf ==
' ')
1745 for (p = patbuf; *p; p++)
1757 EscChar(patbuf, stuffedPat,
sizeof(stuffedPat), (
char*)kShellStuff, kShellEscape);
1762 if (stuffedPat[0] ==
'~') {
1763 if (stuffedPat[1] !=
'\0' && stuffedPat[1] !=
'/') {
1765 for (p = &stuffedPat[1],
q =
name; *p && *p !=
'/';)
1782 cmd += &stuffedPat[1];
1787 if ((pf = ::popen(cmd.Data(),
"r")) == 0) {
1798 for (ch = fgetc(pf); ch != EOF && ch !=
' ' && ch !=
'\n'; ch = fgetc(pf)) {
1804 if (
cnt == 0 && ch == EOF)
goto again;
1810 if (ch ==
' ' || ch ==
'\t') {
1844 return ::chmod(
file, mode);
1852 return ::umask(mask);
1865 t.actime = (time_t)actime;
1866 t.modtime = (time_t)modtime;
1867 return ::utime(
file, &t);
1880 show.
Form(
"Which: %s =", wfil.
Data());
1884 if (wfil[0] ==
'/') {
1885#if defined(R__SEEK64)
1886 struct stat64 finfo;
1887 if (access(wfil.
Data(), mode) == 0 &&
1888 stat64(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1891 if (access(wfil.
Data(), mode) == 0 &&
1892 stat(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1909 for (
const char* ptr = search; *ptr;) {
1911 if (*ptr !=
'/' && *ptr !=
'$' && *ptr !=
'~')
1913 const char* posEndOfPart = strchr(ptr,
':');
1915 name.Append(ptr, posEndOfPart - ptr);
1916 ptr = posEndOfPart + 1;
1922 if (!
name.EndsWith(
"/"))
1927#if defined(R__SEEK64)
1928 struct stat64 finfo;
1929 if (access(
name.Data(), mode) == 0 &&
1930 stat64(
name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1933 if (access(
name.Data(), mode) == 0 &&
1934 stat(
name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1956 if (!user || !user[0])
1959 struct passwd *apwd = getpwnam(user);
2006 static UserInfoCache_t gUserInfo;
2008 UserInfoCache_t::const_iterator iUserInfo = gUserInfo.find(uid);
2009 if (iUserInfo != gUserInfo.end())
2012 struct passwd *apwd = getpwuid(uid);
2025 gUserInfo[uid] = *ug;
2050 struct group *grp = getgrgid(gid);
2080 ::setenv(
name, value, 1);
2088 return ::getenv(
name);
2106 return ::system(shellcmd);
2114 return ::popen(command, mode);
2122 return ::pclose(pipe);
2159#include <mach/mach.h>
2167 typedef CSTypeRef CSSymbolicatorRef;
2168 typedef CSTypeRef CSSourceInfoRef;
2169 typedef CSTypeRef CSSymbolOwnerRef;
2170 typedef CSTypeRef CSSymbolRef;
2172 CSSymbolicatorRef CSSymbolicatorCreateWithPid(pid_t pid);
2173 CSSymbolRef CSSymbolicatorGetSymbolWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2174 CSSourceInfoRef CSSymbolicatorGetSourceInfoWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2175 const char* CSSymbolGetName(CSSymbolRef
sym);
2176 CSSymbolOwnerRef CSSymbolGetSymbolOwner(CSSymbolRef
sym);
2177 const char* CSSymbolOwnerGetPath(CSSymbolOwnerRef symbol);
2178 const char* CSSourceInfoGetPath(CSSourceInfoRef info);
2179 int CSSourceInfoGetLineNumber(CSSourceInfoRef info);
2182bool CSTypeRefIdValid(CSTypeRef ref) {
2183 return ref.csCppData || ref.csCppObj;
2186void macosx_backtrace() {
2187void* addrlist[kMAX_BACKTRACE_DEPTH];
2189 int numstacks = backtrace( addrlist,
sizeof( addrlist ) /
sizeof(
void* ));
2191 CSSymbolicatorRef symbolicator = CSSymbolicatorCreateWithPid(getpid());
2194 static const int skipFrames = 2;
2195 for (
int i = skipFrames; i < numstacks; ++i) {
2197 CSSymbolRef
sym = CSSymbolicatorGetSymbolWithAddressAtTime(symbolicator,
2198 (vm_address_t)addrlist[i],
2200 CSSymbolOwnerRef symOwner = CSSymbolGetSymbolOwner(
sym);
2202 if (
const char* libPath = CSSymbolOwnerGetPath(symOwner)) {
2203 printf(
"[%s]", libPath);
2205 printf(
"[<unknown binary>]");
2208 if (
const char* symname = CSSymbolGetName(
sym)) {
2209 printf(
" %s", symname);
2212 CSSourceInfoRef sourceInfo
2213 = CSSymbolicatorGetSourceInfoWithAddressAtTime(symbolicator,
2214 (vm_address_t)addrlist[i],
2216 if (
const char* sourcePath = CSSourceInfoGetPath(sourceInfo)) {
2217 printf(
" %s:%d", sourcePath, (
int)CSSourceInfoGetLineNumber(sourceInfo));
2219 printf(
" (no debug info)");
2236 gdbscript = gdbscript.
Strip();
2237 if (gdbscript !=
"") {
2239 fprintf(stderr,
"Root.StacktraceScript %s does not exist\n", gdbscript.
Data());
2243 if (gdbscript ==
"") {
2244 gdbscript =
"gdb-backtrace.sh";
2247 fprintf(stderr,
"Error in <TUnixSystem::StackTrace> script %s is missing\n", gdbscript.
Data());
2254 gdbmess = gdbmess.
Strip();
2262 int fd = STDERR_FILENO;
2264 const char *message =
" Generating stack trace...\n";
2266 if (fd && message) { }
2269 Getlinem(kCleanUp, 0);
2271#if defined(USE_GDB_STACK_TRACE)
2274 fprintf(stderr,
"gdb not found, need it for stack trace\n");
2279 TString gdbmessf =
"gdb-message";
2280 if (gdbmess !=
"") {
2282 fprintf(
f,
"%s\n", gdbmess.
Data());
2290 if (gdbmess !=
"") {
2292 gdbscript += gdbmessf;
2294 gdbscript +=
" 1>&2";
2299#elif defined(R__AIX)
2300 TString script =
"procstack ";
2304#elif defined(R__SOLARIS)
2315#elif defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_DLADDR)
2323 const char *cppfilt =
"c++filt";
2324 const char *cppfiltarg =
"";
2326 const char *format1 =
" 0x%016lx in %.200s %s 0x%lx from %.200s\n";
2328 const char *format2 =
" 0x%016lx in %.200s\n";
2330 const char *format2 =
" 0x%016lx in %.200s at %.200s from %.200s\n";
2332 const char *format3 =
" 0x%016lx in %.200s from %.200s\n";
2333 const char *format4 =
" 0x%016lx in <unknown function>\n";
2335 const char *format1 =
" 0x%08lx in %.200s %s 0x%lx from %.200s\n";
2337 const char *format2 =
" 0x%08lx in %.200s\n";
2339 const char *format2 =
" 0x%08lx in %.200s at %.200s from %.200s\n";
2341 const char *format3 =
" 0x%08lx in %.200s from %.200s\n";
2342 const char *format4 =
" 0x%08lx in <unknown function>\n";
2354 while (help.
Gets(p)) {
2356 cppfiltarg =
"--format=gnu-v3";
2358 }
else if (help.
Index(
"gnu-new-abi") !=
kNPOS) {
2359 cppfiltarg =
"--format=gnu-new-abi";
2368#if (defined(R__LINUX) && !defined(R__WINGCC))
2371#ifdef PR_SET_PTRACER
2372 prctl(PR_SET_PTRACER, getpid(), 0, 0, 0);
2378 TString gdbmessf =
"gdb-message";
2379 if (gdbmess !=
"") {
2381 fprintf(
f,
"%s\n", gdbmess.
Data());
2391 if (gdbmess !=
"") {
2393 gdbscript += gdbmessf;
2395 gdbscript +=
" 1>&2";
2408 if (write(fd, message, strlen(message)) < 0)
2413 TString tmpf1 =
"gdb-backtrace";
2414 std::ofstream file1;
2420 Error(
"StackTrace",
"could not open file %s", tmpf1.
Data());
2432 void *trace[kMAX_BACKTRACE_DEPTH];
2433 int depth = backtrace(trace, kMAX_BACKTRACE_DEPTH);
2434 for (
int n = 5;
n < depth;
n++) {
2438 if (dladdr(trace[
n], &info) && info.dli_fname && info.dli_fname[0]) {
2439 const char *libname = info.dli_fname;
2440 const char *symname = (info.dli_sname && info.dli_sname[0]) ?
2441 info.dli_sname :
"<unknown>";
2444 Bool_t gte = (addr >= symaddr);
2445 ULong_t diff = (gte) ? addr - symaddr : symaddr - addr;
2446 if (addr2line && symaddr) {
2450#if defined(MAC_OS_X_VERSION_10_10)
2451 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2452#elif defined(MAC_OS_X_VERSION_10_9)
2454 snprintf(buffer,
sizeof(buffer),
"%s -d -p %d 0x%016lx", addr2line,
GetPid(), addr);
2456 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2459 ULong_t offset = (addr >= libaddr) ? addr - libaddr :
2465 if (
name.Contains(
".so") ||
name.Contains(
".sl")) noShare =
kFALSE;
2466 if (noShare) offset = addr;
2467 if (noPath)
name =
"`which " +
name +
"`";
2468 snprintf(buffer,
sizeof(buffer),
"%s -e %s 0x%016lx", addr2line,
name.Data(), offset);
2470 if (FILE *pf = ::popen(buffer,
"r")) {
2472 if (fgets(buf, 2048, pf)) {
2473 buf[strlen(buf)-1] = 0;
2474 if (strncmp(buf,
"??", 2)) {
2476 snprintf(buffer,
sizeof(buffer), format2, addr, buf);
2478 snprintf(buffer,
sizeof(buffer), format2, addr, symname, buf, libname);
2486 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2487 gte ?
"+" :
"-", diff, libname);
2490 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2491 gte ?
"+" :
"-", diff, libname);
2493 snprintf(buffer,
sizeof(buffer), format3, addr, symname, libname);
2496 snprintf(buffer,
sizeof(buffer), format4, addr);
2502 if (write(fd, buffer, ::strlen(buffer)) < 0)
2507 TString tmpf2 =
"gdb-backtrace";
2511 snprintf(buffer,
sizeof(buffer),
"%s %s < %s > %s", filter, cppfiltarg, tmpf1.
Data(), tmpf2.
Data());
2513 std::ifstream file2(tmpf2);
2517 line.ReadString(file2);
2518 if (write(fd,
line.Data(),
line.Length()) < 0)
2526 delete [] addr2line;
2529#elif defined(HAVE_EXCPT_H) && defined(HAVE_PDSC_H) && \
2530 defined(HAVE_RLD_INTERFACE_H)
2539 exc_capture_context (&context);
2540 while (!rc && context.sc_pc) {
2542 pdsc_crd *func, *base, *crd
2543 = exc_remote_lookup_function_entry(0, 0, context.sc_pc, 0, &func, &base);
2544 Elf32_Addr addr = PDSC_CRD_BEGIN_ADDRESS(base, func);
2546 const char *
name =
"<unknown function>";
2547 sprintf(buffer,
" 0x%012lx %.200s + 0x%lx\n",
2548 context.sc_pc,
name, context.sc_pc - addr);
2549 write(fd, buffer, ::strlen(buffer));
2550 rc = exc_virtual_unwind(0, &context);
2595 ::openlog(
name, options, fac);
2605 ::syslog(level,
"%s", mess);
2645 const char *tty = ttyname(STDOUT_FILENO);
2649 if ((xh->
fStdOutDup = dup(STDOUT_FILENO)) < 0) {
2657 const char *tty = ttyname(STDERR_FILENO);
2661 if ((xh->
fStdErrDup = dup(STDERR_FILENO)) < 0) {
2663 if (outdone && dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2664 Warning(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2673 const char *
m = (mode[0] ==
'a' || mode[0] ==
'w') ? mode :
"a";
2686 if (freopen(
file,
m, stdout) == 0) {
2690 if (freopen(
file,
m, stderr) == 0) {
2706 if (
close(STDOUT_FILENO) != 0) {
2708 "problems closing STDOUT_FILENO (%d) before 'dup2' (errno: %d)",
2712 if (dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2713 SysError(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2719 "problems closing temporary 'out' descriptor %d (errno: %d)",
2732 if (
close(STDERR_FILENO) != 0) {
2734 "problems closing STDERR_FILENO (%d) before 'dup2' (errno: %d)",
2738 if (dup2(xh->
fStdErrDup, STDERR_FILENO) < 0) {
2739 SysError(
"RedirectOutput",
"could not restore stderr (back to original redirected"
2745 "problems closing temporary 'err' descriptor %d (errno: %d)",
2790 Error(
"ListSymbols",
"not yet implemented");
2812 if (!linkedLibs.
IsNull())
2818#if !defined(R__MACOSX)
2824#if defined(R__MACOSX)
2826 linkedLibs = gLinkedDylibs;
2830 while (otool.
Gets(p)) {
2835 if (!linkedLibs.
IsNull())
2837 linkedLibs += dylib;
2845#elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__AIX)
2846#if defined(R__WINGCC )
2847 const char *cLDD=
"cygcheck";
2848 const char *cSOEXT=
".dll";
2849 size_t lenexe = strlen(exe);
2850 if (strcmp(exe + lenexe - 4,
".exe")
2851 && strcmp(exe + lenexe - 4,
".dll")) {
2854 char* longerexe =
new char[lenexe + 5];
2855 strlcpy(longerexe, exe,lenexe+5);
2856 strlcat(longerexe,
".exe",lenexe+5);
2860 TRegexp sovers =
"\\.so\\.[0-9]+";
2862 const char *cLDD=
"ldd";
2864 const char *cSOEXT=
".a";
2865 TRegexp sovers =
"\\.a\\.[0-9]+";
2867 const char *cSOEXT=
".so";
2868 TRegexp sovers =
"\\.so\\.[0-9]+";
2874 while (ldd.
Gets(p)) {
2893 if (!linkedLibs.
IsNull())
2895 linkedLibs += solib;
2940 if (mode && t->
IsSync()) {
2943 }
else if (!mode && t->
IsAsync()) {
2997 struct addrinfo hints;
2998 struct addrinfo *result, *rp;
2999 memset(&hints, 0,
sizeof(
struct addrinfo));
3000 hints.ai_family = AF_INET;
3001 hints.ai_socktype = 0;
3002 hints.ai_protocol = 0;
3003 hints.ai_flags = AI_CANONNAME;
3008 size_t lenHostname = strlen(hostname);
3009 std::string hostnameWithoutLocal{hostname};
3010 if (lenHostname > 6 && !strcmp(hostname + lenHostname - 6,
".local")) {
3011 hostnameWithoutLocal.erase(lenHostname - 6);
3012 hostname = hostnameWithoutLocal.c_str();
3017 int rc = getaddrinfo(hostname,
nullptr, &hints, &result);
3019 if (rc == EAI_NONAME) {
3020 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host '%s'", hostname);
3023 Error(
"GetHostByName",
"getaddrinfo failed for '%s': %s", hostname, gai_strerror(rc));
3029 std::string hostcanon(result->ai_canonname ? result->ai_canonname : hostname);
3031 ia.
fFamily = result->ai_family;
3032 ia.
fAddresses[0] = ntohl(((
struct sockaddr_in *)(result->ai_addr))->sin_addr.s_addr);
3034 if (hostcanon.compare(hostname) != 0) ia.
AddAlias(hostname);
3037 char tmp[
sizeof(
struct in_addr)];
3038 if (inet_pton(AF_INET, hostcanon.data(), tmp) == 1) {
3039 char hbuf[NI_MAXHOST];
3040 if (getnameinfo(result->ai_addr, result->ai_addrlen, hbuf,
sizeof(hbuf),
nullptr, 0, 0) == 0)
3045 rp = result->ai_next;
3046 for (; rp !=
nullptr; rp = rp->ai_next) {
3047 UInt_t arp = ntohl(((
struct sockaddr_in *)(rp->ai_addr))->sin_addr.s_addr);
3052 freeaddrinfo(result);
3061 struct sockaddr addr;
3062#if defined(USE_SIZE_T)
3063 size_t len =
sizeof(addr);
3064#elif defined(USE_SOCKLEN_T)
3065 socklen_t len =
sizeof(addr);
3067 int len =
sizeof(addr);
3071 if (getsockname(sock, &addr, &len) == -1) {
3072 SysError(
"GetSockName",
"getsockname failed");
3076 if (addr.sa_family != AF_INET)
return ia;
3078 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3079 ia.
fPort = ntohs(addrin->sin_port);
3080 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3082 char hbuf[NI_MAXHOST];
3083 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3084 Error(
"GetSockName",
"getnameinfo failed");
3097 struct sockaddr addr;
3098#if defined(USE_SIZE_T)
3099 size_t len =
sizeof(addr);
3100#elif defined(USE_SOCKLEN_T)
3101 socklen_t len =
sizeof(addr);
3103 int len =
sizeof(addr);
3107 if (getpeername(sock, &addr, &len) == -1) {
3108 SysError(
"GetPeerName",
"getpeername failed");
3112 if (addr.sa_family != AF_INET)
return ia;
3114 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3115 ia.
fPort = ntohs(addrin->sin_port);
3116 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3118 char hbuf[NI_MAXHOST];
3119 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3120 Error(
"GetPeerName",
"getnameinfo failed");
3135 if ((sp = getservbyname(servicename,
kProtocolName)) == 0) {
3136 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
3140 return ntohs(sp->s_port);
3150 if ((sp = getservbyport(htons(port),
kProtocolName)) == 0) {
3153 return Form(
"%d", port);
3162 int tcpwindowsize,
const char *protocol)
3164 if (!strcmp(servername,
"unix")) {
3170 if (!strcmp(protocol,
"udp")){
3240 while ((soc = ::accept(sock, 0, 0)) == -1 &&
GetErrno() == EINTR)
3247 SysError(
"AcceptConnection",
"accept");
3260 if (sock < 0)
return;
3262#if !defined(R__AIX) || defined(_AIX41) || defined(_AIX43)
3264 ::shutdown(sock, 2);
3280 if (
UnixRecv(sock, &header,
sizeof(header), 0) > 0) {
3281 int count = ntohl(header);
3283 if (count > length) {
3284 Error(
"RecvBuf",
"record header exceeds buffer size");
3286 }
else if (count > 0) {
3287 if (
UnixRecv(sock, buf, count, 0) < 0) {
3288 Error(
"RecvBuf",
"cannot receive buffer");
3303 Int_t header = htonl(length);
3305 if (
UnixSend(sock, &header,
sizeof(header), 0) < 0) {
3306 Error(
"SendBuf",
"cannot send header");
3310 if (
UnixSend(sock, buf, length, 0) < 0) {
3311 Error(
"SendBuf",
"cannot send buffer");
3351 if ((
n =
UnixRecv(sock, buf, length, flag)) <= 0) {
3353 Error(
"RecvRaw",
"cannot receive buffer");
3386 if ((
n =
UnixSend(sock, buf, length, flag)) <= 0) {
3388 Error(
"SendRaw",
"cannot send buffer");
3399 if (sock < 0)
return -1;
3403 if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == -1) {
3404 SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
3409 if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == -1) {
3410 SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
3415 if (setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == -1) {
3416 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
3421 if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == -1) {
3422 SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
3427 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == -1) {
3428 SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
3433 if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == -1) {
3434 SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
3439 if (ioctl(sock, FIONBIO, (
char*)&val) == -1) {
3440 SysError(
"SetSockOpt",
"ioctl(FIONBIO)");
3446 if (ioctl(sock, SIOCSPGRP, (
char*)&val) == -1) {
3447 SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
3451 Error(
"SetSockOpt",
"ioctl(SIOCGPGRP) not supported on cygwin/gcc");
3458 Error(
"SetSockOpt",
"illegal option (%d)", opt);
3469 if (sock < 0)
return -1;
3471#if defined(USE_SOCKLEN_T) || defined(_AIX43)
3472 socklen_t optlen =
sizeof(*val);
3473#elif defined(USE_SIZE_T)
3474 size_t optlen =
sizeof(*val);
3476 int optlen =
sizeof(*val);
3481 if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == -1) {
3482 SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
3487 if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == -1) {
3488 SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
3493 if (getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == -1) {
3494 SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
3499 if (getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == -1) {
3500 SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
3505 if (getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == -1) {
3506 SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
3511 if (getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == -1) {
3512 SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
3518 if ((flg = fcntl(sock, F_GETFL, 0)) == -1) {
3519 SysError(
"GetSockOpt",
"fcntl(F_GETFL)");
3522 *val = flg & O_NDELAY;
3525#if !defined(R__LYNXOS) && !defined(R__WINGCC)
3526 if (ioctl(sock, SIOCGPGRP, (
char*)val) == -1) {
3527 SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
3531 Error(
"GetSockOpt",
"ioctl(SIOCGPGRP) not supported on LynxOS and cygwin/gcc");
3536#if !defined(R__LYNXOS)
3537 if (ioctl(sock, SIOCATMARK, (
char*)val) == -1) {
3538 SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
3542 Error(
"GetSockOpt",
"ioctl(SIOCATMARK) not supported on LynxOS");
3547#if !defined(R__LYNXOS)
3548 if (ioctl(sock, FIONREAD, (
char*)val) == -1) {
3549 SysError(
"GetSockOpt",
"ioctl(FIONREAD)");
3553 Error(
"GetSockOpt",
"ioctl(FIONREAD) not supported on LynxOS");
3558 Error(
"GetSockOpt",
"illegal option (%d)", opt);
3573static struct Signalmap_t {
3576 struct sigaction *fOldHandler;
3577 const char *fSigName;
3579 { SIGBUS, 0, 0,
"bus error" },
3580 { SIGSEGV, 0, 0,
"segmentation violation" },
3581 { SIGSYS, 0, 0,
"bad argument to system call" },
3582 { SIGPIPE, 0, 0,
"write on a pipe with no one to read it" },
3583 { SIGILL, 0, 0,
"illegal instruction" },
3584 { SIGQUIT, 0, 0,
"quit" },
3585 { SIGINT, 0, 0,
"interrupt" },
3586 { SIGWINCH, 0, 0,
"window size change" },
3587 { SIGALRM, 0, 0,
"alarm clock" },
3588 { SIGCHLD, 0, 0,
"death of a child" },
3589 { SIGURG, 0, 0,
"urgent data arrived on an I/O channel" },
3590 { SIGFPE, 0, 0,
"floating point exception" },
3591 { SIGTERM, 0, 0,
"termination signal" },
3592 { SIGUSR1, 0, 0,
"user-defined signal 1" },
3593 { SIGUSR2, 0, 0,
"user-defined signal 2" }
3644 Break(
"TUnixSystem::DispatchSignals",
"%s: printing stacktrace",
UnixSigname(sig));
3667 struct sigaction sigact;
3670 gSignalMap[sig].fOldHandler =
new struct sigaction();
3674#elif defined(R__SOLARIS)
3676#elif defined(R__LYNXOS)
3685 sigemptyset(&sigact.sa_mask);
3686 sigact.sa_flags = 0;
3687#if defined(SA_RESTART)
3688 sigact.sa_flags |= SA_RESTART;
3690 if (sigaction(
gSignalMap[sig].fCode, &sigact,
3692 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3703 TTHREAD_TLS_ARRAY(
struct sigaction,
kMAXSIGNALS,oldsigact);
3705 if (ignore != ignoreSig[sig]) {
3706 ignoreSig[sig] = ignore;
3708 struct sigaction sigact;
3710 sigact.sa_handler = (
void (*)())SIG_IGN;
3711#elif defined(R__SOLARIS)
3712 sigact.sa_handler = (
void (*)(int))SIG_IGN;
3714 sigact.sa_handler = SIG_IGN;
3716 sigemptyset(&sigact.sa_mask);
3717 sigact.sa_flags = 0;
3718 if (sigaction(
gSignalMap[sig].fCode, &sigact, &oldsigact[sig]) < 0)
3719 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3721 if (sigaction(
gSignalMap[sig].fCode, &oldsigact[sig], 0) < 0)
3722 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3738 struct sigaction sigact;
3741#elif defined(R__SOLARIS)
3743#elif defined(R__LYNXOS)
3752 sigemptyset(&sigact.sa_mask);
3753 sigact.sa_flags = 0;
3755#if defined(SA_INTERRUPT)
3756 sigact.sa_flags |= SA_INTERRUPT;
3759#if defined(SA_RESTART)
3760 sigact.sa_flags |= SA_RESTART;
3764 ::SysError(
"TUnixSystem::UnixSigAlarmInterruptsSyscalls",
"sigaction");
3784 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3807 static std::atomic<time_t> jan95{0};
3818 jan95 = mktime(&tp);
3819 if ((
int)jan95 == -1) {
3820 ::SysError(
"TUnixSystem::UnixNow",
"error converting 950001 0:00 to time_t");
3826 gettimeofday(&t, 0);
3835 struct itimerval itv;
3836 itv.it_value.tv_sec = 0;
3837 itv.it_value.tv_usec = 0;
3838 itv.it_interval.tv_sec = 0;
3839 itv.it_interval.tv_usec = 0;
3841 itv.it_value.tv_sec = time_t(
ms / 1000);
3842 itv.it_value.tv_usec = time_t((
ms % 1000) * 1000);
3844 int st = setitimer(ITIMER_REAL, &itv, 0);
3846 ::SysError(
"TUnixSystem::UnixSetitimer",
"setitimer");
3864 fd_set *rd = (readready) ? (fd_set*)readready->GetBits() : 0;
3865 fd_set *wr = (writeready) ? (fd_set*)writeready->GetBits() : 0;
3869 tv.tv_sec =
Int_t(timeout / 1000);
3870 tv.tv_usec = (timeout % 1000) * 1000;
3871 retcode = select(nfds, rd, wr, 0, &tv);
3873 retcode = select(nfds, rd, wr, 0, 0);
3875 if (retcode == -1) {
3906 pw = getpwnam(
name);
3915 pw = getpwuid(getuid());
3948 if (stat(edir, &finfo) < 0)
3951 if (!S_ISDIR(finfo.st_mode))
3954 return (
void*) opendir(edir);
3957#if defined(_POSIX_SOURCE)
3960# define REAL_DIR_ENTRY(dp) 1
3962# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
3970 DIR *dirp = (DIR*)dirp1;
4002#if defined(R__SEEK64)
4004 if (path && lstat64(path, &sbuf) == 0) {
4007 if (path && lstat(path, &sbuf) == 0) {
4009 buf.
fIsLink = S_ISLNK(sbuf.st_mode);
4011#if defined(R__SEEK64)
4012 if (stat64(path, &sbuf) == -1) {
4014 if (stat(path, &sbuf) == -1) {
4019 buf.
fDev = sbuf.st_dev;
4020 buf.
fIno = sbuf.st_ino;
4021 buf.
fMode = sbuf.st_mode;
4022 buf.
fUid = sbuf.st_uid;
4023 buf.
fGid = sbuf.st_gid;
4024 buf.
fSize = sbuf.st_size;
4025 buf.
fMtime = sbuf.st_mtime;
4044 struct statfs statfsbuf;
4045#if (defined(R__SOLARIS) && !defined(R__LINUX))
4046 if (statfs(path, &statfsbuf,
sizeof(
struct statfs), 0) == 0) {
4047 *
id = statfsbuf.f_fstyp;
4048 *bsize = statfsbuf.f_bsize;
4049 *blocks = statfsbuf.f_blocks;
4050 *bfree = statfsbuf.f_bfree;
4052 if (statfs((
char*)path, &statfsbuf) == 0) {
4058 if (!strcmp(statfsbuf.f_fstypename, MOUNT_FFS) ||
4059 !strcmp(statfsbuf.f_fstypename, MOUNT_MFS))
4061 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NFS))
4063 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_MSDOS))
4065 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_EXT2FS))
4067 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_CD9660))
4069 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NCPFS))
4074 *
id = statfsbuf.f_type;
4076 *bsize = statfsbuf.f_bsize;
4077 *blocks = statfsbuf.f_blocks;
4078 *bfree = statfsbuf.f_bavail;
4091 return (
int) waitpid(0, &status, WNOHANG);
4112 sport = htons(port);
4115 if (!addr.
IsValid())
return -1;
4118 struct sockaddr_in server;
4119 memset(&server, 0,
sizeof(server));
4120 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4122 server.sin_port = sport;
4126 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4127 ::SysError(
"TUnixSystem::UnixTcpConnect",
"socket (%s:%d)",
4132 if (tcpwindowsize > 0) {
4137 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4141 ::SysError(
"TUnixSystem::UnixTcpConnect",
"connect (%s:%d)",
4163 sport = htons(port);
4166 if (!addr.
IsValid())
return -1;
4169 struct sockaddr_in server;
4170 memset(&server, 0,
sizeof(server));
4171 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4173 server.sin_port = sport;
4177 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4178 ::SysError(
"TUnixSystem::UnixUdpConnect",
"socket (%s:%d)",
4183 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4187 ::SysError(
"TUnixSystem::UnixUdpConnect",
"connect (%s:%d)",
4209 if (!sockpath || strlen(sockpath) <= 0) {
4210 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket path undefined");
4215 struct sockaddr_un unserver;
4216 unserver.sun_family = AF_UNIX;
4218 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4219 ::Error(
"TUnixSystem::UnixUnixConnect",
"socket path %s, longer than max allowed length (%u)",
4220 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4223 strcpy(unserver.sun_path, sockpath);
4226 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4227 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket");
4231 while (connect(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2) == -1) {
4235 ::SysError(
"TUnixSystem::UnixUnixConnect",
"connect");
4258 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4259 short sport, tryport = kSOCKET_MINPORT;
4262 if (port == 0 && reuse) {
4263 ::Error(
"TUnixSystem::UnixTcpService",
"cannot do a port scan while reuse is true");
4270 sport = htons(port);
4274 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4275 ::SysError(
"TUnixSystem::UnixTcpService",
"socket");
4282 if (tcpwindowsize > 0) {
4287 struct sockaddr_in inserver;
4288 memset(&inserver, 0,
sizeof(inserver));
4289 inserver.sin_family = AF_INET;
4290 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4291 inserver.sin_port = sport;
4295 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4296 ::SysError(
"TUnixSystem::UnixTcpService",
"bind");
4303 inserver.sin_port = htons(tryport);
4304 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4306 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4308 ::SysError(
"TUnixSystem::UnixTcpService",
"bind (port scan)");
4315 if (::listen(sock, backlog)) {
4316 ::SysError(
"TUnixSystem::UnixTcpService",
"listen");
4333 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4334 short sport, tryport = kSOCKET_MINPORT;
4340 sport = htons(port);
4344 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4345 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
4349 struct sockaddr_in inserver;
4350 memset(&inserver, 0,
sizeof(inserver));
4351 inserver.sin_family = AF_INET;
4352 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4353 inserver.sin_port = sport;
4357 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4358 ::SysError(
"TUnixSystem::UnixUdpService",
"bind");
4365 inserver.sin_port = htons(tryport);
4366 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4368 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4370 ::SysError(
"TUnixSystem::UnixUdpService",
"bind (port scan)");
4377 if (::listen(sock, backlog)) {
4378 ::SysError(
"TUnixSystem::UnixUdpService",
"listen");
4395 oldumask = umask(0);
4407 unlink(sockpath.
Data());
4418 if (!sockpath || strlen(sockpath) <= 0) {
4419 ::SysError(
"TUnixSystem::UnixUnixService",
"socket path undefined");
4423 struct sockaddr_un unserver;
4427 memset(&unserver, 0,
sizeof(unserver));
4428 unserver.sun_family = AF_UNIX;
4430 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4431 ::Error(
"TUnixSystem::UnixUnixService",
"socket path %s, longer than max allowed length (%u)",
4432 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4435 strcpy(unserver.sun_path, sockpath);
4438 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4439 ::SysError(
"TUnixSystem::UnixUnixService",
"socket");
4443 if (::bind(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2)) {
4444 ::SysError(
"TUnixSystem::UnixUnixService",
"bind");
4450 if (::listen(sock, backlog)) {
4451 ::SysError(
"TUnixSystem::UnixUnixService",
"listen");
4470 if (sock < 0)
return -1;
4477 if (flag == MSG_PEEK)
4481 char *buf = (
char *)buffer;
4483 for (
n = 0;
n < length;
n += nrecv) {
4484 if ((nrecv = recv(sock, buf+
n, length-
n, flag)) <= 0) {
4487 if (flag == MSG_OOB) {
4518 if (sock < 0)
return -1;
4527 const char *buf = (
const char *)buffer;
4529 for (
n = 0;
n < length;
n += nsent) {
4530 if ((nsent = send(sock, buf+
n, length-
n, flag)) <= 0) {
4568 }
else if (reset || !initialized) {
4569 initialized =
kTRUE;
4578#elif defined(R__MACOSX)
4592 dynpath = ldpath; dynpath +=
":"; dynpath += rdynpath;
4602#if defined(R__WINGCC) || defined(R__MACOSX)
4603 if (!dynpath.
EndsWith(
":")) dynpath +=
":";
4604 dynpath +=
"/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:";
4605 dynpath +=
"/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:";
4608 std::string cmd(
"LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls 2>&1");
4609 FILE *pf = popen(cmd.c_str (),
"r");
4610 std::string result =
"";
4613 if (fgets(buffer, 128, pf) != NULL)
4617 std::size_t from = result.find(
"search path=", result.find(
"(LD_LIBRARY_PATH)"));
4618 std::size_t to = result.find(
"(system search path)");
4619 if (from != std::string::npos && to != std::string::npos) {
4621 std::string sys_path = result.substr(from, to-from);
4622 sys_path.erase(std::remove_if(sys_path.begin(), sys_path.end(), isspace), sys_path.end());
4623 if (!dynpath.
EndsWith(
":")) dynpath +=
":";
4624 dynpath += sys_path.c_str();
4628 if (
gDebug > 0) std::cout <<
"dynpath = " << dynpath.
Data() << std::endl;
4674 char buf[PATH_MAX + 1];
4675 char *res = realpath(sLib.
Data(), buf);
4676 if (res) sLib = buf;
4682 const char* lib = sLib.
Data();
4684 if (len > 3 && (!strcmp(lib+len-3,
".so") ||
4685 !strcmp(lib+len-3,
".dl") ||
4686 !strcmp(lib+len-4,
".dll") ||
4687 !strcmp(lib+len-4,
".DLL") ||
4688 !strcmp(lib+len-6,
".dylib") ||
4689 !strcmp(lib+len-3,
".sl") ||
4690 !strcmp(lib+len-2,
".a"))) {
4695 Error(
"FindDynamicLibrary",
4699 static const char* exts[] = {
4700 ".so",
".dll",
".dylib",
".sl",
".dl",
".a", 0 };
4701 const char** ext = exts;
4713 Error(
"FindDynamicLibrary",
4714 "%s[.so | .dll | .dylib | .sl | .dl | .a] does not exist in %s",
4722#if defined(R__MACOSX)
4723#include <sys/resource.h>
4724#include <mach/mach.h>
4725#include <mach/mach_error.h>
4730static void GetDarwinSysInfo(
SysInfo_t *sysinfo)
4732 FILE *p =
gSystem->
OpenPipe(
"sysctl -n kern.ostype hw.model hw.ncpu hw.cpufrequency "
4733 "hw.busfrequency hw.l2cachesize hw.memsize",
"r");
4740 sysinfo->
fCpus =
s.Atoi();
4755 if (
s.BeginsWith(
"Processor type: ")) {
4766static void ReadDarwinCpu(
long *ticks)
4768 mach_msg_type_number_t count;
4770 host_cpu_load_info_data_t cpu;
4772 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
4774 count = HOST_CPU_LOAD_INFO_COUNT;
4775 kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpu, &count);
4776 if (kr != KERN_SUCCESS) {
4777 ::Error(
"TUnixSystem::ReadDarwinCpu",
"host_statistics: %s", mach_error_string(kr));
4779 ticks[0] = cpu.cpu_ticks[CPU_STATE_USER];
4780 ticks[1] = cpu.cpu_ticks[CPU_STATE_SYSTEM];
4781 ticks[2] = cpu.cpu_ticks[CPU_STATE_IDLE];
4782 ticks[3] = cpu.cpu_ticks[CPU_STATE_NICE];
4790static void GetDarwinCpuInfo(
CpuInfo_t *cpuinfo,
Int_t sampleTime)
4793 if (getloadavg(avg,
sizeof(avg)) < 0) {
4794 ::Error(
"TUnixSystem::GetDarwinCpuInfo",
"getloadavg failed");
4801 Long_t cpu_ticks1[4], cpu_ticks2[4];
4802 ReadDarwinCpu(cpu_ticks1);
4804 ReadDarwinCpu(cpu_ticks2);
4806 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
4807 (cpu_ticks1[0] + cpu_ticks1[3]);
4808 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
4809 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
4810 if (userticks < 0) userticks = 0;
4811 if (systicks < 0) systicks = 0;
4812 if (idleticks < 0) idleticks = 0;
4813 Long_t totalticks = userticks + systicks + idleticks;
4825static void GetDarwinMemInfo(
MemInfo_t *meminfo)
4827 static Int_t pshift = 0;
4829 vm_statistics_data_t vm_info;
4830 mach_msg_type_number_t count;
4835 count = HOST_VM_INFO_COUNT;
4836 kr = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_info, &count);
4837 if (kr != KERN_SUCCESS) {
4838 ::Error(
"TUnixSystem::GetDarwinMemInfo",
"host_statistics: %s", mach_error_string(kr));
4842 for (
int psize = getpagesize(); psize > 1; psize >>= 1)
4846 used = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.wire_count) << pshift;
4848 total = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.free_count + vm_info.wire_count) << pshift;
4851 swap_used = vm_info.pageouts << pshift;
4854 dirp = opendir(
"/private/var/vm");
4859 while ((dp = readdir(dirp)) != 0) {
4861 char fname [MAXNAMLEN];
4862 if (strncmp(dp->d_name,
"swapfile", 8))
4864 strlcpy(fname,
"/private/var/vm/",MAXNAMLEN);
4865 strlcat (fname, dp->d_name,MAXNAMLEN);
4866 if (stat(fname, &sb) < 0)
4868 swap_total += sb.st_size;
4888static void GetDarwinProcInfo(
ProcInfo_t *procinfo)
4891#define vm_region vm_region_64
4895#define GLOBAL_SHARED_TEXT_SEGMENT 0x90000000U
4896#define GLOBAL_SHARED_DATA_SEGMENT 0xA0000000U
4897#define SHARED_TEXT_REGION_SIZE 0x10000000
4898#define SHARED_DATA_REGION_SIZE 0x10000000
4901 if (getrusage(RUSAGE_SELF, &ru) < 0) {
4902 ::SysError(
"TUnixSystem::GetDarwinProcInfo",
"getrusage failed");
4905 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
4907 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
4910 task_basic_info_data_t ti;
4911 mach_msg_type_number_t count;
4914 task_t a_task = mach_task_self();
4916 count = TASK_BASIC_INFO_COUNT;
4917 kr = task_info(a_task, TASK_BASIC_INFO, (task_info_t)&ti, &count);
4918 if (kr != KERN_SUCCESS) {
4919 ::Error(
"TUnixSystem::GetDarwinProcInfo",
"task_info: %s", mach_error_string(kr));
4924 mach_port_t object_name;
4925 vm_address_t address;
4926 vm_region_top_info_data_t info;
4927 vm_size_t vsize, vprvt, rsize, size;
4928 rsize = ti.resident_size;
4929 vsize = ti.virtual_size;
4931 for (address = 0; ; address += size) {
4933 count = VM_REGION_TOP_INFO_COUNT;
4934 if (vm_region(a_task, &address, &size,
4935 VM_REGION_TOP_INFO, (vm_region_info_t)&info, &count,
4936 &object_name) != KERN_SUCCESS) {
4941 if (address >= GLOBAL_SHARED_TEXT_SEGMENT &&
4942 address < (GLOBAL_SHARED_DATA_SEGMENT + SHARED_DATA_REGION_SIZE)) {
4947 if (info.share_mode == SM_EMPTY) {
4948 vm_region_basic_info_data_64_t b_info;
4949 count = VM_REGION_BASIC_INFO_COUNT_64;
4950 if (vm_region_64(a_task, &address,
4951 &size, VM_REGION_BASIC_INFO,
4952 (vm_region_info_t)&b_info, &count,
4953 &object_name) != KERN_SUCCESS) {
4957 if (b_info.reserved) {
4958 vsize -= (SHARED_TEXT_REGION_SIZE + SHARED_DATA_REGION_SIZE);
4965 if (info.share_mode != SM_PRIVATE) {
4969 switch (info.share_mode) {
4971 if (info.ref_count == 1) {
4974 vprvt += info.private_pages_resident * getpagesize();
4994#if defined(R__LINUX)
4998static void GetLinuxSysInfo(
SysInfo_t *sysinfo)
5001 FILE *
f = fopen(
"/proc/cpuinfo",
"r");
5004 if (
s.BeginsWith(
"model name")) {
5008 if (
s.BeginsWith(
"cpu MHz")) {
5012 if (
s.BeginsWith(
"cache size")) {
5016 if (
s.BeginsWith(
"processor")) {
5018 sysinfo->
fCpus =
s.Atoi();
5025 f = fopen(
"/proc/meminfo",
"r");
5028 if (
s.BeginsWith(
"MemTotal")) {
5041 s.Tokenize(sysinfo->
fOS, from);
5050static void ReadLinuxCpu(
long *ticks)
5052 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
5055 FILE *
f = fopen(
"/proc/stat",
"r");
5059 sscanf(
s.Data(),
"%*s %ld %ld %ld %ld", &ticks[0], &ticks[3], &ticks[1], &ticks[2]);
5069 Double_t avg[3] = { -1., -1., -1. };
5071 if (getloadavg(avg,
sizeof(avg)) < 0) {
5072 ::Error(
"TUnixSystem::GetLinuxCpuInfo",
"getloadavg failed");
5081 Long_t cpu_ticks1[4], cpu_ticks2[4];
5082 ReadLinuxCpu(cpu_ticks1);
5084 ReadLinuxCpu(cpu_ticks2);
5086 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
5087 (cpu_ticks1[0] + cpu_ticks1[3]);
5088 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
5089 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
5090 if (userticks < 0) userticks = 0;
5091 if (systicks < 0) systicks = 0;
5092 if (idleticks < 0) idleticks = 0;
5093 Long_t totalticks = userticks + systicks + idleticks;
5105static void GetLinuxMemInfo(
MemInfo_t *meminfo)
5108 FILE *
f = fopen(
"/proc/meminfo",
"r");
5111 if (
s.BeginsWith(
"MemTotal")) {
5115 if (
s.BeginsWith(
"MemFree")) {
5119 if (
s.BeginsWith(
"SwapTotal")) {
5123 if (
s.BeginsWith(
"SwapFree")) {
5137static void GetLinuxProcInfo(
ProcInfo_t *procinfo)
5140 if (getrusage(RUSAGE_SELF, &ru) < 0) {
5141 ::SysError(
"TUnixSystem::GetLinuxProcInfo",
"getrusage failed");
5144 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
5146 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
5157 sscanf(
s.Data(),
"%ld %ld", &
total, &rss);
5171 if (!info)
return -1;
5175 if (!sysinfo.
fCpus) {
5176#if defined(R__MACOSX)
5177 GetDarwinSysInfo(&sysinfo);
5178#elif defined(R__LINUX)
5179 GetLinuxSysInfo(&sysinfo);
5195 if (!info)
return -1;
5197#if defined(R__MACOSX)
5198 GetDarwinCpuInfo(info, sampleTime);
5199#elif defined(R__LINUX)
5200 GetLinuxCpuInfo(info, sampleTime);
5212 if (!info)
return -1;
5214#if defined(R__MACOSX)
5215 GetDarwinMemInfo(info);
5216#elif defined(R__LINUX)
5217 GetLinuxMemInfo(info);
5229 if (!info)
return -1;
5231#if defined(R__MACOSX)
5232 GetDarwinProcInfo(info);
5233#elif defined(R__LINUX)
5234 GetLinuxProcInfo(info);
R__EXTERN TApplication * gApplication
void SysError(const char *location, const char *msgfmt,...)
void Break(const char *location, const char *msgfmt,...)
void Fatal(const char *location, const char *msgfmt,...)
static unsigned int total
R__EXTERN TInterpreter * gCling
Binding & operator=(OUT(*fun)(void))
char * Form(const char *fmt,...)
void Printf(const char *fmt,...)
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
typedef void((*Func_t)())
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 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()
static const char * DynamicPath(const char *newpath=0, Bool_t reset=kFALSE)
Get shared library search path. Static utility function.
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 Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
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.
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 * At(Int_t idx) const
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()
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.
virtual Bool_t Notify()
Notify when signal occurs.
ESignals GetSignal() const
Bool_t Gets(FILE *fp, Bool_t chop=kTRUE)
Read one line from the stream, including the , 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.
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
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 all 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=0)
Create helper TSystem to handle file and directory operations that might be special for remote file a...
Int_t fNfd
Signals that were trapped.
static const char * StripOffProto(const char *path, const char *proto)
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.
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
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.
TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
Int_t GetEffectiveGid()
Returns the effective group id.
const char * GetError()
Return system error string.
int GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Bool_t Init()
Initialize Unix system interface.
const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file "wfil" in a search path.
Int_t Select(TList *active, Long_t timeout)
Select on file descriptors.
static int UnixUdpConnect(const char *hostname, int port)
Creates a UDP socket connection Is called via the TSocket constructor.
int SetSockOpt(int sock, int option, int val)
Set socket option.
static const char * UnixHomedirectory(const char *user=0)
Returns the user's home directory.
void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
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 GetSysInfo(SysInfo_t *info) const
Returns static system info, like OS type, CPU type, number of CPUs RAM size, etc into the SysInfo_t s...
static const char * UnixGetdirentry(void *dir)
Returns the next directory entry.
void ListSymbols(const char *module, const char *re="")
List symbols in a shared library.
int ConnectService(const char *server, int port, int tcpwindowsize, const char *protocol="tcp")
Connect to service servicename on server servername.
void Setenv(const char *name, const char *value)
Set environment variable.
int GetFsInfo(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.
int ClosePipe(FILE *pipe)
Close the pipe.
int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
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.
std::string GetWorkingDirectory() const
Return working directory.
UserGroup_t * GetGroupInfo(Int_t gid)
Returns all group info in the UserGroup_t structure.
int Utime(const char *file, Long_t modtime, Long_t actime)
Set a files modification and access times.
int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
static void UnixSigAlarmInterruptsSyscalls(Bool_t set)
When the argument is true the SIGALRM signal handler is set so that interrupted syscalls will not be ...
void Syslog(ELogLevel level, const char *mess)
Send mess to syslog daemon.
int GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.
static int UnixUnixConnect(int port)
Connect to a Unix domain socket.
const char * WorkingDirectory()
Return working directory.
int Umask(Int_t mask)
Set the process file creation mode mask.
Int_t SetFPEMask(Int_t mask=kDefaultMask)
Set which conditions trigger a floating point exception.
int GetServiceByName(const char *service)
Get port # of internet service.
int Unlink(const char *name)
Unlink, i.e.
int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket.
virtual ~TUnixSystem()
Reset to original state.
TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to a service on a server.
void ResetSignals()
Reset signals handlers to previous behaviour.
int SendBuf(int sock, const void *buffer, int length)
Send a buffer headed by a length indicator.
static void UnixResetSignal(ESignals sig)
Restore old signal handler for specified signal.
int AnnounceUdpService(int port, int backlog)
Announce UDP service.
void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
static int UnixUdpService(int port, int backlog)
Open a socket, bind to it and start listening for UDP connections on the port.
int Rename(const char *from, const char *to)
Rename a file. Returns 0 when successful, -1 in case of failure.
Bool_t ExpandPathName(TString &patbuf)
Expand a pathname getting rid of special shell characters like ~.
TTimer * RemoveTimer(TTimer *ti)
Remove timer from list of system timers.
void Sleep(UInt_t milliSec)
Sleep milliSec milliseconds.
void Abort(int code=0)
Abort the application.
void Unsetenv(const char *name)
Unset environment variable.
int GetSockOpt(int sock, int option, int *val)
Get socket option.
const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const
Returns cpu load average and load info into the CpuInfo_t structure.
Bool_t DispatchTimers(Bool_t mode)
Handle and dispatch timers.
void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
const char * GetLinkedLibraries()
Get list of shared libraries loaded at the start of the executable.
void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
void DispatchOneEvent(Bool_t pendingOnly=kFALSE)
Dispatch a single event.
TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
int AcceptConnection(int sock)
Accept a connection.
void FreeDirectory(void *dirp)
Close a Unix file system directory.
const char * GetDirEntry(void *dirp)
Get next Unix file system directory entry. Returns 0 if no more entries.
Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
void SetDynamicPath(const char *lib)
Set the dynamic path to a new value.
const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Int_t GetEffectiveUid()
Returns the effective user id.
char * GetServiceByPort(int port)
Get name of internet service.
int RecvBuf(int sock, void *buffer, int length)
Receive a buffer headed by a length indicator.
Int_t GetFPEMask()
Return the bitmap of conditions that trigger a floating point exception.
const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE)
Returns the path of a shared library (searches for library in the shared library search path).
void CheckChilds()
Check if children have finished.
static int UnixUnixService(int port, int backlog)
Open a socket, bind to it and start listening for Unix domain connections to it.
const char * HostName()
Return the system's host name.
void SigAlarmInterruptsSyscalls(Bool_t set)
When the argument is true the SIGALRM signal handler is set so that interrupted syscalls will not be ...
std::string GetHomeDirectory(const char *userName=0) const
Return the user's home directory.
const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
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 AddTimer(TTimer *ti)
Add timer to list of system timers.
void * OpenDirectory(const char *name)
Open a Unix file system directory. Returns 0 if directory does not exist.
void AddDynamicPath(const char *lib)
Add a new directory to the dynamic path.
void ResetSignal(ESignals sig, Bool_t reset=kTRUE)
If reset is true reset the signal handler for the specified signal to the default handler,...
static int UnixSetitimer(Long_t ms)
Set interval timer to time-out in ms milliseconds.
Func_t DynFindSymbol(const char *module, const char *entry)
dynamic linking of module
static int UnixSend(int sock, const void *buf, int len, int flag)
Send exactly length bytes from buffer.
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.
int Symlink(const char *from, const char *to)
Create a symlink from file1 to file2.
void DispatchSignals(ESignals sig)
Handle and dispatch signals.
Int_t Exec(const char *shellcmd)
Execute a command.
Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
void Unload(const char *module)
Unload a shared library.
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...
FILE * TempFileName(TString &base, const char *dir=0)
Create a secure temporary file by appending a unique 6 letter string to base.
static void UnixSignal(ESignals sig, SigHandler_t h)
Set a signal handler for a signal.
int MakeDirectory(const char *name)
Make a Unix file system directory.
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Bool_t ChangeDirectory(const char *path)
Change directory. Returns kTRUE in case of success, kFALSE otherwise.
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Int_t GetGid(const char *group=0)
Returns the group's id. If group = 0, returns current user's group.
TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
const char * Getenv(const char *name)
Get environment variable.
void StackTrace()
Print a stack trace.
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.
void FillWithCwd(char *cwd) const
Fill buffer with current working directory.
static int UnixWaitchild()
Wait till child is finished.
int GetPid()
Get process id.
int AnnounceUnixService(int port, int backlog)
Announce unix domain service on path "kServerPath/<port>".
void Closelog()
Close connection to system log daemon.
int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
int Chmod(const char *file, UInt_t mode)
Set the file permission bits. Returns -1 in case or error, 0 otherwise.
void Openlog(const char *name, Int_t options, ELogFacility facility)
Open connection to system log daemon.
int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1)
Announce TCP/IP service.
void ResetTimer(TTimer *ti)
Reset a-sync timer.
static void UnixResetSignals()
Restore old signal handlers.
int Link(const char *from, const char *to)
Create a link from file1 to file2.
static void * UnixOpendir(const char *name)
Open a directory.
Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
FILE * OpenPipe(const char *shellcmd, const char *mode)
Open a pipe.
void ListLibraries(const char *regexp="")
List all loaded shared libraries.
TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
void demangle(char *_codeInfo, TString &_str)
demangle symbols
static constexpr double s
static constexpr double ms
Short_t Max(Short_t a, Short_t b)
void SetRootSys()
Set the ROOTSYS env var based on the executable location.
#define org(otri, vertexptr)
#define sym(otri1, otri2)