20#include "RConfigure.h"
52#if defined(R__SUN) || defined(R__AIX) || \
53 defined(R__LINUX) || defined(R__SOLARIS) || \
54 defined(R__FBSD) || defined(R__OBSD) || \
55 defined(R__MACOSX) || defined(R__HURD)
63#if defined(ULTRIX) || defined(R__SUN)
66#if defined(R__AIX) || defined(R__LINUX) || \
67 defined(R__FBSD) || defined(R__OBSD) || \
68 defined(R__LYNXOS) || defined(R__MACOSX) || defined(R__HURD)
69# include <sys/ioctl.h>
71#if defined(R__AIX) || defined(R__SOLARIS)
72# include <sys/select.h>
75# include <mach-o/dyld.h>
76# include <sys/mount.h>
77 extern "C" int statfs(
const char *
file,
struct statfs *buffer);
78#elif defined(R__LINUX) || defined(R__HURD)
80#elif defined(R__FBSD) || defined(R__OBSD)
81# include <sys/param.h>
82# include <sys/mount.h>
84# include <sys/statfs.h>
96#include <sys/resource.h>
101#include <sys/socket.h>
102#include <netinet/in.h>
103#include <netinet/tcp.h>
105# define _XOPEN_EXTENDED_SOURCE
106# include <arpa/inet.h>
107# undef _XOPEN_EXTENDED_SOURCE
108# if !defined(_AIX41) && !defined(_AIX43)
110# define HASNOT_INETATON
113# include <arpa/inet.h>
118#if defined(R__SOLARIS)
119# include <sys/systeminfo.h>
120# include <sys/filio.h>
121# include <sys/sockio.h>
122# define HASNOT_INETATON
124# define INADDR_NONE (UInt_t)-1
128#if defined(R__SOLARIS)
133#if defined(MAC_OS_X_VERSION_10_5)
139# include <sys/param.h>
140# if __FreeBSD_version >= 900007
145#if defined(R__AIX) || defined(R__FBSD) || \
146 defined(R__OBSD) || defined(R__LYNXOS) || \
147 (defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5))
151#if defined(R__LYNXOS)
153 extern int putenv(
const char *);
154 extern int inet_aton(
const char *,
struct in_addr *);
160#define STRUCT_UTMP struct utmpx
163#define STRUCT_UTMP struct utmp
165#if !defined(UTMP_FILE) && defined(_PATH_UTMP)
166#define UTMP_FILE _PATH_UTMP
168#if defined(UTMPX_FILE)
170#define UTMP_FILE UTMPX_FILE
173#define UTMP_FILE "/etc/utmp"
177#if (defined(R__LINUX) || defined(R__HURD)) && !defined(R__WINGCC)
178# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
179# define HAVE_BACKTRACE_SYMBOLS_FD
183#if defined(R__MACOSX)
184# define HAVE_BACKTRACE_SYMBOLS_FD
188#ifdef HAVE_BACKTRACE_SYMBOLS_FD
189# include <execinfo.h>
198#ifdef HAVE_BACKTRACE_SYMBOLS_FD
201 static const int kMAX_BACKTRACE_DEPTH = 128;
205#if (defined(R__LINUX) && !defined(R__WINGCC))
207#include <sys/prctl.h>
210#if defined(R__MACOSX) && defined(__SSE2__)
211#include <xmmintrin.h>
214#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
215 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
222#include <mach/thread_status.h>
224#define fegetenvd(x) asm volatile("mffs %0" : "=f" (x));
225#define fesetenvd(x) asm volatile("mtfsf 255,%0" : : "f" (x));
228 FE_ENABLE_INEXACT = 0x00000008,
229 FE_ENABLE_DIVBYZERO = 0x00000010,
230 FE_ENABLE_UNDERFLOW = 0x00000020,
231 FE_ENABLE_OVERFLOW = 0x00000040,
232 FE_ENABLE_INVALID = 0x00000080,
233 FE_ENABLE_ALL_EXCEPT = 0x000000F8
237#if defined(R__MACOSX) && !defined(__SSE2__) && \
238 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
250 template<
typename U = T,
typename std::enable_if<std::is_member_po
inter<decltype(&U::ut_name)>::value,
int>::type = 0>
251 static char getValue(U* ue,
int) {
252 return ue->ut_name[0];
255 template<
typename U = T,
typename std::enable_if<std::is_member_po
inter<decltype(&U::ut_user)>::value,
int>::type = 0>
256 static char getValue(U* ue,
long) {
257 return ue->ut_user[0];
263 return ut_name<STRUCT_UTMP>::getValue(ue, 0);
282 if (get_ut_name(ue) && !strncmp(tty, ue->ut_line,
sizeof(ue->ut_line)))
294 struct stat file_stats;
305 if (fstat(fileno(utmp), &file_stats) == -1) {
309 size = file_stats.st_size;
323 if (fclose(utmp) != EOF && n_read ==
size) {
342# define HOWMANY(x, y) (((x)+((y)-1))/(y))
402 TTHREAD_TLS_DECL(
TString,exepath);
404#if defined(R__MACOSX)
405 exepath = _dyld_get_image_name(0);
406#elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__FBSD)
411 int ret = readlink(
"/proc/self/exe", buf,
kMAXPATHLEN);
412#elif defined(R__SOLARIS)
413 int ret = readlink(
"/proc/self/path/a.out", buf,
kMAXPATHLEN);
414#elif defined(R__FBSD)
415 int ret = readlink(
"/proc/curproc/file", buf,
kMAXPATHLEN);
443#if defined(HAVE_DLADDR) && !defined(R__MACOSX)
453 if (dladdr(addr, &info) && info.dli_fname && info.dli_fname[0]) {
455 if (!realpath(info.dli_fname, respath)) {
457 ::SysError(
"TUnixSystem::SetRootSys",
"error getting realpath of libCore, please set ROOTSYS in the shell");
469#if defined(R__MACOSX)
474static void DylibAdded(
const struct mach_header *mh, intptr_t )
483 gLinkedDylibs = linkedDylibs;
487 TString lib = _dyld_get_image_name(i++);
489 TRegexp sovers =
"libCore\\.[0-9]+\\.*[0-9]*\\.*[0-9]*\\.so";
490 TRegexp dyvers =
"libCore\\.[0-9]+\\.*[0-9]*\\.*[0-9]*\\.dylib";
498 if (!realpath(lib, respath)) {
500 ::SysError(
"TUnixSystem::DylibAdded",
"error getting realpath of libCore, please set ROOTSYS in the shell");
514 if (lib.
EndsWith(
"/libSystem.B.dylib")) {
516 if (linkedDylibs.
IsNull()) {
526 sovers =
"\\.[0-9]+\\.*[0-9]*\\.so";
532 dyvers =
"\\.[0-9]+\\.*[0-9]*\\.dylib";
533 idx = lib.
Index(dyvers);
539 if (linkedDylibs.
Length())
595#if defined(R__MACOSX)
598 _dyld_register_func_for_add_image(DylibAdded);
599#elif defined(HAVE_DLADDR)
642 char *tty = ::ttyname(0);
651 if (utmp_entry->ut_host[0]) {
653 for (
unsigned n = 0; (
n <
sizeof(utmp_entry->ut_host)) && utmp_entry->ut_host[
n];
n++)
654 disp.
Append(utmp_entry->ut_host[
n]);
658 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s", disp.
Data());
661 else if (utmp_entry->ut_addr) {
663 struct sockaddr_in addr;
664 addr.sin_family = AF_INET;
666 memcpy(&addr.sin_addr, &utmp_entry->ut_addr,
sizeof(addr.sin_addr));
667 memset(&addr.sin_zero[0], 0,
sizeof(addr.sin_zero));
668 struct sockaddr *sa = (
struct sockaddr *) &addr;
670 char hbuf[NI_MAXHOST + 4];
671 if (getnameinfo(sa,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, NI_NAMEREQD) == 0) {
672 assert( strlen(hbuf) < NI_MAXHOST );
673 strlcat(hbuf,
":0.0",
sizeof(hbuf));
675 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
683 if (!
gROOT->IsBatch() && !getenv(
"DISPLAY")) {
684 Error(
"SetDisplay",
"Can't figure out DISPLAY, set it manually\n"
685 "In case you run a remote ssh session, restart your ssh session with:\n"
686 "=========> ssh -Y");
701#if defined(R__SOLARIS) || defined (R__LINUX) || defined(R__AIX) || \
702 defined(R__FBSD) || defined(R__OBSD) || defined(R__HURD)
703 return strerror(err);
705 if (err < 0 || err >= sys_nerr)
706 return Form(
"errno out of range %d", err);
707 return sys_errlist[err];
718#if defined(R__SOLARIS)
719 sysinfo(SI_HOSTNAME, hn,
sizeof(hn));
721 gethostname(hn,
sizeof(hn));
741 if (
h->HasReadInterest()) {
745 if (
h->HasWriteInterest()) {
758 if (!
h)
return nullptr;
771 int fd = th->
GetFd();
803 if (!
h)
return nullptr;
872#if defined(R__LINUX) && !defined(__powerpc__)
873#if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
875#if __GLIBC_MINOR__>=3
877 Int_t oldmask = fegetexcept();
884 Int_t oldmask = ~oldenv;
886 Int_t oldmask = ~oldenv.__control_word;
890 if (oldmask & FE_INVALID ) mask |=
kInvalid;
891 if (oldmask & FE_DIVBYZERO) mask |=
kDivByZero;
892 if (oldmask & FE_OVERFLOW ) mask |=
kOverflow;
893 if (oldmask & FE_UNDERFLOW) mask |=
kUnderflow;
895 if (oldmask & FE_INEXACT ) mask |=
kInexact;
900#if defined(R__MACOSX) && defined(__SSE2__)
902 Int_t oldmask = ~_MM_GET_EXCEPTION_MASK();
904 if (oldmask & _MM_MASK_INVALID ) mask |=
kInvalid;
905 if (oldmask & _MM_MASK_DIV_ZERO ) mask |=
kDivByZero;
906 if (oldmask & _MM_MASK_OVERFLOW ) mask |=
kOverflow;
907 if (oldmask & _MM_MASK_UNDERFLOW) mask |=
kUnderflow;
908 if (oldmask & _MM_MASK_INEXACT ) mask |=
kInexact;
911#if defined(R__MACOSX) && !defined(__SSE2__) && \
912 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
917 Int_t oldmask = ~oldenv.__fpscr;
918#elif defined(__arm64__)
919 Int_t oldmask = ~oldenv.__fpcr;
921 Int_t oldmask = ~oldenv.__control;
924 if (oldmask & FE_INVALID ) mask |=
kInvalid;
925 if (oldmask & FE_DIVBYZERO) mask |=
kDivByZero;
926 if (oldmask & FE_OVERFLOW ) mask |=
kOverflow;
927 if (oldmask & FE_UNDERFLOW) mask |=
kUnderflow;
928 if (oldmask & FE_INEXACT ) mask |=
kInexact;
931#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
932 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
937 if (oldmask & FE_ENABLE_INVALID ) mask |=
kInvalid;
938 if (oldmask & FE_ENABLE_DIVBYZERO) mask |=
kDivByZero;
939 if (oldmask & FE_ENABLE_OVERFLOW ) mask |=
kOverflow;
940 if (oldmask & FE_ENABLE_UNDERFLOW) mask |=
kUnderflow;
941 if (oldmask & FE_ENABLE_INEXACT ) mask |=
kInexact;
957#if defined(R__LINUX) && !defined(__powerpc__)
958#if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
960 if (mask &
kInvalid ) newm |= FE_INVALID;
962 if (mask &
kOverflow ) newm |= FE_OVERFLOW;
965 if (mask &
kInexact ) newm |= FE_INEXACT;
968#if __GLIBC_MINOR__>=3
971 feclearexcept(FE_ALL_EXCEPT);
972 fedisableexcept(FE_ALL_EXCEPT);
973 feenableexcept(newm);
982 cur.__control_word &= ~newm;
990#if defined(R__MACOSX) && defined(__SSE2__)
993 if (mask &
kInvalid ) newm |= _MM_MASK_INVALID;
994 if (mask &
kDivByZero) newm |= _MM_MASK_DIV_ZERO;
995 if (mask &
kOverflow ) newm |= _MM_MASK_OVERFLOW;
996 if (mask &
kUnderflow) newm |= _MM_MASK_UNDERFLOW;
997 if (mask &
kInexact ) newm |= _MM_MASK_INEXACT;
999 _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~newm);
1002#if defined(R__MACOSX) && !defined(__SSE2__) && \
1003 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
1005 if (mask &
kInvalid ) newm |= FE_INVALID;
1007 if (mask &
kOverflow ) newm |= FE_OVERFLOW;
1009 if (mask &
kInexact ) newm |= FE_INEXACT;
1014 cur.__fpscr &= ~newm;
1015#elif defined(__arm64__)
1016 cur.__fpcr &= ~newm;
1018 cur.__control &= ~newm;
1023#if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
1024 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
1027 if (mask &
kInvalid ) newm |= FE_ENABLE_INVALID;
1028 if (mask &
kDivByZero) newm |= FE_ENABLE_DIVBYZERO;
1029 if (mask &
kOverflow ) newm |= FE_ENABLE_OVERFLOW;
1030 if (mask &
kUnderflow) newm |= FE_ENABLE_UNDERFLOW;
1031 if (mask &
kInexact ) newm |= FE_ENABLE_INEXACT;
1035 curmask = (curmask & ~FE_ENABLE_ALL_EXCEPT) | newm;
1047 Bool_t pollOnce = pendingOnly;
1056 if (!pendingOnly)
return;
1062 if (!pendingOnly)
return;
1067 if (pendingOnly && !pollOnce)
1073 if (!pendingOnly)
return;
1104 if (mxfd == 0 && nextto == -1)
1111 for (fd = 0; fd < mxfd; fd++) {
1115 if (rc < 0 && rc != -2) {
1116 SysError(
"DispatchOneEvent",
"select: read error on %d", fd);
1122 if (rc < 0 && rc != -2) {
1123 SysError(
"DispatchOneEvent",
"select: write error on %d", fd);
1140 tv.tv_sec = milliSec / 1000;
1141 tv.tv_usec = (milliSec % 1000) * 1000;
1143 select(0, 0, 0, 0, &tv);
1165 if (
h->HasReadInterest()) {
1169 if (
h->HasWriteInterest()) {
1173 h->ResetReadyMask();
1212 if (
h->HasReadInterest())
1214 if (
h->HasWriteInterest())
1216 h->ResetReadyMask();
1246 if (sync == sh->
IsSync()) {
1248 if ((
fSignals->
IsSet(sig) && sigdone == -1) || sigdone == sig) {
1249 if (sigdone == -1) {
1274 TIter next(zombieHandler);
1275 register UnixPtty *pty;
1276 while ((pty = (UnixPtty*) next()))
1277 if (pty->GetPid() == pid) {
1278 zombieHandler->RemovePtr(pty);
1297 if ((fd <= fMaxrfd && fReadready->IsSet(fd) && fddone == -1) ||
1298 (fddone == fd && read)) {
1308 if ((fd <= fMaxwfd && fWriteready->IsSet(fd) && fddone == -1) ||
1309 (fddone == fd && !read)) {
1365 ::closedir((DIR*)dirp);
1419 return std::string(cwd);
1428 Error(
"WorkingDirectory",
"getcwd() failed");
1447 if (res)
return std::string(res);
1448 else return std::string();
1480 char *arg =
StrDup(base);
1481 int fd = mkstemp(arg);
1489 FILE *fp = fdopen(fd,
"w+");
1491 SysError(
"TempFileName",
"converting filedescriptor (%d)", fd);
1501 if (
name.IsNull() ||
name ==
".") {
1504 if (dir[strlen(dir) - 1] !=
'/')
1510 if (!dir || !dir[0])
1512 else if (dir[strlen(dir) - 1] !=
'/')
1550 FILE *from = fopen(
f,
"r");
1554 FILE *to = fopen(t,
"w");
1560 const int bufsize = 1024;
1563 while (!ret && !feof(from)) {
1564 size_t numread = fread (buf,
sizeof(
char), bufsize, from);
1565 size_t numwritten = fwrite(buf,
sizeof(
char), numread, to);
1566 if (numread != numwritten)
1581 int ret = ::rename(
f, t);
1626 return UnixFSstat(path,
id, bsize, blocks, bfree);
1635 return ::link(from, to);
1645 return ::symlink((
char*)from, (
char*)to);
1647 return ::symlink(from, to);
1661#if defined(R__SEEK64)
1662 struct stat64 finfo;
1663 if (lstat64(
name, &finfo) < 0)
1666 if (lstat(
name, &finfo) < 0)
1670 if (S_ISDIR(finfo.st_mode))
1671 return ::rmdir(
name);
1673 return ::unlink(
name);
1682 kShellEscape =
'\\',
1683 *kShellStuff =
"(){}<>\"'",
1698 const char *p, *patbuf = (
const char *)path;
1701 while (*patbuf ==
' ')
1705 for (p = patbuf; *p; p++)
1730 const char *patbuf = (
const char *)patbuf0;
1739 while (*patbuf ==
' ')
1743 for (p = patbuf; *p; p++)
1755 EscChar(patbuf, stuffedPat,
sizeof(stuffedPat), (
char*)kShellStuff, kShellEscape);
1760 if (stuffedPat[0] ==
'~') {
1761 if (stuffedPat[1] !=
'\0' && stuffedPat[1] !=
'/') {
1763 for (p = &stuffedPat[1],
q =
name; *p && *p !=
'/';)
1780 cmd += &stuffedPat[1];
1785 if ((pf = ::popen(cmd.Data(),
"r")) == 0) {
1796 for (ch = fgetc(pf); ch != EOF && ch !=
' ' && ch !=
'\n'; ch = fgetc(pf)) {
1802 if (cnt == 0 && ch == EOF)
goto again;
1808 if (ch ==
' ' || ch ==
'\t') {
1842 return ::chmod(
file, mode);
1850 return ::umask(mask);
1863 t.actime = (time_t)actime;
1864 t.modtime = (time_t)modtime;
1865 return ::utime(
file, &t);
1878 show.
Form(
"Which: %s =", wfil.
Data());
1882 if (wfil[0] ==
'/') {
1883#if defined(R__SEEK64)
1884 struct stat64 finfo;
1885 if (access(wfil.
Data(), mode) == 0 &&
1886 stat64(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1889 if (access(wfil.
Data(), mode) == 0 &&
1890 stat(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1907 for (
const char* ptr = search; *ptr;) {
1909 if (*ptr !=
'/' && *ptr !=
'$' && *ptr !=
'~')
1911 const char* posEndOfPart = strchr(ptr,
':');
1913 name.Append(ptr, posEndOfPart - ptr);
1914 ptr = posEndOfPart + 1;
1920 if (!
name.EndsWith(
"/"))
1925#if defined(R__SEEK64)
1926 struct stat64 finfo;
1927 if (access(
name.Data(), mode) == 0 &&
1928 stat64(
name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1931 if (access(
name.Data(), mode) == 0 &&
1932 stat(
name.Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1954 if (!user || !user[0])
1957 struct passwd *apwd = getpwnam(user);
2004 static UserInfoCache_t gUserInfo;
2006 UserInfoCache_t::const_iterator iUserInfo = gUserInfo.find(uid);
2007 if (iUserInfo != gUserInfo.end())
2010 struct passwd *apwd = getpwuid(uid);
2023 gUserInfo[uid] = *ug;
2048 struct group *grp = getgrgid(gid);
2078 ::setenv(
name, value, 1);
2086 return ::getenv(
name);
2104 return ::system(shellcmd);
2112 return ::popen(command, mode);
2120 return ::pclose(pipe);
2158#include <mach/mach.h>
2166 typedef CSTypeRef CSSymbolicatorRef;
2167 typedef CSTypeRef CSSourceInfoRef;
2168 typedef CSTypeRef CSSymbolOwnerRef;
2169 typedef CSTypeRef CSSymbolRef;
2171 CSSymbolicatorRef CSSymbolicatorCreateWithPid(pid_t pid);
2172 CSSymbolRef CSSymbolicatorGetSymbolWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2173 CSSourceInfoRef CSSymbolicatorGetSourceInfoWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2174 const char* CSSymbolGetName(CSSymbolRef
sym);
2175 CSSymbolOwnerRef CSSymbolGetSymbolOwner(CSSymbolRef
sym);
2176 const char* CSSymbolOwnerGetPath(CSSymbolOwnerRef symbol);
2177 const char* CSSourceInfoGetPath(CSSourceInfoRef info);
2178 int CSSourceInfoGetLineNumber(CSSourceInfoRef info);
2181bool CSTypeRefIdValid(CSTypeRef ref) {
2182 return ref.csCppData || ref.csCppObj;
2185void macosx_backtrace() {
2186void* addrlist[kMAX_BACKTRACE_DEPTH];
2188 int numstacks = backtrace( addrlist,
sizeof( addrlist ) /
sizeof(
void* ));
2190 CSSymbolicatorRef symbolicator = CSSymbolicatorCreateWithPid(getpid());
2193 static const int skipFrames = 2;
2194 for (
int i = skipFrames; i < numstacks; ++i) {
2196 CSSymbolRef
sym = CSSymbolicatorGetSymbolWithAddressAtTime(symbolicator,
2197 (vm_address_t)addrlist[i],
2199 CSSymbolOwnerRef symOwner = CSSymbolGetSymbolOwner(
sym);
2201 if (
const char* libPath = CSSymbolOwnerGetPath(symOwner)) {
2202 printf(
"[%s]", libPath);
2204 printf(
"[<unknown binary>]");
2207 if (
const char* symname = CSSymbolGetName(
sym)) {
2208 printf(
" %s", symname);
2211 CSSourceInfoRef sourceInfo
2212 = CSSymbolicatorGetSourceInfoWithAddressAtTime(symbolicator,
2213 (vm_address_t)addrlist[i],
2215 if (
const char* sourcePath = CSSourceInfoGetPath(sourceInfo)) {
2216 printf(
" %s:%d", sourcePath, (
int)CSSourceInfoGetLineNumber(sourceInfo));
2218 printf(
" (no debug info)");
2235 gdbscript = gdbscript.
Strip();
2236 if (gdbscript !=
"") {
2238 fprintf(stderr,
"Root.StacktraceScript %s does not exist\n", gdbscript.
Data());
2242 if (gdbscript ==
"") {
2243 gdbscript =
"gdb-backtrace.sh";
2246 fprintf(stderr,
"Error in <TUnixSystem::StackTrace> script %s is missing\n", gdbscript.
Data());
2253 gdbmess = gdbmess.
Strip();
2261 int fd = STDERR_FILENO;
2263 const char *message =
" Generating stack trace...\n";
2265 if (fd && message) { }
2268 Getlinem(kCleanUp, 0);
2270#if defined(USE_GDB_STACK_TRACE)
2273 fprintf(stderr,
"gdb not found, need it for stack trace\n");
2278 TString gdbmessf =
"gdb-message";
2279 if (gdbmess !=
"") {
2281 fprintf(
f,
"%s\n", gdbmess.
Data());
2289 if (gdbmess !=
"") {
2291 gdbscript += gdbmessf;
2293 gdbscript +=
" 1>&2";
2298#elif defined(R__AIX)
2299 TString script =
"procstack ";
2303#elif defined(R__SOLARIS)
2314#elif defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_DLADDR)
2322 const char *cppfilt =
"c++filt";
2323 const char *cppfiltarg =
"";
2325 const char *format1 =
" 0x%016lx in %.200s %s 0x%lx from %.200s\n";
2327 const char *format2 =
" 0x%016lx in %.200s\n";
2329 const char *format2 =
" 0x%016lx in %.200s at %.200s from %.200s\n";
2331 const char *format3 =
" 0x%016lx in %.200s from %.200s\n";
2332 const char *format4 =
" 0x%016lx in <unknown function>\n";
2334 const char *format1 =
" 0x%08lx in %.200s %s 0x%lx from %.200s\n";
2336 const char *format2 =
" 0x%08lx in %.200s\n";
2338 const char *format2 =
" 0x%08lx in %.200s at %.200s from %.200s\n";
2340 const char *format3 =
" 0x%08lx in %.200s from %.200s\n";
2341 const char *format4 =
" 0x%08lx in <unknown function>\n";
2353 while (help.
Gets(p)) {
2355 cppfiltarg =
"--format=gnu-v3";
2357 }
else if (help.
Index(
"gnu-new-abi") !=
kNPOS) {
2358 cppfiltarg =
"--format=gnu-new-abi";
2367#if (defined(R__LINUX) && !defined(R__WINGCC))
2370#ifdef PR_SET_PTRACER
2371 prctl(PR_SET_PTRACER, getpid(), 0, 0, 0);
2377 TString gdbmessf =
"gdb-message";
2378 if (gdbmess !=
"") {
2380 fprintf(
f,
"%s\n", gdbmess.
Data());
2390 if (gdbmess !=
"") {
2392 gdbscript += gdbmessf;
2394 gdbscript +=
" 1>&2";
2407 if (write(fd, message, strlen(message)) < 0)
2412 TString tmpf1 =
"gdb-backtrace";
2413 std::ofstream file1;
2419 Error(
"StackTrace",
"could not open file %s", tmpf1.
Data());
2431 void *trace[kMAX_BACKTRACE_DEPTH];
2432 int depth = backtrace(trace, kMAX_BACKTRACE_DEPTH);
2433 for (
int n = 5;
n < depth;
n++) {
2437 if (dladdr(trace[
n], &info) && info.dli_fname && info.dli_fname[0]) {
2438 const char *libname = info.dli_fname;
2439 const char *symname = (info.dli_sname && info.dli_sname[0]) ?
2440 info.dli_sname :
"<unknown>";
2443 Bool_t gte = (addr >= symaddr);
2444 ULong_t diff = (gte) ? addr - symaddr : symaddr - addr;
2445 if (addr2line && symaddr) {
2449#if defined(MAC_OS_X_VERSION_10_10)
2450 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2451#elif defined(MAC_OS_X_VERSION_10_9)
2453 snprintf(buffer,
sizeof(buffer),
"%s -d -p %d 0x%016lx", addr2line,
GetPid(), addr);
2455 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2458 ULong_t offset = (addr >= libaddr) ? addr - libaddr :
2464 if (
name.Contains(
".so") ||
name.Contains(
".sl")) noShare =
kFALSE;
2465 if (noShare) offset = addr;
2466 if (noPath)
name =
"`which " +
name +
"`";
2467 snprintf(buffer,
sizeof(buffer),
"%s -e %s 0x%016lx", addr2line,
name.Data(), offset);
2469 if (FILE *pf = ::popen(buffer,
"r")) {
2471 if (fgets(buf, 2048, pf)) {
2472 buf[strlen(buf)-1] = 0;
2473 if (strncmp(buf,
"??", 2)) {
2475 snprintf(buffer,
sizeof(buffer), format2, addr, buf);
2477 snprintf(buffer,
sizeof(buffer), format2, addr, symname, buf, libname);
2485 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2486 gte ?
"+" :
"-", diff, libname);
2489 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2490 gte ?
"+" :
"-", diff, libname);
2492 snprintf(buffer,
sizeof(buffer), format3, addr, symname, libname);
2495 snprintf(buffer,
sizeof(buffer), format4, addr);
2501 if (write(fd, buffer, ::strlen(buffer)) < 0)
2506 TString tmpf2 =
"gdb-backtrace";
2510 snprintf(buffer,
sizeof(buffer),
"%s %s < %s > %s", filter, cppfiltarg, tmpf1.
Data(), tmpf2.
Data());
2512 std::ifstream file2(tmpf2);
2516 line.ReadString(file2);
2517 if (write(fd,
line.Data(),
line.Length()) < 0)
2525 delete [] addr2line;
2528#elif defined(HAVE_EXCPT_H) && defined(HAVE_PDSC_H) && \
2529 defined(HAVE_RLD_INTERFACE_H)
2538 exc_capture_context (&context);
2539 while (!rc && context.sc_pc) {
2541 pdsc_crd *func, *base, *crd
2542 = exc_remote_lookup_function_entry(0, 0, context.sc_pc, 0, &func, &base);
2543 Elf32_Addr addr = PDSC_CRD_BEGIN_ADDRESS(base, func);
2545 const char *
name =
"<unknown function>";
2546 sprintf(buffer,
" 0x%012lx %.200s + 0x%lx\n",
2547 context.sc_pc,
name, context.sc_pc - addr);
2548 write(fd, buffer, ::strlen(buffer));
2549 rc = exc_virtual_unwind(0, &context);
2594 ::openlog(
name, options, fac);
2604 ::syslog(level,
"%s", mess);
2644 const char *tty = ttyname(STDOUT_FILENO);
2648 if ((xh->
fStdOutDup = dup(STDOUT_FILENO)) < 0) {
2656 const char *tty = ttyname(STDERR_FILENO);
2660 if ((xh->
fStdErrDup = dup(STDERR_FILENO)) < 0) {
2662 if (outdone && dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2663 Warning(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2672 const char *
m = (mode[0] ==
'a' || mode[0] ==
'w') ? mode :
"a";
2685 if (freopen(
file,
m, stdout) == 0) {
2689 if (freopen(
file,
m, stderr) == 0) {
2705 if (close(STDOUT_FILENO) != 0) {
2707 "problems closing STDOUT_FILENO (%d) before 'dup2' (errno: %d)",
2711 if (dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2712 SysError(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2718 "problems closing temporary 'out' descriptor %d (errno: %d)",
2731 if (close(STDERR_FILENO) != 0) {
2733 "problems closing STDERR_FILENO (%d) before 'dup2' (errno: %d)",
2737 if (dup2(xh->
fStdErrDup, STDERR_FILENO) < 0) {
2738 SysError(
"RedirectOutput",
"could not restore stderr (back to original redirected"
2744 "problems closing temporary 'err' descriptor %d (errno: %d)",
2789 Error(
"ListSymbols",
"not yet implemented");
2811 if (!linkedLibs.
IsNull())
2817#if !defined(R__MACOSX)
2823#if defined(R__MACOSX)
2825 linkedLibs = gLinkedDylibs;
2829 while (otool.
Gets(p)) {
2834 if (!linkedLibs.
IsNull())
2836 linkedLibs += dylib;
2844#elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__AIX)
2845#if defined(R__WINGCC )
2846 const char *cLDD=
"cygcheck";
2847 const char *cSOEXT=
".dll";
2848 size_t lenexe = strlen(exe);
2849 if (strcmp(exe + lenexe - 4,
".exe")
2850 && strcmp(exe + lenexe - 4,
".dll")) {
2853 char* longerexe =
new char[lenexe + 5];
2854 strlcpy(longerexe, exe,lenexe+5);
2855 strlcat(longerexe,
".exe",lenexe+5);
2857 #error "unsupported platform, fix memory leak to use it"
2859 TRegexp sovers =
"\\.so\\.[0-9]+";
2861 const char *cLDD=
"ldd";
2863 const char *cSOEXT=
".a";
2864 TRegexp sovers =
"\\.a\\.[0-9]+";
2866 const char *cSOEXT=
".so";
2867 TRegexp sovers =
"\\.so\\.[0-9]+";
2873 while (ldd.
Gets(p)) {
2892 if (!linkedLibs.
IsNull())
2894 linkedLibs += solib;
2939 if (mode && t->
IsSync()) {
2942 }
else if (!mode && t->
IsAsync()) {
2967 if (!ti)
return nullptr;
2996 struct addrinfo hints;
2997 struct addrinfo *result, *rp;
2998 memset(&hints, 0,
sizeof(
struct addrinfo));
2999 hints.ai_family = AF_INET;
3000 hints.ai_socktype = 0;
3001 hints.ai_protocol = 0;
3002 hints.ai_flags = AI_CANONNAME;
3007 size_t lenHostname = strlen(hostname);
3008 std::string hostnameWithoutLocal{hostname};
3009 if (lenHostname > 6 && !strcmp(hostname + lenHostname - 6,
".local")) {
3010 hostnameWithoutLocal.erase(lenHostname - 6);
3011 hostname = hostnameWithoutLocal.c_str();
3016 int rc = getaddrinfo(hostname,
nullptr, &hints, &result);
3018 if (rc == EAI_NONAME) {
3019 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host '%s'", hostname);
3022 Error(
"GetHostByName",
"getaddrinfo failed for '%s': %s", hostname, gai_strerror(rc));
3028 std::string hostcanon(result->ai_canonname ? result->ai_canonname : hostname);
3030 ia.
fFamily = result->ai_family;
3031 ia.
fAddresses[0] = ntohl(((
struct sockaddr_in *)(result->ai_addr))->sin_addr.s_addr);
3033 if (hostcanon.compare(hostname) != 0) ia.
AddAlias(hostname);
3036 char tmp[
sizeof(
struct in_addr)];
3037 if (inet_pton(AF_INET, hostcanon.data(), tmp) == 1) {
3038 char hbuf[NI_MAXHOST];
3039 if (getnameinfo(result->ai_addr, result->ai_addrlen, hbuf,
sizeof(hbuf),
nullptr, 0, 0) == 0)
3044 rp = result->ai_next;
3045 for (; rp !=
nullptr; rp = rp->ai_next) {
3046 UInt_t arp = ntohl(((
struct sockaddr_in *)(rp->ai_addr))->sin_addr.s_addr);
3051 freeaddrinfo(result);
3060 struct sockaddr addr;
3061 socklen_t len =
sizeof(addr);
3064 if (getsockname(sock, &addr, &len) == -1) {
3065 SysError(
"GetSockName",
"getsockname failed");
3069 if (addr.sa_family != AF_INET)
return ia;
3071 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3072 ia.
fPort = ntohs(addrin->sin_port);
3073 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3075 char hbuf[NI_MAXHOST];
3076 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3077 Error(
"GetSockName",
"getnameinfo failed");
3090 struct sockaddr addr;
3091 socklen_t len =
sizeof(addr);
3094 if (getpeername(sock, &addr, &len) == -1) {
3095 SysError(
"GetPeerName",
"getpeername failed");
3099 if (addr.sa_family != AF_INET)
return ia;
3101 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3102 ia.
fPort = ntohs(addrin->sin_port);
3103 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3105 char hbuf[NI_MAXHOST];
3106 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3107 Error(
"GetPeerName",
"getnameinfo failed");
3122 if ((sp = getservbyname(servicename,
kProtocolName)) == 0) {
3123 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
3127 return ntohs(sp->s_port);
3137 if ((sp = getservbyport(htons(port),
kProtocolName)) == 0) {
3140 return Form(
"%d", port);
3149 int tcpwindowsize,
const char *protocol)
3151 if (!strcmp(servername,
"unix")) {
3157 if (!strcmp(protocol,
"udp")){
3227 while ((soc = ::accept(sock, 0, 0)) == -1 &&
GetErrno() == EINTR)
3234 SysError(
"AcceptConnection",
"accept");
3247 if (sock < 0)
return;
3249#if !defined(R__AIX) || defined(_AIX41) || defined(_AIX43)
3251 ::shutdown(sock, 2);
3254 while (::close(sock) == -1 &&
GetErrno() == EINTR)
3267 if (
UnixRecv(sock, &header,
sizeof(header), 0) > 0) {
3268 int count = ntohl(header);
3270 if (count > length) {
3271 Error(
"RecvBuf",
"record header exceeds buffer size");
3273 }
else if (count > 0) {
3274 if (
UnixRecv(sock, buf, count, 0) < 0) {
3275 Error(
"RecvBuf",
"cannot receive buffer");
3290 Int_t header = htonl(length);
3292 if (
UnixSend(sock, &header,
sizeof(header), 0) < 0) {
3293 Error(
"SendBuf",
"cannot send header");
3297 if (
UnixSend(sock, buf, length, 0) < 0) {
3298 Error(
"SendBuf",
"cannot send buffer");
3338 if ((
n =
UnixRecv(sock, buf, length, flag)) <= 0) {
3340 Error(
"RecvRaw",
"cannot receive buffer");
3373 if ((
n =
UnixSend(sock, buf, length, flag)) <= 0) {
3375 Error(
"SendRaw",
"cannot send buffer");
3386 if (sock < 0)
return -1;
3390 if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == -1) {
3391 SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
3396 if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == -1) {
3397 SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
3402 if (setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == -1) {
3403 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
3408 if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == -1) {
3409 SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
3414 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == -1) {
3415 SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
3420 if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == -1) {
3421 SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
3426 if (ioctl(sock, FIONBIO, (
char*)&val) == -1) {
3427 SysError(
"SetSockOpt",
"ioctl(FIONBIO)");
3433 if (ioctl(sock, SIOCSPGRP, (
char*)&val) == -1) {
3434 SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
3438 Error(
"SetSockOpt",
"ioctl(SIOCGPGRP) not supported on cygwin/gcc");
3445 Error(
"SetSockOpt",
"illegal option (%d)", opt);
3456 if (sock < 0)
return -1;
3458 socklen_t optlen =
sizeof(*val);
3462 if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == -1) {
3463 SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
3468 if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == -1) {
3469 SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
3474 if (getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == -1) {
3475 SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
3480 if (getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == -1) {
3481 SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
3486 if (getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == -1) {
3487 SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
3492 if (getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == -1) {
3493 SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
3499 if ((flg = fcntl(sock, F_GETFL, 0)) == -1) {
3500 SysError(
"GetSockOpt",
"fcntl(F_GETFL)");
3503 *val = flg & O_NDELAY;
3506#if !defined(R__LYNXOS) && !defined(R__WINGCC)
3507 if (ioctl(sock, SIOCGPGRP, (
char*)val) == -1) {
3508 SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
3512 Error(
"GetSockOpt",
"ioctl(SIOCGPGRP) not supported on LynxOS and cygwin/gcc");
3517#if !defined(R__LYNXOS)
3518 if (ioctl(sock, SIOCATMARK, (
char*)val) == -1) {
3519 SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
3523 Error(
"GetSockOpt",
"ioctl(SIOCATMARK) not supported on LynxOS");
3528#if !defined(R__LYNXOS)
3529 if (ioctl(sock, FIONREAD, (
char*)val) == -1) {
3530 SysError(
"GetSockOpt",
"ioctl(FIONREAD)");
3534 Error(
"GetSockOpt",
"ioctl(FIONREAD) not supported on LynxOS");
3539 Error(
"GetSockOpt",
"illegal option (%d)", opt);
3560 { SIGBUS, 0, 0,
"bus error" },
3561 { SIGSEGV, 0, 0,
"segmentation violation" },
3562 { SIGSYS, 0, 0,
"bad argument to system call" },
3563 { SIGPIPE, 0, 0,
"write on a pipe with no one to read it" },
3564 { SIGILL, 0, 0,
"illegal instruction" },
3565 { SIGABRT, 0, 0,
"abort" },
3566 { SIGQUIT, 0, 0,
"quit" },
3567 { SIGINT, 0, 0,
"interrupt" },
3568 { SIGWINCH, 0, 0,
"window size change" },
3569 { SIGALRM, 0, 0,
"alarm clock" },
3570 { SIGCHLD, 0, 0,
"death of a child" },
3571 { SIGURG, 0, 0,
"urgent data arrived on an I/O channel" },
3572 { SIGFPE, 0, 0,
"floating point exception" },
3573 { SIGTERM, 0, 0,
"termination signal" },
3574 { SIGUSR1, 0, 0,
"user-defined signal 1" },
3575 { SIGUSR2, 0, 0,
"user-defined signal 2" }
3633 Break(
"TUnixSystem::DispatchSignals",
"%s: printing stacktrace",
UnixSigname(sig));
3656 struct sigaction sigact;
3663#elif defined(R__SOLARIS)
3665#elif defined(R__LYNXOS)
3674 sigemptyset(&sigact.sa_mask);
3675 sigact.sa_flags = 0;
3676#if defined(SA_RESTART)
3677 sigact.sa_flags |= SA_RESTART;
3679 if (sigaction(
gSignalMap[sig].fCode, &sigact,
3681 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3692 TTHREAD_TLS_ARRAY(
struct sigaction,
kMAXSIGNALS,oldsigact);
3694 if (ignore != ignoreSig[sig]) {
3695 ignoreSig[sig] = ignore;
3697 struct sigaction sigact;
3699 sigact.sa_handler = (
void (*)())SIG_IGN;
3700#elif defined(R__SOLARIS)
3701 sigact.sa_handler = (
void (*)(
int))SIG_IGN;
3703 sigact.sa_handler = SIG_IGN;
3705 sigemptyset(&sigact.sa_mask);
3706 sigact.sa_flags = 0;
3707 if (sigaction(
gSignalMap[sig].fCode, &sigact, &oldsigact[sig]) < 0)
3708 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3710 if (sigaction(
gSignalMap[sig].fCode, &oldsigact[sig], 0) < 0)
3711 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3727 struct sigaction sigact;
3730#elif defined(R__SOLARIS)
3732#elif defined(R__LYNXOS)
3741 sigemptyset(&sigact.sa_mask);
3742 sigact.sa_flags = 0;
3744#if defined(SA_INTERRUPT)
3745 sigact.sa_flags |= SA_INTERRUPT;
3748#if defined(SA_RESTART)
3749 sigact.sa_flags |= SA_RESTART;
3753 ::SysError(
"TUnixSystem::UnixSigAlarmInterruptsSyscalls",
"sigaction");
3773 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3796 static std::atomic<time_t> jan95{0};
3807 jan95 = mktime(&tp);
3808 if ((
int)jan95 == -1) {
3809 ::SysError(
"TUnixSystem::UnixNow",
"error converting 950001 0:00 to time_t");
3815 gettimeofday(&t, 0);
3824 struct itimerval itv;
3825 itv.it_value.tv_sec = 0;
3826 itv.it_value.tv_usec = 0;
3827 itv.it_interval.tv_sec = 0;
3828 itv.it_interval.tv_usec = 0;
3830 itv.it_value.tv_sec = time_t(ms / 1000);
3831 itv.it_value.tv_usec = time_t((ms % 1000) * 1000);
3833 int st = setitimer(ITIMER_REAL, &itv, 0);
3835 ::SysError(
"TUnixSystem::UnixSetitimer",
"setitimer");
3853 fd_set *rd = (readready) ? (fd_set*)readready->
GetBits() : 0;
3854 fd_set *wr = (writeready) ? (fd_set*)writeready->
GetBits() : 0;
3858 tv.tv_sec =
Int_t(timeout / 1000);
3859 tv.tv_usec = (timeout % 1000) * 1000;
3860 retcode = select(nfds, rd, wr, 0, &tv);
3862 retcode = select(nfds, rd, wr, 0, 0);
3864 if (retcode == -1) {
3895 pw = getpwnam(
name);
3904 pw = getpwuid(getuid());
3909 }
else if (pw && pw->
pw_dir) {
3937 if (stat(edir, &finfo) < 0)
3940 if (!S_ISDIR(finfo.st_mode))
3943 return (
void*) opendir(edir);
3946#if defined(_POSIX_SOURCE)
3949# define REAL_DIR_ENTRY(dp) 1
3951# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
3959 DIR *dirp = (DIR*)dirp1;
3991#if defined(R__SEEK64)
3993 if (path && lstat64(path, &sbuf) == 0) {
3996 if (path && lstat(path, &sbuf) == 0) {
3998 buf.
fIsLink = S_ISLNK(sbuf.st_mode);
4000#if defined(R__SEEK64)
4001 if (stat64(path, &sbuf) == -1) {
4003 if (stat(path, &sbuf) == -1) {
4008 buf.
fDev = sbuf.st_dev;
4009 buf.
fIno = sbuf.st_ino;
4010 buf.
fMode = sbuf.st_mode;
4011 buf.
fUid = sbuf.st_uid;
4012 buf.
fGid = sbuf.st_gid;
4013 buf.
fSize = sbuf.st_size;
4014 buf.
fMtime = sbuf.st_mtime;
4033 struct statfs statfsbuf;
4034#if (defined(R__SOLARIS) && !defined(R__LINUX))
4035 if (statfs(path, &statfsbuf,
sizeof(
struct statfs), 0) == 0) {
4036 *
id = statfsbuf.f_fstyp;
4037 *bsize = statfsbuf.f_bsize;
4038 *blocks = statfsbuf.f_blocks;
4039 *bfree = statfsbuf.f_bfree;
4041 if (statfs((
char*)path, &statfsbuf) == 0) {
4047 if (!strcmp(statfsbuf.f_fstypename, MOUNT_FFS) ||
4048 !strcmp(statfsbuf.f_fstypename, MOUNT_MFS))
4050 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NFS))
4052 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_MSDOS))
4054 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_EXT2FS))
4056 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_CD9660))
4058 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NCPFS))
4063 *
id = statfsbuf.f_type;
4065 *bsize = statfsbuf.f_bsize;
4066 *blocks = statfsbuf.f_blocks;
4067 *bfree = statfsbuf.f_bavail;
4080 return (
int) waitpid(0, &status, WNOHANG);
4101 sport = htons(port);
4104 if (!addr.
IsValid())
return -1;
4107 struct sockaddr_in server;
4108 memset(&server, 0,
sizeof(server));
4109 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4111 server.sin_port = sport;
4115 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4116 ::SysError(
"TUnixSystem::UnixTcpConnect",
"socket (%s:%d)",
4121 if (tcpwindowsize > 0) {
4126 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4130 ::SysError(
"TUnixSystem::UnixTcpConnect",
"connect (%s:%d)",
4152 sport = htons(port);
4155 if (!addr.
IsValid())
return -1;
4158 struct sockaddr_in server;
4159 memset(&server, 0,
sizeof(server));
4160 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4162 server.sin_port = sport;
4166 if ((sock =
socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4167 ::SysError(
"TUnixSystem::UnixUdpConnect",
"socket (%s:%d)",
4172 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4176 ::SysError(
"TUnixSystem::UnixUdpConnect",
"connect (%s:%d)",
4198 if (!sockpath || strlen(sockpath) <= 0) {
4199 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket path undefined");
4204 struct sockaddr_un unserver;
4205 unserver.sun_family = AF_UNIX;
4207 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4208 ::Error(
"TUnixSystem::UnixUnixConnect",
"socket path %s, longer than max allowed length (%u)",
4209 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4212 strlcpy(unserver.sun_path, sockpath,
sizeof(unserver.sun_path));
4215 if ((sock =
socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4216 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket");
4220 while (connect(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2) == -1) {
4224 ::SysError(
"TUnixSystem::UnixUnixConnect",
"connect");
4247 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4248 short sport, tryport = kSOCKET_MINPORT;
4251 if (port == 0 && reuse) {
4252 ::Error(
"TUnixSystem::UnixTcpService",
"cannot do a port scan while reuse is true");
4259 sport = htons(port);
4263 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4264 ::SysError(
"TUnixSystem::UnixTcpService",
"socket");
4271 if (tcpwindowsize > 0) {
4276 struct sockaddr_in inserver;
4277 memset(&inserver, 0,
sizeof(inserver));
4278 inserver.sin_family = AF_INET;
4279 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4280 inserver.sin_port = sport;
4284 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4285 ::SysError(
"TUnixSystem::UnixTcpService",
"bind");
4292 inserver.sin_port = htons(tryport);
4293 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4295 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4297 ::SysError(
"TUnixSystem::UnixTcpService",
"bind (port scan)");
4304 if (::listen(sock, backlog)) {
4305 ::SysError(
"TUnixSystem::UnixTcpService",
"listen");
4322 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4323 short sport, tryport = kSOCKET_MINPORT;
4329 sport = htons(port);
4333 if ((sock =
socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4334 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
4338 struct sockaddr_in inserver;
4339 memset(&inserver, 0,
sizeof(inserver));
4340 inserver.sin_family = AF_INET;
4341 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4342 inserver.sin_port = sport;
4346 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4347 ::SysError(
"TUnixSystem::UnixUdpService",
"bind");
4354 inserver.sin_port = htons(tryport);
4355 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4357 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4359 ::SysError(
"TUnixSystem::UnixUdpService",
"bind (port scan)");
4366 if (::listen(sock, backlog)) {
4367 ::SysError(
"TUnixSystem::UnixUdpService",
"listen");
4384 oldumask = umask(0);
4396 unlink(sockpath.
Data());
4407 if (!sockpath || strlen(sockpath) <= 0) {
4408 ::SysError(
"TUnixSystem::UnixUnixService",
"socket path undefined");
4412 struct sockaddr_un unserver;
4416 memset(&unserver, 0,
sizeof(unserver));
4417 unserver.sun_family = AF_UNIX;
4419 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4420 ::Error(
"TUnixSystem::UnixUnixService",
"socket path %s, longer than max allowed length (%u)",
4421 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4424 strlcpy(unserver.sun_path, sockpath,
sizeof(unserver.sun_path));
4427 if ((sock =
socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4428 ::SysError(
"TUnixSystem::UnixUnixService",
"socket");
4432 if (::bind(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2)) {
4433 ::SysError(
"TUnixSystem::UnixUnixService",
"bind");
4439 if (::listen(sock, backlog)) {
4440 ::SysError(
"TUnixSystem::UnixUnixService",
"listen");
4459 if (sock < 0)
return -1;
4466 if (flag == MSG_PEEK)
4470 char *buf = (
char *)buffer;
4472 for (
n = 0;
n < length;
n += nrecv) {
4473 if ((nrecv = recv(sock, buf+
n, length-
n, flag)) <= 0) {
4476 if (flag == MSG_OOB) {
4507 if (sock < 0)
return -1;
4516 const char *buf = (
const char *)buffer;
4518 for (
n = 0;
n < length;
n += nsent) {
4519 if ((nsent = send(sock, buf+
n, length-
n, flag)) <= 0) {
4557 }
else if (reset || !initialized) {
4558 initialized =
kTRUE;
4568#elif defined(R__MACOSX)
4584 if (!rdynpath.
IsNull()) {
4587 dynpath += rdynpath;
4597#if defined(R__WINGCC) || defined(R__MACOSX)
4598 if (!dynpath.
EndsWith(
":")) dynpath +=
":";
4599 dynpath +=
"/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:";
4600 dynpath +=
"/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:";
4603 std::string cmd(
"LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls 2>&1");
4604 FILE *pf = popen(cmd.c_str (),
"r");
4605 std::string result =
"";
4608 if (fgets(buffer, 128, pf) != NULL)
4612 std::size_t from = result.find(
"search path=", result.find(
"(LD_LIBRARY_PATH)"));
4613 std::size_t to = result.find(
"(system search path)");
4614 if (from != std::string::npos && to != std::string::npos) {
4616 std::string sys_path = result.substr(from, to-from);
4617 sys_path.erase(std::remove_if(sys_path.begin(), sys_path.end(), isspace), sys_path.end());
4618 if (!dynpath.
EndsWith(
":")) dynpath +=
":";
4619 dynpath += sys_path.c_str();
4623 if (
gDebug > 0) std::cout <<
"dynpath = " << dynpath.
Data() << std::endl;
4669 char buf[PATH_MAX + 1];
4670 char *res = realpath(sLib.
Data(), buf);
4671 if (res) sLib = buf;
4677 const char* lib = sLib.
Data();
4679 if (len > 3 && (!strcmp(lib+len-3,
".so") ||
4680 !strcmp(lib+len-3,
".dl") ||
4681 !strcmp(lib+len-4,
".dll") ||
4682 !strcmp(lib+len-4,
".DLL") ||
4683 !strcmp(lib+len-6,
".dylib") ||
4684 !strcmp(lib+len-3,
".sl") ||
4685 !strcmp(lib+len-2,
".a"))) {
4690 Error(
"FindDynamicLibrary",
4694 static const char* exts[] = {
4695 ".so",
".dll",
".dylib",
".sl",
".dl",
".a", 0 };
4696 const char** ext = exts;
4708 Error(
"FindDynamicLibrary",
4709 "%s[.so | .dll | .dylib | .sl | .dl | .a] does not exist in %s",
4717#if defined(R__MACOSX)
4718#include <sys/resource.h>
4719#include <mach/mach.h>
4720#include <mach/mach_error.h>
4725static void GetDarwinSysInfo(
SysInfo_t *sysinfo)
4727 FILE *p =
gSystem->
OpenPipe(
"sysctl -n kern.ostype hw.model hw.ncpu hw.cpufrequency "
4728 "hw.busfrequency hw.l2cachesize hw.memsize",
"r");
4761static void ReadDarwinCpu(
long *ticks)
4763 mach_msg_type_number_t count;
4765 host_cpu_load_info_data_t cpu;
4767 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
4769 count = HOST_CPU_LOAD_INFO_COUNT;
4770 kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpu, &count);
4771 if (kr != KERN_SUCCESS) {
4772 ::Error(
"TUnixSystem::ReadDarwinCpu",
"host_statistics: %s", mach_error_string(kr));
4774 ticks[0] = cpu.cpu_ticks[CPU_STATE_USER];
4775 ticks[1] = cpu.cpu_ticks[CPU_STATE_SYSTEM];
4776 ticks[2] = cpu.cpu_ticks[CPU_STATE_IDLE];
4777 ticks[3] = cpu.cpu_ticks[CPU_STATE_NICE];
4785static void GetDarwinCpuInfo(
CpuInfo_t *cpuinfo,
Int_t sampleTime)
4788 if (getloadavg(avg,
sizeof(avg)) < 0) {
4789 ::Error(
"TUnixSystem::GetDarwinCpuInfo",
"getloadavg failed");
4796 Long_t cpu_ticks1[4], cpu_ticks2[4];
4797 ReadDarwinCpu(cpu_ticks1);
4799 ReadDarwinCpu(cpu_ticks2);
4801 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
4802 (cpu_ticks1[0] + cpu_ticks1[3]);
4803 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
4804 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
4805 if (userticks < 0) userticks = 0;
4806 if (systicks < 0) systicks = 0;
4807 if (idleticks < 0) idleticks = 0;
4808 Long_t totalticks = userticks + systicks + idleticks;
4820static void GetDarwinMemInfo(
MemInfo_t *meminfo)
4822 static Int_t pshift = 0;
4824 vm_statistics_data_t vm_info;
4825 mach_msg_type_number_t count;
4830 count = HOST_VM_INFO_COUNT;
4831 kr = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_info, &count);
4832 if (kr != KERN_SUCCESS) {
4833 ::Error(
"TUnixSystem::GetDarwinMemInfo",
"host_statistics: %s", mach_error_string(kr));
4837 for (
int psize = getpagesize(); psize > 1; psize >>= 1)
4841 used = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.wire_count) << pshift;
4843 total = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.free_count + vm_info.wire_count) << pshift;
4846 swap_used = vm_info.pageouts << pshift;
4849 dirp = opendir(
"/private/var/vm");
4854 while ((dp = readdir(dirp)) != 0) {
4856 char fname [MAXNAMLEN];
4857 if (strncmp(dp->d_name,
"swapfile", 8))
4859 strlcpy(fname,
"/private/var/vm/",MAXNAMLEN);
4860 strlcat (fname, dp->d_name,MAXNAMLEN);
4861 if (stat(fname, &sb) < 0)
4863 swap_total += sb.st_size;
4883static void GetDarwinProcInfo(
ProcInfo_t *procinfo)
4886#define vm_region vm_region_64
4890#define GLOBAL_SHARED_TEXT_SEGMENT 0x90000000U
4891#define GLOBAL_SHARED_DATA_SEGMENT 0xA0000000U
4892#define SHARED_TEXT_REGION_SIZE 0x10000000
4893#define SHARED_DATA_REGION_SIZE 0x10000000
4896 if (getrusage(RUSAGE_SELF, &ru) < 0) {
4897 ::SysError(
"TUnixSystem::GetDarwinProcInfo",
"getrusage failed");
4900 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
4902 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
4905 task_basic_info_data_t ti;
4906 mach_msg_type_number_t count;
4909 task_t a_task = mach_task_self();
4911 count = TASK_BASIC_INFO_COUNT;
4912 kr = task_info(a_task, TASK_BASIC_INFO, (task_info_t)&ti, &count);
4913 if (kr != KERN_SUCCESS) {
4914 ::Error(
"TUnixSystem::GetDarwinProcInfo",
"task_info: %s", mach_error_string(kr));
4919 mach_port_t object_name;
4920 vm_address_t address;
4921 vm_region_top_info_data_t info;
4922 vm_size_t vprvt, rsize,
size;
4923 rsize = ti.resident_size;
4925 for (address = 0; ; address +=
size) {
4927 count = VM_REGION_TOP_INFO_COUNT;
4928 if (vm_region(a_task, &address, &
size,
4929 VM_REGION_TOP_INFO, (vm_region_info_t)&info, &count,
4930 &object_name) != KERN_SUCCESS) {
4935 if (address >= GLOBAL_SHARED_TEXT_SEGMENT &&
4936 address < (GLOBAL_SHARED_DATA_SEGMENT + SHARED_DATA_REGION_SIZE)) {
4941 if (info.share_mode == SM_EMPTY) {
4942 vm_region_basic_info_data_64_t b_info;
4943 count = VM_REGION_BASIC_INFO_COUNT_64;
4944 if (vm_region_64(a_task, &address,
4945 &
size, VM_REGION_BASIC_INFO,
4946 (vm_region_info_t)&b_info, &count,
4947 &object_name) != KERN_SUCCESS) {
4954 if (info.share_mode != SM_PRIVATE) {
4958 switch (info.share_mode) {
4960 if (info.ref_count == 1) {
4963 vprvt += info.private_pages_resident * getpagesize();
4982#if defined(R__LINUX)
4986static void GetLinuxSysInfo(
SysInfo_t *sysinfo)
4989 FILE *
f = fopen(
"/proc/cpuinfo",
"r");
5013 f = fopen(
"/proc/meminfo",
"r");
5038static void ReadLinuxCpu(
long *ticks)
5040 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
5043 FILE *
f = fopen(
"/proc/stat",
"r");
5047 sscanf(s.
Data(),
"%*s %ld %ld %ld %ld", &ticks[0], &ticks[3], &ticks[1], &ticks[2]);
5057 Double_t avg[3] = { -1., -1., -1. };
5059 if (getloadavg(avg,
sizeof(avg)) < 0) {
5060 ::Error(
"TUnixSystem::GetLinuxCpuInfo",
"getloadavg failed");
5069 Long_t cpu_ticks1[4], cpu_ticks2[4];
5070 ReadLinuxCpu(cpu_ticks1);
5072 ReadLinuxCpu(cpu_ticks2);
5074 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
5075 (cpu_ticks1[0] + cpu_ticks1[3]);
5076 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
5077 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
5078 if (userticks < 0) userticks = 0;
5079 if (systicks < 0) systicks = 0;
5080 if (idleticks < 0) idleticks = 0;
5081 Long_t totalticks = userticks + systicks + idleticks;
5093static void GetLinuxMemInfo(
MemInfo_t *meminfo)
5096 FILE *
f = fopen(
"/proc/meminfo",
"r");
5125static void GetLinuxProcInfo(
ProcInfo_t *procinfo)
5128 if (getrusage(RUSAGE_SELF, &ru) < 0) {
5129 ::SysError(
"TUnixSystem::GetLinuxProcInfo",
"getrusage failed");
5132 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
5134 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
5145 sscanf(s.
Data(),
"%ld %ld", &
total, &rss);
5159 if (!info)
return -1;
5163 if (!sysinfo.
fCpus) {
5164#if defined(R__MACOSX)
5165 GetDarwinSysInfo(&sysinfo);
5166#elif defined(R__LINUX)
5167 GetLinuxSysInfo(&sysinfo);
5183 if (!info)
return -1;
5185#if defined(R__MACOSX)
5186 GetDarwinCpuInfo(info, sampleTime);
5187#elif defined(R__LINUX)
5188 GetLinuxCpuInfo(info, sampleTime);
5200 if (!info)
return -1;
5202#if defined(R__MACOSX)
5203 GetDarwinMemInfo(info);
5204#elif defined(R__LINUX)
5205 GetLinuxMemInfo(info);
5217 if (!info)
return -1;
5219#if defined(R__MACOSX)
5220 GetDarwinProcInfo(info);
5221#elif defined(R__LINUX)
5222 GetLinuxProcInfo(info);
The file contains utilities which are foundational and could be used across the core component of ROO...
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
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
R__EXTERN TInterpreter * gCling
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
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 void HandleException(int sig)=0
ULong_t fds_bits[HOWMANY(kFDSETSIZE, kNFDBITS)]
TFdSet & operator=(const TFdSet &rhs)
TFdSet(const TFdSet &org)
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 * Next()
Return next object in the list. Returns 0 when no more objects in list.
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
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 , 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 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=nullptr)
Create helper TSystem to handle file and directory operations that might be special for remote file a...
Int_t fNfd
Signals that were trapped.
std::atomic< Bool_t > fInsideNotify
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual const char * WorkingDirectory()
Return working directory.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
virtual TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
virtual void Setenv(const char *name, const char *value)
Set environment variable.
static const char * StripOffProto(const char *path, const char *proto)
Strip off protocol string from specified path.
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
virtual int Unlink(const char *name)
Unlink, i.e.
Basic time type with millisecond precision.
Handles synchronous and a-synchronous timer events.
Bool_t CheckTimer(const TTime &now)
Check if timer timed out.
void AddTimer(TTimer *ti) override
Add timer to list of system timers.
int RecvRaw(int sock, void *buffer, int length, int flag) override
Receive exactly length bytes into buffer.
int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp") override
Open a connection to a service on a server.
int GetMemInfo(MemInfo_t *info) const override
Returns ram and swap memory usage info into the MemInfo_t structure.
Bool_t IsPathLocal(const char *path) override
Returns TRUE if the url in 'path' points to the local file system.
int Symlink(const char *from, const char *to) override
Create a symlink from file1 to file2.
const char * HomeDirectory(const char *userName=nullptr) override
Return the user's home directory.
Int_t GetGid(const char *group=nullptr) override
Returns the group's id. If group = 0, returns current user's group.
static int UnixUdpConnect(const char *hostname, int port)
Creates a UDP socket connection Is called via the TSocket constructor.
int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE) override
Copy a file.
TTimer * RemoveTimer(TTimer *ti) override
Remove timer from list of system timers.
int AnnounceUdpService(int port, int backlog) override
Announce UDP service.
int AnnounceUnixService(int port, int backlog) override
Announce unix domain service on path "kServerPath/<port>".
static int UnixTcpConnect(const char *hostname, int port, int tcpwindowsize)
Open a TCP/IP connection to server and connect to a service (i.e.
Int_t SetFPEMask(Int_t mask=kDefaultMask) override
Set which conditions trigger a floating point exception.
static const char * UnixGetdirentry(void *dir)
Returns the next directory entry.
void Setenv(const char *name, const char *value) override
Set environment variable.
int ConnectService(const char *server, int port, int tcpwindowsize, const char *protocol="tcp")
Connect to service servicename on server servername.
Bool_t ChangeDirectory(const char *path) override
Change directory. Returns kTRUE in case of success, kFALSE otherwise.
static const char * UnixHomedirectory(const char *user=nullptr)
Returns the user's home directory.
char * GetServiceByPort(int port) override
Get name of internet service.
Bool_t CheckSignals(Bool_t sync)
Check if some signals were raised and call their Notify() member.
static int UnixMakedir(const char *name)
Make a Unix file system directory.
static void UnixSigAlarmInterruptsSyscalls(Bool_t set)
When the argument is true the SIGALRM signal handler is set so that interrupted syscalls will not be ...
Int_t GetFPEMask() override
Return the bitmap of conditions that trigger a floating point exception.
static int UnixUnixConnect(int port)
Connect to a Unix domain socket.
int GetSysInfo(SysInfo_t *info) const override
Returns static system info, like OS type, CPU type, number of CPUs RAM size, etc into the SysInfo_t s...
void Exit(int code, Bool_t mode=kTRUE) override
Exit the application.
int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1) override
Announce TCP/IP service.
void AddDynamicPath(const char *lib) override
Add a new directory to the dynamic path.
void SetDynamicPath(const char *lib) override
Set the dynamic path to a new value.
int ClosePipe(FILE *pipe) override
Close the pipe.
std::string GetHomeDirectory(const char *userName=nullptr) const override
Return the user's home directory.
Int_t Select(TList *active, Long_t timeout) override
Select on file descriptors.
void Unsetenv(const char *name) override
Unset environment variable.
virtual ~TUnixSystem()
Reset to original state.
void Abort(int code=0) override
Abort the application.
void Syslog(ELogLevel level, const char *mess) override
Send mess to syslog daemon.
UserGroup_t * GetGroupInfo(Int_t gid) override
Returns all group info in the UserGroup_t structure.
Int_t GetUid(const char *user=nullptr) override
Returns the user's id. If user = 0, returns current user's id.
Bool_t ExpandPathName(TString &patbuf) override
Expand a pathname getting rid of special shell characters like ~.
void Openlog(const char *name, Int_t options, ELogFacility facility) override
Open connection to system log daemon.
int AcceptConnection(int sock) override
Accept a connection.
TTime Now() override
Get current time in milliseconds since 0:00 Jan 1 1995.
static void UnixResetSignal(ESignals sig)
Restore old signal handler for specified signal.
int GetServiceByName(const char *service) override
Get port # of internet service.
const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists) override
Find location of file "wfil" in a search path.
void SigAlarmInterruptsSyscalls(Bool_t set) override
When the argument is true the SIGALRM signal handler is set so that interrupted syscalls will not be ...
static int UnixUdpService(int port, int backlog)
Open a socket, bind to it and start listening for UDP connections on the port.
int Utime(const char *file, Long_t modtime, Long_t actime) override
Set a files modification and access times.
const char * GetLinkedLibraries() override
Get list of shared libraries loaded at the start of the executable.
FILE * TempFileName(TString &base, const char *dir=nullptr) override
Create a secure temporary file by appending a unique 6 letter string to base.
const char * GetError() override
Return system error string.
std::string GetWorkingDirectory() const override
Return working directory.
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists) override
Returns FALSE if one can access a file using the specified access mode.
void DispatchOneEvent(Bool_t pendingOnly=kFALSE) override
Dispatch a single event.
int Chmod(const char *file, UInt_t mode) override
Set the file permission bits. Returns -1 in case or error, 0 otherwise.
const char * PrependPathName(const char *dir, TString &name) override
Concatenate a directory and a file name.
Bool_t DispatchTimers(Bool_t mode)
Handle and dispatch timers.
void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE) override
If ignore is true ignore the specified signal, else restore previous behaviour.
void ListSymbols(const char *module, const char *re="") override
List symbols in a shared library.
int Load(const char *module, const char *entry="", Bool_t system=kFALSE) override
Load a shared library.
void StackTrace() override
Print a stack trace.
TInetAddress GetHostByName(const char *server) override
Get Internet Protocol (IP) address of host.
int SendBuf(int sock, const void *buffer, int length) override
Send a buffer headed by a length indicator.
const char * HostName() override
Return the system's host name.
void CheckChilds()
Check if children have finished.
int RecvBuf(int sock, void *buffer, int length) override
Receive a buffer headed by a length indicator.
static int UnixUnixService(int port, int backlog)
Open a socket, bind to it and start listening for Unix domain connections to it.
UserGroup_t * GetUserInfo(Int_t uid) override
Returns all user info in the UserGroup_t structure.
void SetDisplay() override
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
TFileHandler * RemoveFileHandler(TFileHandler *fh) override
Remove a file handler from the list of file handlers.
static const char * UnixSigname(ESignals sig)
Return the signal name associated with a signal.
static Long64_t UnixNow()
Get current time in milliseconds since 0:00 Jan 1 1995.
static int UnixFSstat(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree)
Get info about a file system: id, bsize, bfree, blocks.
void ResetSignals() override
Reset signals handlers to previous behaviour.
TInetAddress GetSockName(int sock) override
Get Internet Protocol (IP) address of host and port #.
int Link(const char *from, const char *to) override
Create a link from file1 to file2.
int GetProcInfo(ProcInfo_t *info) const override
Returns cpu and memory used by this process into the ProcInfo_t structure.
int SetSockOpt(int sock, int option, int val) override
Set socket option.
static int UnixSetitimer(Long_t ms)
Set interval timer to time-out in ms milliseconds.
static int UnixSend(int sock, const void *buf, int len, int flag)
Send exactly length bytes from buffer.
TInetAddress GetPeerName(int sock) override
Get Internet Protocol (IP) address of remote host and port #.
static void UnixIgnoreSignal(ESignals sig, Bool_t ignore)
If ignore is true ignore the specified signal, else restore previous behaviour.
static int UnixTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize)
Open a socket, bind to it and start listening for TCP/IP connections on the port.
void DispatchSignals(ESignals sig)
Handle and dispatch signals.
void AddFileHandler(TFileHandler *fh) override
Add a file handler to the list of system file handlers.
void * OpenDirectory(const char *name) override
Open a Unix file system directory. Returns 0 if directory does not exist.
int Rename(const char *from, const char *to) override
Rename a file. Returns 0 when successful, -1 in case of failure.
const char * Getenv(const char *name) override
Get environment variable.
int GetPathInfo(const char *path, FileStat_t &buf) override
Get info about a file.
Int_t GetEffectiveGid() override
Returns the effective group id.
static int UnixSelect(Int_t nfds, TFdSet *readready, TFdSet *writeready, Long_t timeout)
Wait for events on the file descriptors specified in the readready and writeready masks or for timeou...
int GetPid() override
Get process id.
Int_t Exec(const char *shellcmd) override
Execute a command.
void ResetTimer(TTimer *ti) override
Reset a-sync timer.
TSignalHandler * RemoveSignalHandler(TSignalHandler *sh) override
Remove a signal handler from list of signal handlers.
static void UnixSignal(ESignals sig, SigHandler_t h)
Set a signal handler for a signal.
void CloseConnection(int sock, Bool_t force=kFALSE) override
Close socket.
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
Bool_t Init() override
Initialize Unix system interface.
void Unload(const char *module) override
Unload a shared library.
int Umask(Int_t mask) override
Set the process file creation mode mask.
static int UnixFilestat(const char *path, FileStat_t &buf)
Get info about a file.
static int UnixRecv(int sock, void *buf, int len, int flag)
Receive exactly length bytes into buffer.
Int_t GetEffectiveUid() override
Returns the effective user id.
void FillWithCwd(char *cwd) const
Fill buffer with current working directory.
static int UnixWaitchild()
Wait till child is finished.
int Unlink(const char *name) override
Unlink, i.e.
void ListLibraries(const char *regexp="") override
List all loaded shared libraries.
void Closelog() override
Close connection to system log daemon.
Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=nullptr) override
Redirect standard output (stdout, stderr) to the specified file.
void Sleep(UInt_t milliSec) override
Sleep milliSec milliseconds.
void ResetSignal(ESignals sig, Bool_t reset=kTRUE) override
If reset is true reset the signal handler for the specified signal to the default handler,...
const char * TempDirectory() const override
Return a user configured or systemwide directory to create temporary files in.
Func_t DynFindSymbol(const char *module, const char *entry) override
dynamic linking of module
const char * GetDynamicPath() override
Return the dynamic path (used to find shared libraries).
FILE * OpenPipe(const char *shellcmd, const char *mode) override
Open a pipe.
void FreeDirectory(void *dirp) override
Close a Unix file system directory.
static void UnixResetSignals()
Restore old signal handlers.
int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const override
Returns cpu load average and load info into the CpuInfo_t structure.
void AddSignalHandler(TSignalHandler *sh) override
Add a signal handler to list of system signal handlers.
static void * UnixOpendir(const char *name)
Open a directory.
int SendRaw(int sock, const void *buffer, int length, int flag) override
Send exactly length bytes from buffer.
const char * WorkingDirectory() override
Return working directory.
int GetSockOpt(int sock, int option, int *val) override
Get socket option.
const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE) override
Returns the path of a shared library (searches for library in the shared library search path).
void SetProgname(const char *name) override
Set the application name (from command line, argv[0]) and copy it in gProgName.
const char * GetDirEntry(void *dirp) override
Get next Unix file system directory entry. Returns 0 if no more entries.
int MakeDirectory(const char *name) override
Make a Unix file system directory.
int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree) override
Get info about a file system: id, bsize, bfree, blocks.
const std::string & GetFallbackRootSys()
Short_t Max(Short_t a, Short_t b)
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 * SearchUtmpEntry(const char *tty)
STRUCT_UTMP * fUtmpContents
#define org(otri, vertexptr)
#define sym(otri1, otri2)