20 #include "RConfigure.h"
47 #include <sys/types.h>
48 #if defined(R__SUN) || defined(R__AIX) || \
49 defined(R__LINUX) || defined(R__SOLARIS) || \
50 defined(R__FBSD) || defined(R__OBSD) || \
51 defined(R__MACOSX) || defined(R__HURD)
59 #if defined(ULTRIX) || defined(R__SUN)
62 #if defined(R__AIX) || defined(R__LINUX) || \
63 defined(R__FBSD) || defined(R__OBSD) || \
64 defined(R__LYNXOS) || defined(R__MACOSX) || defined(R__HURD)
65 # include <sys/ioctl.h>
67 #if defined(R__AIX) || defined(R__SOLARIS)
68 # include <sys/select.h>
70 #if defined(R__LINUX) || defined(R__HURD)
72 # define SIGSYS SIGUNUSED // SIGSYS does not exist in linux ??
75 #if defined(R__MACOSX)
76 # include <mach-o/dyld.h>
77 # include <sys/mount.h>
78 extern "C" int statfs(
const char *
file,
struct statfs *
buffer);
79 #elif defined(R__LINUX) || defined(R__HURD)
81 #elif defined(R__FBSD) || defined(R__OBSD)
82 # include <sys/param.h>
83 # include <sys/mount.h>
85 # include <sys/statfs.h>
93 #include <sys/param.h>
97 #include <sys/resource.h>
100 #include <sys/time.h>
101 #include <sys/file.h>
102 #include <sys/socket.h>
103 #include <netinet/in.h>
104 #include <netinet/tcp.h>
106 # define _XOPEN_EXTENDED_SOURCE
107 # include <arpa/inet.h>
108 # undef _XOPEN_EXTENDED_SOURCE
109 # if !defined(_AIX41) && !defined(_AIX43)
111 # define HASNOT_INETATON
114 # include <arpa/inet.h>
119 #if defined(R__SOLARIS)
120 # include <sys/systeminfo.h>
121 # include <sys/filio.h>
122 # include <sys/sockio.h>
123 # define HASNOT_INETATON
125 # define INADDR_NONE (UInt_t)-1
129 #if defined(R__SOLARIS)
130 # define HAVE_UTMPX_H
131 # define UTMP_NO_ADDR
134 #if defined(MAC_OS_X_VERSION_10_5)
135 # define HAVE_UTMPX_H
136 # define UTMP_NO_ADDR
140 # include <sys/param.h>
141 # if __FreeBSD_version >= 900007
142 # define HAVE_UTMPX_H
146 #if defined(R__AIX) || defined(R__FBSD) || \
147 defined(R__OBSD) || defined(R__LYNXOS) || \
148 (defined(R__MACOSX) && !defined(MAC_OS_X_VERSION_10_5))
149 # define UTMP_NO_ADDR
152 #if (defined(R__AIX) && !defined(_AIX43)) || \
153 (defined(R__SUNGCC3) && !defined(__arch64__))
155 #elif defined(R__GLIBC) || defined(R__FBSD) || \
156 (defined(R__SUNGCC3) && defined(__arch64__)) || \
157 defined(R__OBSD) || defined(MAC_OS_X_VERSION_10_4) || \
158 (defined(R__AIX) && defined(_AIX43)) || \
159 (defined(R__SOLARIS) && defined(_SOCKLEN_T))
160 # define USE_SOCKLEN_T
163 #if defined(R__LYNXOS)
165 extern int putenv(
const char *);
166 extern int inet_aton(
const char *,
struct in_addr *);
172 #define STRUCT_UTMP struct utmpx
175 #define STRUCT_UTMP struct utmp
177 #if !defined(UTMP_FILE) && defined(_PATH_UTMP) // 4.4BSD
178 #define UTMP_FILE _PATH_UTMP
180 #if defined(UTMPX_FILE) // Solaris, SysVr4
182 #define UTMP_FILE UTMPX_FILE
185 #define UTMP_FILE "/etc/utmp"
189 #if (defined(R__LINUX) || defined(R__HURD)) && !defined(R__WINGCC)
190 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1
191 # define HAVE_BACKTRACE_SYMBOLS_FD
195 #if defined(R__MACOSX)
196 # if defined(MAC_OS_X_VERSION_10_5)
197 # define HAVE_BACKTRACE_SYMBOLS_FD
200 # define USE_GDB_STACK_TRACE
204 #ifdef HAVE_BACKTRACE_SYMBOLS_FD
205 # include <execinfo.h>
214 #ifdef HAVE_BACKTRACE_SYMBOLS_FD
217 static const int kMAX_BACKTRACE_DEPTH = 128;
221 #if (defined(R__LINUX) && !defined(R__WINGCC))
222 #include <fpu_control.h>
224 #include <sys/prctl.h>
227 #if defined(R__MACOSX) && defined(__SSE2__)
228 #include <xmmintrin.h>
231 #if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
232 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
236 #include <ucontext.h>
239 #include <mach/thread_status.h>
241 #define fegetenvd(x) asm volatile("mffs %0" : "=f" (x));
242 #define fesetenvd(x) asm volatile("mtfsf 255,%0" : : "f" (x));
245 FE_ENABLE_INEXACT = 0x00000008,
246 FE_ENABLE_DIVBYZERO = 0x00000010,
247 FE_ENABLE_UNDERFLOW = 0x00000020,
248 FE_ENABLE_OVERFLOW = 0x00000040,
249 FE_ENABLE_INVALID = 0x00000080,
250 FE_ENABLE_ALL_EXCEPT = 0x000000F8
254 #if defined(R__MACOSX) && !defined(__SSE2__) && \
255 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
268 static char getValue(U* ue,
int) {
269 return ue->ut_name[0];
273 static char getValue(U* ue,
long) {
274 return ue->ut_user[0];
280 return ut_name<STRUCT_UTMP>::getValue(ue, 0);
284 struct TUtmpContent {
288 TUtmpContent() : fUtmpContents(0), fEntries(0) {}
289 ~TUtmpContent() {
free(fUtmpContents); }
299 if (get_ut_name(ue) && !strncmp(tty, ue->ut_line,
sizeof(ue->ut_line)))
311 struct stat file_stats;
322 if (fstat(fileno(utmp), &file_stats) == -1) {
326 size = file_stats.st_size;
333 if (!fUtmpContents) {
338 n_read = fread(fUtmpContents, 1, size, utmp);
340 if (fclose(utmp) != EOF && n_read == size) {
354 const char *kServerPath =
"/tmp";
355 const char *kProtocolName =
"tcp";
359 # define HOWMANY(x, y) (((x)+((y)-1))/(y))
364 const Int_t kFDSETSIZE = FD_SETSIZE;
374 TFdSet() { memset(fds_bits, 0,
sizeof(fds_bits)); }
375 TFdSet(
const TFdSet &
org) { memcpy(fds_bits, org.fds_bits,
sizeof(org.fds_bits)); }
376 TFdSet &
operator=(
const TFdSet &rhs) {
if (
this != &rhs) { memcpy(fds_bits, rhs.fds_bits,
sizeof(rhs.fds_bits));}
return *
this; }
377 void Zero() { memset(fds_bits, 0,
sizeof(fds_bits)); }
380 if (n >= 0 && n < kFDSETSIZE) {
383 ::Fatal(
"TFdSet::Set",
"fd (%d) out of range [0..%d]", n, kFDSETSIZE-1);
388 if (n >= 0 && n < kFDSETSIZE) {
391 ::Fatal(
"TFdSet::Clr",
"fd (%d) out of range [0..%d]", n, kFDSETSIZE-1);
396 if (n >= 0 && n < kFDSETSIZE) {
397 return (fds_bits[n/kNFDBITS] & (1UL << (n % kNFDBITS))) != 0;
399 ::Fatal(
"TFdSet::IsSet",
"fd (%d) out of range [0..%d]", n, kFDSETSIZE-1);
419 TTHREAD_TLS_DECL(
TString,exepath);
421 #if defined(R__MACOSX)
422 exepath = _dyld_get_image_name(0);
423 #elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__FBSD)
427 #if defined(R__LINUX)
428 int ret = readlink(
"/proc/self/exe", buf,
kMAXPATHLEN);
429 #elif defined(R__SOLARIS)
430 int ret = readlink(
"/proc/self/path/a.out", buf,
kMAXPATHLEN);
431 #elif defined(R__FBSD)
432 int ret = readlink(
"/proc/curproc/file", buf,
kMAXPATHLEN);
460 #if defined(HAVE_DLADDR) && !defined(R__MACOSX)
463 static void SetRootSys()
466 void *addr = (
void *)SetRootSys;
468 if (dladdr(addr, &info) && info.dli_fname && info.dli_fname[0]) {
470 if (!realpath(info.dli_fname, respath)) {
472 ::
SysError(
"TUnixSystem::SetRootSys",
"error getting realpath of libCore, please set ROOTSYS in the shell");
484 #if defined(R__MACOSX)
489 static void DylibAdded(
const struct mach_header *mh, intptr_t )
498 gLinkedDylibs = linkedDylibs;
502 TString lib = _dyld_get_image_name(i++);
504 TRegexp sovers =
"libCore\\.[0-9]+\\.*[0-9]*\\.so";
505 TRegexp dyvers =
"libCore\\.[0-9]+\\.*[0-9]*\\.dylib";
508 #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
512 if (!realpath(lib, respath)) {
524 if (!realpath(lib, respath)) {
526 ::
SysError(
"TUnixSystem::DylibAdded",
"error getting realpath of libCore, please set ROOTSYS in the shell");
539 if (lib.
EndsWith(
"/libSystem.B.dylib"))
544 sovers =
"\\.[0-9]+\\.*[0-9]*\\.so";
550 dyvers =
"\\.[0-9]+\\.*[0-9]*\\.dylib";
551 idx = lib.
Index(dyvers);
557 if (linkedDylibs.
Length())
612 #if defined(R__MACOSX)
615 _dyld_register_func_for_add_image(DylibAdded);
616 #elif defined(HAVE_DLADDR)
646 if (!name || !*name) {
664 char *tty = ::ttyname(0);
671 STRUCT_UTMP *utmp_entry = utmp.SearchUtmpEntry(tty);
673 if (utmp_entry->ut_host[0]) {
674 if (strchr(utmp_entry->ut_host,
':')) {
675 Setenv(
"DISPLAY", utmp_entry->ut_host);
676 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
677 utmp_entry->ut_host);
680 snprintf(disp,
sizeof(disp),
"%s:0.0", utmp_entry->ut_host);
682 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
687 else if (utmp_entry->ut_addr) {
689 if ((he = gethostbyaddr((
const char*)&utmp_entry->ut_addr,
690 sizeof(utmp_entry->ut_addr), AF_INET))) {
692 snprintf(disp,
sizeof(disp),
"%s:0.0", he->h_name);
694 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
713 #if defined(R__SOLARIS) || defined (R__LINUX) || defined(R__AIX) || \
714 defined(R__FBSD) || defined(R__OBSD) || defined(R__HURD)
715 return strerror(err);
717 if (err < 0 || err >= sys_nerr)
718 return Form(
"errno out of range %d", err);
719 return sys_errlist[err];
730 #if defined(R__SOLARIS)
731 sysinfo(SI_HOSTNAME, hn,
sizeof(hn));
733 gethostname(hn,
sizeof(hn));
783 int fd = th->
GetFd();
884 #if defined(R__LINUX) && !defined(__powerpc__)
885 #if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
887 #if __GLIBC_MINOR__>=3
889 Int_t oldmask = fegetexcept();
896 Int_t oldmask = ~oldenv;
898 Int_t oldmask = ~oldenv.__control_word;
902 if (oldmask & FE_INVALID ) mask |=
kInvalid;
903 if (oldmask & FE_DIVBYZERO) mask |=
kDivByZero;
904 if (oldmask & FE_OVERFLOW ) mask |=
kOverflow;
905 if (oldmask & FE_UNDERFLOW) mask |=
kUnderflow;
907 if (oldmask & FE_INEXACT ) mask |=
kInexact;
912 #if defined(R__MACOSX) && defined(__SSE2__)
914 Int_t oldmask = ~_MM_GET_EXCEPTION_MASK();
916 if (oldmask & _MM_MASK_INVALID ) mask |=
kInvalid;
917 if (oldmask & _MM_MASK_DIV_ZERO ) mask |=
kDivByZero;
918 if (oldmask & _MM_MASK_OVERFLOW ) mask |=
kOverflow;
919 if (oldmask & _MM_MASK_UNDERFLOW) mask |=
kUnderflow;
920 if (oldmask & _MM_MASK_INEXACT ) mask |=
kInexact;
923 #if defined(R__MACOSX) && !defined(__SSE2__) && \
924 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
929 Int_t oldmask = ~oldenv.__fpscr;
930 #elif defined(__arm64__)
931 Int_t oldmask = ~oldenv.__fpcr;
933 Int_t oldmask = ~oldenv.__control;
936 if (oldmask & FE_INVALID ) mask |=
kInvalid;
937 if (oldmask & FE_DIVBYZERO) mask |=
kDivByZero;
938 if (oldmask & FE_OVERFLOW ) mask |=
kOverflow;
939 if (oldmask & FE_UNDERFLOW) mask |=
kUnderflow;
940 if (oldmask & FE_INEXACT ) mask |=
kInexact;
943 #if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
944 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
949 if (oldmask & FE_ENABLE_INVALID ) mask |=
kInvalid;
950 if (oldmask & FE_ENABLE_DIVBYZERO) mask |=
kDivByZero;
951 if (oldmask & FE_ENABLE_OVERFLOW ) mask |=
kOverflow;
952 if (oldmask & FE_ENABLE_UNDERFLOW) mask |=
kUnderflow;
953 if (oldmask & FE_ENABLE_INEXACT ) mask |=
kInexact;
969 #if defined(R__LINUX) && !defined(__powerpc__)
970 #if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1)
972 if (mask &
kInvalid ) newm |= FE_INVALID;
974 if (mask &
kOverflow ) newm |= FE_OVERFLOW;
977 if (mask &
kInexact ) newm |= FE_INEXACT;
980 #if __GLIBC_MINOR__>=3
983 feclearexcept(FE_ALL_EXCEPT);
984 fedisableexcept(FE_ALL_EXCEPT);
985 feenableexcept(newm);
994 cur.__control_word &= ~newm;
1002 #if defined(R__MACOSX) && defined(__SSE2__)
1005 if (mask & kInvalid ) newm |= _MM_MASK_INVALID;
1006 if (mask & kDivByZero) newm |= _MM_MASK_DIV_ZERO;
1007 if (mask & kOverflow ) newm |= _MM_MASK_OVERFLOW;
1008 if (mask & kUnderflow) newm |= _MM_MASK_UNDERFLOW;
1009 if (mask & kInexact ) newm |= _MM_MASK_INEXACT;
1011 _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~newm);
1014 #if defined(R__MACOSX) && !defined(__SSE2__) && \
1015 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__))
1017 if (mask & kInvalid ) newm |= FE_INVALID;
1018 if (mask & kDivByZero) newm |= FE_DIVBYZERO;
1019 if (mask & kOverflow ) newm |= FE_OVERFLOW;
1020 if (mask & kUnderflow) newm |= FE_UNDERFLOW;
1021 if (mask & kInexact ) newm |= FE_INEXACT;
1025 #if defined(__arm__)
1026 cur.__fpscr &= ~newm;
1027 #elif defined(__arm64__)
1028 cur.__fpcr &= ~newm;
1030 cur.__control &= ~newm;
1035 #if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \
1036 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \
1039 if (mask & kInvalid ) newm |= FE_ENABLE_INVALID;
1040 if (mask & kDivByZero) newm |= FE_ENABLE_DIVBYZERO;
1041 if (mask & kOverflow ) newm |= FE_ENABLE_OVERFLOW;
1042 if (mask & kUnderflow) newm |= FE_ENABLE_UNDERFLOW;
1043 if (mask & kInexact ) newm |= FE_ENABLE_INEXACT;
1047 curmask = (curmask & ~FE_ENABLE_ALL_EXCEPT) | newm;
1059 Bool_t pollOnce = pendingOnly;
1068 if (!pendingOnly)
return;
1074 if (!pendingOnly)
return;
1079 if (pendingOnly && !pollOnce)
1085 if (!pendingOnly)
return;
1116 if (mxfd == 0 && nextto == -1)
1123 for (fd = 0; fd < mxfd; fd++) {
1127 if (rc < 0 && rc != -2) {
1128 SysError(
"DispatchOneEvent",
"select: read error on %d", fd);
1134 if (rc < 0 && rc != -2) {
1135 SysError(
"DispatchOneEvent",
"select: write error on %d", fd);
1152 tv.tv_sec = milliSec / 1000;
1153 tv.tv_usec = (milliSec % 1000) * 1000;
1258 if (sync == sh->
IsSync()) {
1260 if ((
fSignals->IsSet(sig) && sigdone == -1) || sigdone == sig) {
1261 if (sigdone == -1) {
1287 register UnixPtty *pty;
1288 while ((pty = (UnixPtty*)
next()))
1289 if (pty->GetPid() == pid) {
1290 zombieHandler->RemovePtr(pty);
1309 if ((fd <= fMaxrfd && fReadready->IsSet(fd) && fddone == -1) ||
1310 (fddone == fd && read)) {
1320 if ((fd <= fMaxwfd && fWriteready->IsSet(fd) && fddone == -1) ||
1321 (fddone == fd && !read)) {
1377 ::closedir((DIR*)dirp);
1420 Error(
"WorkingDirectory",
"getcwd() failed");
1463 char *arg =
StrDup(base);
1464 int fd = mkstemp(arg);
1472 FILE *fp = fdopen(fd,
"w+");
1474 SysError(
"TempFileName",
"converting filedescriptor (%d)", fd);
1484 if (name.
IsNull() || name ==
".") {
1487 if (dir[strlen(dir) - 1] !=
'/')
1493 if (!dir || !dir[0]) dir =
"/";
1494 else if (dir[strlen(dir) - 1] !=
'/')
1532 FILE *from = fopen(f,
"r");
1536 FILE *to = fopen(t,
"w");
1542 const int bufsize = 1024;
1545 while (!ret && !feof(from)) {
1546 size_t numread = fread (buf,
sizeof(
char), bufsize, from);
1547 size_t numwritten = fwrite(buf,
sizeof(
char), numread, to);
1548 if (numread != numwritten)
1563 int ret = ::rename(f, t);
1608 return UnixFSstat(path,
id, bsize, blocks, bfree);
1627 return ::symlink((
char*)from, (
char*)to);
1629 return ::symlink(from, to);
1641 return helper->
Unlink(name);
1643 #if defined(R__SEEK64)
1644 struct stat64 finfo;
1645 if (lstat64(name, &finfo) < 0)
1648 if (lstat(name, &finfo) < 0)
1652 if (S_ISDIR(finfo.st_mode))
1653 return ::rmdir(name);
1655 return ::unlink(name);
1664 kShellEscape =
'\\',
1665 *kShellStuff =
"(){}<>\"'",
1670 #ifndef G__OLDEXPAND
1680 const char *p, *patbuf = (
const char *)path;
1683 while (*patbuf ==
' ')
1687 for (p = patbuf; *p; p++)
1716 const char *patbuf = (
const char *)patbuf0;
1725 while (*patbuf ==
' ')
1729 for (p = patbuf; *p; p++)
1741 EscChar(patbuf, stuffedPat,
sizeof(stuffedPat), (
char*)kShellStuff, kShellEscape);
1746 if (stuffedPat[0] ==
'~') {
1747 if (stuffedPat[1] !=
'\0' && stuffedPat[1] !=
'/') {
1749 for (p = &stuffedPat[1], q = name; *p && *p !=
'/';)
1766 cmd += &stuffedPat[1];
1771 if ((pf = ::popen(cmd.Data(),
"r")) == 0) {
1782 for (ch = fgetc(pf); ch != EOF && ch !=
' ' && ch !=
'\n'; ch = fgetc(pf)) {
1788 if (cnt == 0 && ch == EOF)
goto again;
1794 if (ch ==
' ' || ch ==
'\t') {
1828 return ::chmod(file, mode);
1836 return ::umask(mask);
1849 t.actime = (time_t)actime;
1850 t.modtime = (time_t)modtime;
1851 return ::utime(file, &t);
1864 show.
Form(
"Which: %s =", wfil.
Data());
1868 if (wfil[0] ==
'/') {
1869 #if defined(R__SEEK64)
1870 struct stat64 finfo;
1871 if (access(wfil.
Data(), mode) == 0 &&
1872 stat64(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1875 if (access(wfil.
Data(), mode) == 0 &&
1876 stat(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1893 for (
const char* ptr = search; *ptr;) {
1895 if (*ptr !=
'/' && *ptr !=
'$' && *ptr !=
'~')
1897 const char* posEndOfPart = strchr(ptr,
':');
1899 name.
Append(ptr, posEndOfPart - ptr);
1900 ptr = posEndOfPart + 1;
1911 #if defined(R__SEEK64)
1912 struct stat64 finfo;
1913 if (access(name.
Data(), mode) == 0 &&
1914 stat64(name.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1917 if (access(name.
Data(), mode) == 0 &&
1918 stat(name.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1940 if (!user || !user[0])
1943 struct passwd *apwd = getpwnam(user);
1964 if (!group || !group[0])
1967 struct group *grp = getgrnam(group);
1990 static UserInfoCache_t gUserInfo;
1992 UserInfoCache_t::const_iterator iUserInfo = gUserInfo.find(uid);
1993 if (iUserInfo != gUserInfo.end())
1996 struct passwd *apwd = getpwuid(uid);
2009 gUserInfo[uid] = *ug;
2034 struct group *grp = getgrgid(gid);
2064 ::setenv(name, value, 1);
2072 return ::getenv(name);
2090 return ::system(shellcmd);
2098 return ::popen(command, mode);
2106 return ::pclose(pipe);
2125 gROOT->EndOfProcessCleanups();
2153 gdbscript = gdbscript.
Strip();
2154 if (gdbscript !=
"") {
2156 fprintf(stderr,
"Root.StacktraceScript %s does not exist\n", gdbscript.
Data());
2162 if (gdbscript ==
"") {
2164 gdbscript.
Form(
"%s/gdb-backtrace.sh", ROOTETCDIR);
2166 gdbscript.
Form(
"%s/etc/gdb-backtrace.sh",
Getenv(
"ROOTSYS"));
2169 fprintf(stderr,
"Error in <TUnixSystem::StackTrace> script %s is missing\n", gdbscript.
Data());
2176 gdbmess = gdbmess.
Strip();
2184 int fd = STDERR_FILENO;
2186 const char *
message =
" Generating stack trace...\n";
2188 if (fd && message) { }
2191 Getlinem(kCleanUp, 0);
2193 #if defined(USE_GDB_STACK_TRACE)
2196 fprintf(stderr,
"gdb not found, need it for stack trace\n");
2201 TString gdbmessf =
"gdb-message";
2202 if (gdbmess !=
"") {
2204 fprintf(f,
"%s\n", gdbmess.
Data());
2212 if (gdbmess !=
"") {
2214 gdbscript += gdbmessf;
2216 gdbscript +=
" 1>&2";
2221 #elif defined(R__AIX)
2222 TString script =
"procstack ";
2226 #elif defined(R__SOLARIS)
2237 #elif defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_DLADDR) // linux + MacOS X >= 10.5
2245 const char *cppfilt =
"c++filt";
2246 const char *cppfiltarg =
"";
2248 const char *format1 =
" 0x%016lx in %.200s %s 0x%lx from %.200s\n";
2250 const char *format2 =
" 0x%016lx in %.200s\n";
2252 const char *format2 =
" 0x%016lx in %.200s at %.200s from %.200s\n";
2254 const char *format3 =
" 0x%016lx in %.200s from %.200s\n";
2255 const char *format4 =
" 0x%016lx in <unknown function>\n";
2257 const char *format1 =
" 0x%08lx in %.200s %s 0x%lx from %.200s\n";
2259 const char *format2 =
" 0x%08lx in %.200s\n";
2261 const char *format2 =
" 0x%08lx in %.200s at %.200s from %.200s\n";
2263 const char *format3 =
" 0x%08lx in %.200s from %.200s\n";
2264 const char *format4 =
" 0x%08lx in <unknown function>\n";
2276 while (help.
Gets(p)) {
2278 cppfiltarg =
"--format=gnu-v3";
2280 }
else if (help.
Index(
"gnu-new-abi") !=
kNPOS) {
2281 cppfiltarg =
"--format=gnu-new-abi";
2290 #if (defined(R__LINUX) && !defined(R__WINGCC))
2293 #ifdef PR_SET_PTRACER
2294 prctl(PR_SET_PTRACER, getpid(), 0, 0, 0);
2300 TString gdbmessf =
"gdb-message";
2301 if (gdbmess !=
"") {
2303 fprintf(f,
"%s\n", gdbmess.
Data());
2313 if (gdbmess !=
"") {
2315 gdbscript += gdbmessf;
2317 gdbscript +=
" 1>&2";
2330 if (
write(fd, message, strlen(message)) < 0)
2335 TString tmpf1 =
"gdb-backtrace";
2336 std::ofstream file1;
2342 Error(
"StackTrace",
"could not open file %s", tmpf1.
Data());
2354 void *trace[kMAX_BACKTRACE_DEPTH];
2355 int depth = backtrace(trace, kMAX_BACKTRACE_DEPTH);
2356 for (
int n = 5; n < depth; n++) {
2360 if (dladdr(trace[n], &info) && info.dli_fname && info.dli_fname[0]) {
2361 const char *libname = info.dli_fname;
2362 const char *symname = (info.dli_sname && info.dli_sname[0]) ?
2363 info.dli_sname :
"<unknown>";
2366 Bool_t gte = (addr >= symaddr);
2367 ULong_t diff = (gte) ? addr - symaddr : symaddr - addr;
2368 if (addr2line && symaddr) {
2372 #if defined(MAC_OS_X_VERSION_10_10)
2373 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2374 #elif defined(MAC_OS_X_VERSION_10_9)
2376 snprintf(buffer,
sizeof(buffer),
"%s -d -p %d 0x%016lx", addr2line,
GetPid(), addr);
2378 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line,
GetPid(), addr);
2386 if (name[0] !=
'/') noPath =
kTRUE;
2388 if (noShare) offset = addr;
2389 if (noPath) name =
"`which " + name +
"`";
2390 snprintf(buffer,
sizeof(buffer),
"%s -e %s 0x%016lx", addr2line, name.
Data(),
offset);
2392 if (FILE *pf = ::popen(buffer,
"r")) {
2394 if (fgets(buf, 2048, pf)) {
2395 buf[strlen(buf)-1] = 0;
2396 if (strncmp(buf,
"??", 2)) {
2398 snprintf(buffer,
sizeof(buffer), format2, addr, buf);
2400 snprintf(buffer,
sizeof(buffer), format2, addr, symname, buf, libname);
2408 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2409 gte ?
"+" :
"-", diff, libname);
2412 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2413 gte ?
"+" :
"-", diff, libname);
2415 snprintf(buffer,
sizeof(buffer), format3, addr, symname, libname);
2418 snprintf(buffer,
sizeof(buffer), format4, addr);
2424 if (
write(fd, buffer, ::strlen(buffer)) < 0)
2429 TString tmpf2 =
"gdb-backtrace";
2433 snprintf(buffer,
sizeof(buffer),
"%s %s < %s > %s", filter, cppfiltarg, tmpf1.
Data(), tmpf2.
Data());
2435 std::ifstream file2(tmpf2);
2448 delete [] addr2line;
2451 #elif defined(HAVE_EXCPT_H) && defined(HAVE_PDSC_H) && \
2452 defined(HAVE_RLD_INTERFACE_H) // tru64
2461 exc_capture_context (&context);
2462 while (!rc && context.sc_pc) {
2464 pdsc_crd *
func, *base, *crd
2465 = exc_remote_lookup_function_entry(0, 0, context.sc_pc, 0, &func, &base);
2466 Elf32_Addr addr = PDSC_CRD_BEGIN_ADDRESS(base, func);
2468 const char *name =
"<unknown function>";
2469 sprintf(buffer,
" 0x%012lx %.200s + 0x%lx\n",
2470 context.sc_pc, name, context.sc_pc - addr);
2471 write(fd, buffer, ::strlen(buffer));
2472 rc = exc_virtual_unwind(0, &context);
2514 ::openlog(name, options, fac);
2524 ::syslog(level,
"%s", mess);
2564 const char *tty = ttyname(STDOUT_FILENO);
2568 if ((xh->
fStdOutDup = dup(STDOUT_FILENO)) < 0) {
2576 const char *tty = ttyname(STDERR_FILENO);
2580 if ((xh->
fStdErrDup = dup(STDERR_FILENO)) < 0) {
2582 if (outdone && dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2583 Warning(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2592 const char *
m = (mode[0] ==
'a' || mode[0] ==
'w') ? mode :
"a";
2605 if (freopen(file, m, stdout) == 0) {
2609 if (freopen(file, m, stderr) == 0) {
2625 if (
close(STDOUT_FILENO) != 0) {
2627 "problems closing STDOUT_FILENO (%d) before 'dup2' (errno: %d)",
2631 if (dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2632 SysError(
"RedirectOutput",
"could not restore stdout (back to original redirected"
2638 "problems closing temporary 'out' descriptor %d (errno: %d)",
2651 if (
close(STDERR_FILENO) != 0) {
2653 "problems closing STDERR_FILENO (%d) before 'dup2' (errno: %d)",
2657 if (dup2(xh->
fStdErrDup, STDERR_FILENO) < 0) {
2658 SysError(
"RedirectOutput",
"could not restore stderr (back to original redirected"
2664 "problems closing temporary 'err' descriptor %d (errno: %d)",
2709 Error(
"ListSymbols",
"not yet implemented");
2731 if (!linkedLibs.
IsNull())
2737 #if !defined(R__MACOSX)
2743 #if defined(R__MACOSX)
2745 linkedLibs = gLinkedDylibs;
2749 while (otool.
Gets(p)) {
2754 if (!linkedLibs.
IsNull())
2756 linkedLibs += dylib;
2764 #elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__AIX)
2765 #if defined(R__WINGCC )
2766 const char *cLDD=
"cygcheck";
2767 const char *cSOEXT=
".dll";
2768 size_t lenexe = strlen(exe);
2769 if (strcmp(exe + lenexe - 4,
".exe")
2770 && strcmp(exe + lenexe - 4,
".dll")) {
2773 char* longerexe =
new char[lenexe + 5];
2774 strlcpy(longerexe, exe,lenexe+5);
2775 strlcat(longerexe,
".exe",lenexe+5);
2779 TRegexp sovers =
"\\.so\\.[0-9]+";
2781 const char *cLDD=
"ldd";
2783 const char *cSOEXT=
".a";
2784 TRegexp sovers =
"\\.a\\.[0-9]+";
2786 const char *cSOEXT=
".so";
2787 TRegexp sovers =
"\\.so\\.[0-9]+";
2793 while (ldd.
Gets(p)) {
2812 if (!linkedLibs.
IsNull())
2814 linkedLibs += solib;
2859 if (mode && t->
IsSync()) {
2862 }
else if (!mode && t->
IsAsync()) {
2915 struct hostent *host_ptr;
2930 #ifdef HASNOT_INETATON
2931 if ((addr = (
UInt_t)inet_addr(hostname)) != INADDR_NONE) {
2934 if (inet_aton(hostname, &ad)) {
2935 memcpy(&addr, &ad.s_addr,
sizeof(ad.s_addr));
2938 if ((host_ptr = gethostbyaddr((
const char *)&addr,
2939 sizeof(addr), AF_INET))) {
2940 host = host_ptr->h_name;
2944 for (i = 1; host_ptr->h_addr_list[i]; i++) {
2945 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
2948 for (i = 0; host_ptr->h_aliases[i]; i++)
2949 a.
AddAlias(host_ptr->h_aliases[i]);
2952 host =
"UnNamedHost";
2954 }
else if ((host_ptr = gethostbyname(hostname))) {
2956 if (host_ptr->h_addrtype != AF_INET) {
2957 Error(
"GetHostByName",
"%s is not an internet host\n", hostname);
2960 memcpy(&addr, host_ptr->h_addr, host_ptr->h_length);
2961 host = host_ptr->h_name;
2962 type = host_ptr->h_addrtype;
2966 for (i = 1; host_ptr->h_addr_list[i]; i++) {
2967 memcpy(&addr2, host_ptr->h_addr_list[i], host_ptr->h_length);
2970 for (i = 0; host_ptr->h_aliases[i]; i++)
2971 a.
AddAlias(host_ptr->h_aliases[i]);
2974 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host %s", hostname);
2986 struct sockaddr_in addr;
2987 #if defined(USE_SIZE_T)
2988 size_t len =
sizeof(addr);
2989 #elif defined(USE_SOCKLEN_T)
2990 socklen_t len =
sizeof(addr);
2992 int len =
sizeof(addr);
2995 if (getsockname(sock, (
struct sockaddr *)&addr, &len) == -1) {
2996 SysError(
"GetSockName",
"getsockname");
3000 struct hostent *host_ptr;
3001 const char *hostname;
3005 if ((host_ptr = gethostbyaddr((
const char *)&addr.sin_addr,
3006 sizeof(addr.sin_addr), AF_INET))) {
3007 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
3008 hostname = host_ptr->h_name;
3009 family = host_ptr->h_addrtype;
3011 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
3016 return TInetAddress(hostname, ntohl(iaddr), family, ntohs(addr.sin_port));
3024 struct sockaddr_in addr;
3025 #if defined(USE_SIZE_T)
3026 size_t len =
sizeof(addr);
3027 #elif defined(USE_SOCKLEN_T)
3028 socklen_t len =
sizeof(addr);
3030 int len =
sizeof(addr);
3033 if (getpeername(sock, (
struct sockaddr *)&addr, &len) == -1) {
3034 SysError(
"GetPeerName",
"getpeername");
3038 struct hostent *host_ptr;
3039 const char *hostname;
3043 if ((host_ptr = gethostbyaddr((
const char *)&addr.sin_addr,
3044 sizeof(addr.sin_addr), AF_INET))) {
3045 memcpy(&iaddr, host_ptr->h_addr, host_ptr->h_length);
3046 hostname = host_ptr->h_name;
3047 family = host_ptr->h_addrtype;
3049 memcpy(&iaddr, &addr.sin_addr,
sizeof(addr.sin_addr));
3054 return TInetAddress(hostname, ntohl(iaddr), family, ntohs(addr.sin_port));
3064 if ((sp = getservbyname(servicename, kProtocolName)) == 0) {
3065 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
3066 servicename, kProtocolName);
3069 return ntohs(sp->s_port);
3079 if ((sp = getservbyport(htons(port), kProtocolName)) == 0) {
3082 return Form(
"%d", port);
3091 int tcpwindowsize,
const char *protocol)
3093 if (!strcmp(servername,
"unix")) {
3099 if (!strcmp(protocol,
"udp")){
3169 while ((soc = ::accept(sock, 0, 0)) == -1 &&
GetErrno() == EINTR)
3176 SysError(
"AcceptConnection",
"accept");
3189 if (sock < 0)
return;
3191 #if !defined(R__AIX) || defined(_AIX41) || defined(_AIX43)
3193 ::shutdown(sock, 2);
3209 if (
UnixRecv(sock, &header,
sizeof(header), 0) > 0) {
3210 int count = ntohl(header);
3212 if (count > length) {
3213 Error(
"RecvBuf",
"record header exceeds buffer size");
3215 }
else if (count > 0) {
3216 if (
UnixRecv(sock, buf, count, 0) < 0) {
3217 Error(
"RecvBuf",
"cannot receive buffer");
3232 Int_t header = htonl(length);
3234 if (
UnixSend(sock, &header,
sizeof(header), 0) < 0) {
3235 Error(
"SendBuf",
"cannot send header");
3239 if (
UnixSend(sock, buf, length, 0) < 0) {
3240 Error(
"SendBuf",
"cannot send buffer");
3280 if ((n =
UnixRecv(sock, buf, length, flag)) <= 0) {
3281 if (n == -1 &&
GetErrno() != EINTR)
3282 Error(
"RecvRaw",
"cannot receive buffer");
3315 if ((n =
UnixSend(sock, buf, length, flag)) <= 0) {
3316 if (n == -1 &&
GetErrno() != EINTR)
3317 Error(
"SendRaw",
"cannot send buffer");
3328 if (sock < 0)
return -1;
3332 if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == -1) {
3333 SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
3338 if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == -1) {
3339 SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
3344 if (setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == -1) {
3345 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
3350 if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == -1) {
3351 SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
3356 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == -1) {
3357 SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
3362 if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == -1) {
3363 SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
3368 if (ioctl(sock, FIONBIO, (
char*)&val) == -1) {
3369 SysError(
"SetSockOpt",
"ioctl(FIONBIO)");
3375 if (ioctl(sock, SIOCSPGRP, (
char*)&val) == -1) {
3376 SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
3380 Error(
"SetSockOpt",
"ioctl(SIOCGPGRP) not supported on cygwin/gcc");
3387 Error(
"SetSockOpt",
"illegal option (%d)", opt);
3398 if (sock < 0)
return -1;
3400 #if defined(USE_SOCKLEN_T) || defined(_AIX43)
3401 socklen_t optlen =
sizeof(*val);
3402 #elif defined(USE_SIZE_T)
3403 size_t optlen =
sizeof(*val);
3405 int optlen =
sizeof(*val);
3410 if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == -1) {
3411 SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
3416 if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == -1) {
3417 SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
3422 if (getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == -1) {
3423 SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
3428 if (getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == -1) {
3429 SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
3434 if (getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == -1) {
3435 SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
3440 if (getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == -1) {
3441 SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
3447 if ((flg = fcntl(sock, F_GETFL, 0)) == -1) {
3448 SysError(
"GetSockOpt",
"fcntl(F_GETFL)");
3451 *val = flg & O_NDELAY;
3454 #if !defined(R__LYNXOS) && !defined(R__WINGCC)
3455 if (ioctl(sock, SIOCGPGRP, (
char*)val) == -1) {
3456 SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
3460 Error(
"GetSockOpt",
"ioctl(SIOCGPGRP) not supported on LynxOS and cygwin/gcc");
3465 #if !defined(R__LYNXOS)
3466 if (ioctl(sock, SIOCATMARK, (
char*)val) == -1) {
3467 SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
3471 Error(
"GetSockOpt",
"ioctl(SIOCATMARK) not supported on LynxOS");
3476 #if !defined(R__LYNXOS)
3477 if (ioctl(sock, FIONREAD, (
char*)val) == -1) {
3478 SysError(
"GetSockOpt",
"ioctl(FIONREAD)");
3482 Error(
"GetSockOpt",
"ioctl(FIONREAD) not supported on LynxOS");
3487 Error(
"GetSockOpt",
"illegal option (%d)", opt);
3502 static struct Signalmap_t {
3505 struct sigaction *fOldHandler;
3506 const char *fSigName;
3508 { SIGBUS, 0, 0,
"bus error" },
3509 { SIGSEGV, 0, 0,
"segmentation violation" },
3510 { SIGSYS, 0, 0,
"bad argument to system call" },
3511 { SIGPIPE, 0, 0,
"write on a pipe with no one to read it" },
3512 { SIGILL, 0, 0,
"illegal instruction" },
3513 { SIGQUIT, 0, 0,
"quit" },
3514 { SIGINT, 0, 0,
"interrupt" },
3515 { SIGWINCH, 0, 0,
"window size change" },
3516 { SIGALRM, 0, 0,
"alarm clock" },
3517 { SIGCHLD, 0, 0,
"death of a child" },
3518 { SIGURG, 0, 0,
"urgent data arrived on an I/O channel" },
3519 { SIGFPE, 0, 0,
"floating point exception" },
3520 { SIGTERM, 0, 0,
"termination signal" },
3521 { SIGUSR1, 0, 0,
"user-defined signal 1" },
3522 { SIGUSR2, 0, 0,
"user-defined signal 2" }
3592 struct sigaction sigact;
3595 gSignalMap[sig].fOldHandler =
new struct sigaction();
3599 #elif defined(R__SOLARIS)
3601 #elif defined(R__LYNXOS)
3610 sigemptyset(&sigact.sa_mask);
3611 sigact.sa_flags = 0;
3612 #if defined(SA_RESTART)
3613 sigact.sa_flags |= SA_RESTART;
3615 if (sigaction(
gSignalMap[sig].fCode, &sigact,
3617 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3628 TTHREAD_TLS_ARRAY(
struct sigaction,
kMAXSIGNALS,oldsigact);
3630 if (ignore != ignoreSig[sig]) {
3631 ignoreSig[sig] = ignore;
3633 struct sigaction sigact;
3635 sigact.sa_handler = (
void (*)())SIG_IGN;
3636 #elif defined(R__SOLARIS)
3637 sigact.sa_handler = (
void (*)(int))SIG_IGN;
3639 sigact.sa_handler = SIG_IGN;
3641 sigemptyset(&sigact.sa_mask);
3642 sigact.sa_flags = 0;
3643 if (sigaction(
gSignalMap[sig].fCode, &sigact, &oldsigact[sig]) < 0)
3644 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3646 if (sigaction(
gSignalMap[sig].fCode, &oldsigact[sig], 0) < 0)
3647 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3663 struct sigaction sigact;
3666 #elif defined(R__SOLARIS)
3668 #elif defined(R__LYNXOS)
3677 sigemptyset(&sigact.sa_mask);
3678 sigact.sa_flags = 0;
3680 #if defined(SA_INTERRUPT) // SunOS
3681 sigact.sa_flags |= SA_INTERRUPT;
3684 #if defined(SA_RESTART)
3685 sigact.sa_flags |= SA_RESTART;
3689 ::SysError(
"TUnixSystem::UnixSigAlarmInterruptsSyscalls",
"sigaction");
3709 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3732 static std::atomic<time_t> jan95{0};
3743 jan95 = mktime(&tp);
3744 if ((
int)jan95 == -1) {
3745 ::SysError(
"TUnixSystem::UnixNow",
"error converting 950001 0:00 to time_t");
3751 gettimeofday(&t, 0);
3760 struct itimerval itv;
3761 itv.it_value.tv_sec = 0;
3762 itv.it_value.tv_usec = 0;
3763 itv.it_interval.tv_sec = 0;
3764 itv.it_interval.tv_usec = 0;
3766 itv.it_value.tv_sec = time_t(ms / 1000);
3767 itv.it_value.tv_usec = time_t((ms % 1000) * 1000);
3769 int st = setitimer(ITIMER_REAL, &itv, 0);
3771 ::SysError(
"TUnixSystem::UnixSetitimer",
"setitimer");
3789 fd_set *rd = (readready) ? (fd_set*)readready->GetBits() : 0;
3790 fd_set *wr = (writeready) ? (fd_set*)writeready->GetBits() : 0;
3794 tv.tv_sec =
Int_t(timeout / 1000);
3795 tv.tv_usec = (timeout % 1000) * 1000;
3796 retcode =
select(nfds, rd, wr, 0, &tv);
3798 retcode =
select(nfds, rd, wr, 0, 0);
3800 if (retcode == -1) {
3824 pw = getpwnam(name);
3827 path[
sizeof(path)-1] =
'\0';
3833 pw = getpwuid(getuid());
3836 mydir[
sizeof(mydir)-1] =
'\0';
3840 mydir[
sizeof(mydir)-1] =
'\0';
3866 if (stat(edir, &finfo) < 0)
3869 if (!S_ISDIR(finfo.st_mode))
3872 return (
void*) opendir(edir);
3875 #if defined(_POSIX_SOURCE)
3878 # define REAL_DIR_ENTRY(dp) 1
3880 # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
3888 DIR *dirp = (DIR*)dirp1;
3920 #if defined(R__SEEK64)
3922 if (path && lstat64(path, &sbuf) == 0) {
3925 if (path && lstat(path, &sbuf) == 0) {
3927 buf.
fIsLink = S_ISLNK(sbuf.st_mode);
3929 #if defined(R__SEEK64)
3930 if (stat64(path, &sbuf) == -1) {
3932 if (stat(path, &sbuf) == -1) {
3937 buf.
fDev = sbuf.st_dev;
3938 buf.
fIno = sbuf.st_ino;
3939 buf.
fMode = sbuf.st_mode;
3940 buf.
fUid = sbuf.st_uid;
3941 buf.
fGid = sbuf.st_gid;
3942 buf.
fSize = sbuf.st_size;
3943 buf.
fMtime = sbuf.st_mtime;
3962 struct statfs statfsbuf;
3963 #if (defined(R__SOLARIS) && !defined(R__LINUX))
3964 if (statfs(path, &statfsbuf,
sizeof(
struct statfs), 0) == 0) {
3965 *
id = statfsbuf.f_fstyp;
3966 *bsize = statfsbuf.f_bsize;
3967 *blocks = statfsbuf.f_blocks;
3968 *bfree = statfsbuf.f_bfree;
3970 if (statfs((
char*)path, &statfsbuf) == 0) {
3976 if (!strcmp(statfsbuf.f_fstypename, MOUNT_FFS) ||
3977 !strcmp(statfsbuf.f_fstypename, MOUNT_MFS))
3979 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NFS))
3981 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_MSDOS))
3983 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_PROCFS))
3985 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_EXT2FS))
3987 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_CD9660))
3989 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NCPFS))
3994 *
id = statfsbuf.f_type;
3996 *bsize = statfsbuf.f_bsize;
3997 *blocks = statfsbuf.f_blocks;
3998 *bfree = statfsbuf.f_bavail;
4011 return (
int) waitpid(0, &status, WNOHANG);
4029 if ((sp = getservbyport(htons(port), kProtocolName)))
4032 sport = htons(port);
4035 if (!addr.
IsValid())
return -1;
4038 struct sockaddr_in server;
4039 memset(&server, 0,
sizeof(server));
4040 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4042 server.sin_port = sport;
4046 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4047 ::SysError(
"TUnixSystem::UnixTcpConnect",
"socket (%s:%d)",
4052 if (tcpwindowsize > 0) {
4057 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4061 ::SysError(
"TUnixSystem::UnixTcpConnect",
"connect (%s:%d)",
4080 if ((sp = getservbyport(htons(port), kProtocolName)))
4083 sport = htons(port);
4086 if (!addr.
IsValid())
return -1;
4089 struct sockaddr_in server;
4090 memset(&server, 0,
sizeof(server));
4091 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4093 server.sin_port = sport;
4097 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4098 ::SysError(
"TUnixSystem::UnixUdpConnect",
"socket (%s:%d)",
4103 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4107 ::SysError(
"TUnixSystem::UnixUdpConnect",
"connect (%s:%d)",
4129 if (!sockpath || strlen(sockpath) <= 0) {
4130 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket path undefined");
4135 struct sockaddr_un unserver;
4136 unserver.sun_family = AF_UNIX;
4138 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4139 ::Error(
"TUnixSystem::UnixUnixConnect",
"socket path %s, longer than max allowed length (%u)",
4140 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4143 strcpy(unserver.sun_path, sockpath);
4146 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4147 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket");
4151 while (connect(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2) == -1) {
4155 ::SysError(
"TUnixSystem::UnixUnixConnect",
"connect");
4178 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4179 short sport, tryport = kSOCKET_MINPORT;
4182 if (port == 0 && reuse) {
4183 ::Error(
"TUnixSystem::UnixTcpService",
"cannot do a port scan while reuse is true");
4187 if ((sp = getservbyport(htons(port), kProtocolName)))
4190 sport = htons(port);
4194 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4195 ::SysError(
"TUnixSystem::UnixTcpService",
"socket");
4202 if (tcpwindowsize > 0) {
4207 struct sockaddr_in inserver;
4208 memset(&inserver, 0,
sizeof(inserver));
4209 inserver.sin_family = AF_INET;
4210 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4211 inserver.sin_port = sport;
4215 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4216 ::SysError(
"TUnixSystem::UnixTcpService",
"bind");
4223 inserver.sin_port = htons(tryport++);
4224 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4225 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4227 ::SysError(
"TUnixSystem::UnixTcpService",
"bind (port scan)");
4234 if (::listen(sock, backlog)) {
4235 ::SysError(
"TUnixSystem::UnixTcpService",
"listen");
4252 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4253 short sport, tryport = kSOCKET_MINPORT;
4256 if ((sp = getservbyport(htons(port), kProtocolName)))
4259 sport = htons(port);
4263 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4264 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
4268 struct sockaddr_in inserver;
4269 memset(&inserver, 0,
sizeof(inserver));
4270 inserver.sin_family = AF_INET;
4271 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4272 inserver.sin_port = sport;
4276 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4277 ::SysError(
"TUnixSystem::UnixUdpService",
"bind");
4284 inserver.sin_port = htons(tryport++);
4285 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4286 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4288 ::SysError(
"TUnixSystem::UnixUdpService",
"bind (port scan)");
4295 if (::listen(sock, backlog)) {
4296 ::SysError(
"TUnixSystem::UnixUdpService",
"listen");
4313 oldumask = umask(0);
4314 int res =
::mkdir(kServerPath, 0777);
4322 sockpath.
Form(
"%s/%d", kServerPath, port);
4325 unlink(sockpath.
Data());
4336 if (!sockpath || strlen(sockpath) <= 0) {
4337 ::SysError(
"TUnixSystem::UnixUnixService",
"socket path undefined");
4341 struct sockaddr_un unserver;
4345 memset(&unserver, 0,
sizeof(unserver));
4346 unserver.sun_family = AF_UNIX;
4348 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4349 ::Error(
"TUnixSystem::UnixUnixService",
"socket path %s, longer than max allowed length (%u)",
4350 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4353 strcpy(unserver.sun_path, sockpath);
4356 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4357 ::SysError(
"TUnixSystem::UnixUnixService",
"socket");
4361 if (::bind(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2)) {
4362 ::SysError(
"TUnixSystem::UnixUnixService",
"bind");
4368 if (::listen(sock, backlog)) {
4369 ::SysError(
"TUnixSystem::UnixUnixService",
"listen");
4388 if (sock < 0)
return -1;
4395 if (flag == MSG_PEEK)
4399 char *buf = (
char *)buffer;
4401 for (n = 0; n <
length; n += nrecv) {
4402 if ((nrecv = recv(sock, buf+n, length-n, flag)) <= 0) {
4405 if (flag == MSG_OOB) {
4415 ::
SysError(
"TUnixSystem::UnixRecv",
"recv");
4436 if (sock < 0)
return -1;
4445 const char *buf = (
const char *)buffer;
4447 for (n = 0; n <
length; n += nsent) {
4448 if ((nsent = send(sock, buf+n, length-n, flag)) <= 0) {
4455 ::
SysError(
"TUnixSystem::UnixSend",
"send");
4486 }
else if (reset || !initialized) {
4487 initialized =
kTRUE;
4492 rdynpath =
".:"; rdynpath += ROOTLIBDIR;
4494 rdynpath =
".:"; rdynpath +=
gRootDir; rdynpath +=
"/lib";
4498 #if defined (R__AIX)
4500 #elif defined(R__MACOSX)
4514 dynpath = ldpath; dynpath +=
":"; dynpath += rdynpath;
4518 if (!dynpath.
Contains(ROOTLIBDIR)) {
4519 dynpath +=
":"; dynpath += ROOTLIBDIR;
4523 dynpath +=
":"; dynpath +=
gRootDir; dynpath +=
"/lib";
4531 #if defined(R__WINGCC) || defined(R__MACOSX)
4532 if (!dynpath.
EndsWith(
":")) dynpath +=
":";
4533 dynpath +=
"/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:";
4534 dynpath +=
"/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:";
4537 std::string cmd(
"LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls 2>&1");
4538 FILE *pf = popen(cmd.c_str (),
"r");
4542 if (fgets(buffer, 128, pf) !=
NULL)
4546 std::size_t from = result.find(
"search path=", result.find(
"(LD_LIBRARY_PATH)"));
4547 std::size_t to = result.find(
"(system search path)");
4548 if (from != std::string::npos && to != std::string::npos) {
4550 std::string sys_path = result.substr(from, to-from);
4551 sys_path.erase(std::remove_if(sys_path.begin(), sys_path.end(), isspace), sys_path.end());
4552 if (!dynpath.
EndsWith(
":")) dynpath +=
":";
4553 dynpath += sys_path.c_str();
4557 if (
gDebug > 0) std::cout <<
"dynpath = " << dynpath.
Data() << std::endl;
4604 char *res = realpath(sLib.
Data(), buf);
4605 if (res) sLib = buf;
4611 const char* lib = sLib.
Data();
4613 if (len > 3 && (!strcmp(lib+len-3,
".so") ||
4614 !strcmp(lib+len-3,
".dl") ||
4615 !strcmp(lib+len-4,
".dll") ||
4616 !strcmp(lib+len-4,
".DLL") ||
4617 !strcmp(lib+len-6,
".dylib") ||
4618 !strcmp(lib+len-3,
".sl") ||
4619 !strcmp(lib+len-2,
".a"))) {
4624 Error(
"FindDynamicLibrary",
4628 static const char* exts[] = {
4629 ".so",
".dll",
".dylib",
".sl",
".dl",
".a", 0 };
4630 const char** ext = exts;
4642 Error(
"FindDynamicLibrary",
4643 "%s[.so | .dll | .dylib | .sl | .dl | .a] does not exist in %s",
4651 #if defined(R__MACOSX)
4652 #include <sys/resource.h>
4653 #include <mach/mach.h>
4654 #include <mach/mach_error.h>
4659 static void GetDarwinSysInfo(
SysInfo_t *sysinfo)
4661 FILE *p =
gSystem->
OpenPipe(
"sysctl -n kern.ostype hw.model hw.ncpu hw.cpufrequency "
4662 "hw.busfrequency hw.l2cachesize hw.memsize",
"r");
4695 static void ReadDarwinCpu(
long *ticks)
4697 mach_msg_type_number_t count;
4699 host_cpu_load_info_data_t cpu;
4701 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
4703 count = HOST_CPU_LOAD_INFO_COUNT;
4704 kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpu, &count);
4705 if (kr != KERN_SUCCESS) {
4706 ::Error(
"TUnixSystem::ReadDarwinCpu",
"host_statistics: %s", mach_error_string(kr));
4708 ticks[0] = cpu.cpu_ticks[CPU_STATE_USER];
4709 ticks[1] = cpu.cpu_ticks[CPU_STATE_SYSTEM];
4710 ticks[2] = cpu.cpu_ticks[CPU_STATE_IDLE];
4711 ticks[3] = cpu.cpu_ticks[CPU_STATE_NICE];
4719 static void GetDarwinCpuInfo(
CpuInfo_t *cpuinfo,
Int_t sampleTime)
4722 if (getloadavg(avg,
sizeof(avg)) < 0) {
4723 ::Error(
"TUnixSystem::GetDarwinCpuInfo",
"getloadavg failed");
4730 Long_t cpu_ticks1[4], cpu_ticks2[4];
4731 ReadDarwinCpu(cpu_ticks1);
4733 ReadDarwinCpu(cpu_ticks2);
4735 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
4736 (cpu_ticks1[0] + cpu_ticks1[3]);
4737 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
4738 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
4739 if (userticks < 0) userticks = 0;
4740 if (systicks < 0) systicks = 0;
4741 if (idleticks < 0) idleticks = 0;
4742 Long_t totalticks = userticks + systicks + idleticks;
4754 static void GetDarwinMemInfo(
MemInfo_t *meminfo)
4756 static Int_t pshift = 0;
4758 vm_statistics_data_t vm_info;
4759 mach_msg_type_number_t count;
4764 count = HOST_VM_INFO_COUNT;
4765 kr = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_info, &count);
4766 if (kr != KERN_SUCCESS) {
4767 ::Error(
"TUnixSystem::GetDarwinMemInfo",
"host_statistics: %s", mach_error_string(kr));
4771 for (
int psize = getpagesize(); psize > 1; psize >>= 1)
4775 used = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.wire_count) << pshift;
4776 free = (
Long64_t)(vm_info.free_count) << pshift;
4777 total = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.free_count + vm_info.wire_count) << pshift;
4780 swap_used = vm_info.pageouts << pshift;
4783 dirp = opendir(
"/private/var/vm");
4788 while ((dp = readdir(dirp)) != 0) {
4790 char fname [MAXNAMLEN];
4791 if (strncmp(dp->d_name,
"swapfile", 8))
4793 strlcpy(fname,
"/private/var/vm/",MAXNAMLEN);
4794 strlcat (fname, dp->d_name,MAXNAMLEN);
4795 if (stat(fname, &sb) < 0)
4797 swap_total += sb.st_size;
4817 static void GetDarwinProcInfo(
ProcInfo_t *procinfo)
4820 #define vm_region vm_region_64
4824 #define GLOBAL_SHARED_TEXT_SEGMENT 0x90000000U
4825 #define GLOBAL_SHARED_DATA_SEGMENT 0xA0000000U
4826 #define SHARED_TEXT_REGION_SIZE 0x10000000
4827 #define SHARED_DATA_REGION_SIZE 0x10000000
4830 if (getrusage(RUSAGE_SELF, &ru) < 0) {
4831 ::SysError(
"TUnixSystem::GetDarwinProcInfo",
"getrusage failed");
4834 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
4836 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
4839 task_basic_info_data_t ti;
4840 mach_msg_type_number_t count;
4843 task_t a_task = mach_task_self();
4845 count = TASK_BASIC_INFO_COUNT;
4846 kr = task_info(a_task, TASK_BASIC_INFO, (task_info_t)&ti, &count);
4847 if (kr != KERN_SUCCESS) {
4848 ::Error(
"TUnixSystem::GetDarwinProcInfo",
"task_info: %s", mach_error_string(kr));
4853 mach_port_t object_name;
4854 vm_address_t address;
4855 vm_region_top_info_data_t info;
4856 vm_size_t vsize, vprvt, rsize, size;
4857 rsize = ti.resident_size;
4858 vsize = ti.virtual_size;
4860 for (address = 0; ; address += size) {
4862 count = VM_REGION_TOP_INFO_COUNT;
4863 if (vm_region(a_task, &address, &size,
4864 VM_REGION_TOP_INFO, (vm_region_info_t)&info, &count,
4865 &object_name) != KERN_SUCCESS) {
4870 if (address >= GLOBAL_SHARED_TEXT_SEGMENT &&
4871 address < (GLOBAL_SHARED_DATA_SEGMENT + SHARED_DATA_REGION_SIZE)) {
4876 if (info.share_mode == SM_EMPTY) {
4877 vm_region_basic_info_data_64_t b_info;
4878 count = VM_REGION_BASIC_INFO_COUNT_64;
4879 if (vm_region_64(a_task, &address,
4880 &size, VM_REGION_BASIC_INFO,
4881 (vm_region_info_t)&b_info, &count,
4882 &object_name) != KERN_SUCCESS) {
4886 if (b_info.reserved) {
4887 vsize -= (SHARED_TEXT_REGION_SIZE + SHARED_DATA_REGION_SIZE);
4894 if (info.share_mode != SM_PRIVATE) {
4898 switch (info.share_mode) {
4900 if (info.ref_count == 1) {
4903 vprvt += info.private_pages_resident * getpagesize();
4923 #if defined(R__LINUX)
4927 static void GetLinuxSysInfo(
SysInfo_t *sysinfo)
4930 FILE *f = fopen(
"/proc/cpuinfo",
"r");
4954 f = fopen(
"/proc/meminfo",
"r");
4979 static void ReadLinuxCpu(
long *ticks)
4981 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
4984 FILE *f = fopen(
"/proc/stat",
"r");
4988 sscanf(s.
Data(),
"%*s %ld %ld %ld %ld", &ticks[0], &ticks[3], &ticks[1], &ticks[2]);
4996 static void GetLinuxCpuInfo(
CpuInfo_t *cpuinfo,
Int_t sampleTime)
4998 Double_t avg[3] = { -1., -1., -1. };
5000 if (getloadavg(avg,
sizeof(avg)) < 0) {
5001 ::Error(
"TUnixSystem::GetLinuxCpuInfo",
"getloadavg failed");
5010 Long_t cpu_ticks1[4], cpu_ticks2[4];
5011 ReadLinuxCpu(cpu_ticks1);
5013 ReadLinuxCpu(cpu_ticks2);
5015 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
5016 (cpu_ticks1[0] + cpu_ticks1[3]);
5017 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
5018 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
5019 if (userticks < 0) userticks = 0;
5020 if (systicks < 0) systicks = 0;
5021 if (idleticks < 0) idleticks = 0;
5022 Long_t totalticks = userticks + systicks + idleticks;
5034 static void GetLinuxMemInfo(
MemInfo_t *meminfo)
5037 FILE *f = fopen(
"/proc/meminfo",
"r");
5066 static void GetLinuxProcInfo(
ProcInfo_t *procinfo)
5069 if (getrusage(RUSAGE_SELF, &ru) < 0) {
5070 ::SysError(
"TUnixSystem::GetLinuxProcInfo",
"getrusage failed");
5073 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
5075 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
5086 sscanf(s.
Data(),
"%ld %ld", &
total, &rss);
5087 procinfo->
fMemVirtual = total * (getpagesize() / 1024);
5100 if (!info)
return -1;
5104 if (!sysinfo.
fCpus) {
5105 #if defined(R__MACOSX)
5106 GetDarwinSysInfo(&sysinfo);
5107 #elif defined(R__LINUX)
5108 GetLinuxSysInfo(&sysinfo);
5124 if (!info)
return -1;
5126 #if defined(R__MACOSX)
5127 GetDarwinCpuInfo(info, sampleTime);
5128 #elif defined(R__LINUX)
5129 GetLinuxCpuInfo(info, sampleTime);
5141 if (!info)
return -1;
5143 #if defined(R__MACOSX)
5144 GetDarwinMemInfo(info);
5145 #elif defined(R__LINUX)
5146 GetLinuxMemInfo(info);
5158 if (!info)
return -1;
5160 #if defined(R__MACOSX)
5161 GetDarwinProcInfo(info);
5162 #elif defined(R__LINUX)
5163 GetLinuxProcInfo(info);
Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
int GetPid()
Get process id.
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
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.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
double read(const std::string &file_name)
reading
void AddTimer(TTimer *ti)
Add timer to list of system timers.
virtual void SetWriteReady()
void ListSymbols(const char *module, const char *re="")
List symbols in a shared library.
virtual int GetPid()
Get process id.
void StackTrace()
Print a stack trace.
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
virtual Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
int GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.
Small helper to encapsulate whether to return the value pointed to by the iterator or its address...
const char * GetError()
Return system error string.
virtual const char * WorkingDirectory()
Return working directory.
void Sleep(UInt_t milliSec)
Sleep milliSec milliseconds.
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.
static void UnixResetSignal(ESignals sig)
Restore old signal handler for specified signal.
Bool_t ExpandPathName(TString &patbuf)
Expand a pathname getting rid of special shell characters like ~.
double write(int n, const std::string &file_name, const std::string &vector_type, int compress=0)
writing
virtual ~TUnixSystem()
Reset to original state.
static const char * GetExePath()
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
R__EXTERN TVirtualMutex * gSystemMutex
void Fatal(const char *location, const char *msgfmt,...)
Collectable string class.
int GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
static int UnixFilestat(const char *path, FileStat_t &buf)
Get info about a file.
Int_t GetFPEMask()
Return the bitmap of conditions that trigger a floating point exception.
static int UnixTcpConnect(const char *hostname, int port, int tcpwindowsize)
Open a TCP/IP connection to server and connect to a service (i.e.
static int UnixRecv(int sock, void *buf, int len, int flag)
Receive exactly length bytes into buffer.
int GetSockOpt(int sock, int option, int *val)
Get socket option.
TString & ReplaceAll(const TString &s1, const TString &s2)
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.
Bool_t DispatchTimers(Bool_t mode)
Handle and dispatch timers.
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 demangle(char *_codeInfo, TString &_str)
demangle symbols
int Symlink(const char *from, const char *to)
Create a symlink from file1 to file2.
This class represents an Internet Protocol (IP) address.
virtual int MakeDirectory(const char *name)
Make a directory.
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
int MakeDirectory(const char *name)
Make a Unix file system directory.
Regular expression class.
Int_t Select(TList *active, Long_t timeout)
Select on file descriptors.
Int_t GetGid(const char *group=0)
Returns the group's id. If group = 0, returns current user's group.
static Long64_t UnixNow()
Get current time in milliseconds since 0:00 Jan 1 1995.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
TSeqCollection * fSignalHandler
static struct Signalmap_t gSignalMap[kMAXSIGNALS]
TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
R__EXTERN TVirtualMutex * gROOTMutex
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...
const char * HostName()
Return the system's host name.
int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
int Umask(Int_t mask)
Set the process file creation mode mask.
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
void Break(const char *location, const char *msgfmt,...)
void Syslog(ELogLevel level, const char *mess)
Send mess to syslog daemon.
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
#define REAL_DIR_ENTRY(dp)
virtual void ResetReadyMask()
TString & Prepend(const char *cs)
R__EXTERN TApplication * gApplication
Basic time type with millisecond precision.
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 ConnectService(const char *server, int port, int tcpwindowsize, const char *protocol="tcp")
Connect to service servicename on server servername.
const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
int Unlink(const char *name)
Unlink, i.e.
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...
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
void SysError(const char *location, const char *msgfmt,...)
virtual const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
static Int_t GetErrno()
Static function returning system error number.
const char * Data() const
virtual Bool_t Notify()
Notify when signal occurs.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
ClassImp(RooList) TObjOptLink *RooList TObjLink * link
Find the link corresponding to the named object in this list.
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Int_t Exec(const char *shellcmd)
Execute a command.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
void DispatchOneEvent(Bool_t pendingOnly=kFALSE)
Dispatch a single event.
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
TPaveText exe(6, 5.5, 12, 8)
static int UnixSend(int sock, const void *buf, int len, int flag)
Send exactly length bytes from buffer.
const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Int_t SetFPEMask(Int_t mask=kDefaultMask)
Set which conditions trigger a floating point exception.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
static const char * DynamicPath(const char *newpath=0, Bool_t reset=kFALSE)
Get shared library search path. Static utility function.
TObject * Next()
Return next object in collection.
Int_t fNfd
Signals that were trapped.
R__EXTERN TFileHandler * gXDisplay
static TString * ReadString(TBuffer &b, const TClass *clReq)
Read TString object from buffer.
static int UnixSetitimer(Long_t ms)
Set interval timer to time-out in ms milliseconds.
virtual const char * Getenv(const char *env)
Get environment variable.
virtual void ListLibraries(const char *regexp="")
List all loaded shared libraries.
static void UnixResetSignals()
Restore old signal handlers.
FILE * OpenPipe(const char *shellcmd, const char *mode)
Open a pipe.
TString & Append(const char *cs)
TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
int AcceptConnection(int sock)
Accept a connection.
Int_t Atoi() const
Return integer value of string.
virtual void Unload(const char *module)
Unload a shared library.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
void ResetSignals()
Reset signals handlers to previous behaviour.
int SetSockOpt(int sock, int option, int val)
Set socket option.
UInt_t GetAddress() const
TSeqCollection * fFileHandler
TString & GetLastErrorString()
Return the thread local storage for the custom last error message.
static void SigHandler(ESignals sig)
Unix signal handler.
TTimer * RemoveTimer(TTimer *ti)
Remove timer from list of system timers.
virtual Bool_t WriteNotify()
Notify when something can be written to the descriptor associated with this handler.
R__EXTERN const char * gProgName
int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const
Returns cpu load average and load info into the CpuInfo_t structure.
static const char * UnixHomedirectory(const char *user=0)
Returns the user's home directory.
static void sighandler(int sig)
Call the signal handler associated with the signal.
void FreeDirectory(void *dirp)
Close a Unix file system directory.
ClassImp(TUnixSystem) TUnixSystem
virtual void Setenv(const char *name, const char *value)
Set environment variable.
virtual Bool_t HasWriteInterest()
True if handler is interested in write events.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Double_t length(const TVector2 &v)
virtual Bool_t Init()
Initialize the OS interface.
int Chmod(const char *file, UInt_t mode)
Set the file permission bits. Returns -1 in case or error, 0 otherwise.
R__EXTERN TSystem * gSystem
int Utime(const char *file, Long_t modtime, Long_t actime)
Set a files modification and access times.
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
Bool_t Gets(FILE *fp, Bool_t chop=kTRUE)
Read one line from the stream, including the , or until EOF.
virtual void SetReadReady()
virtual Long_t NextTimeOut(Bool_t mode)
Time when next timer of mode (synchronous=kTRUE or asynchronous=kFALSE) will time-out (in ms)...
void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
void Closelog()
Close connection to system log daemon.
char * Form(const char *fmt,...)
void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
static const char * StripOffProto(const char *path, const char *proto)
Handles synchronous and a-synchronous timer events.
Bool_t CheckTimer(const TTime &now)
Check if timer timed out.
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
TSubString Strip(EStripType s=kTrailing, char c= ' ') const
Return a substring of self stripped at beginning and/or end.
Func_t DynFindSymbol(const char *module, const char *entry)
dynamic linking of module
static int UnixWaitchild()
Wait till child is finished.
void * OpenDirectory(const char *name)
Open a Unix file system directory. Returns 0 if directory does not exist.
static int UnixUnixService(int port, int backlog)
Open a socket, bind to it and start listening for Unix domain connections to it.
static const char * UnixSigname(ESignals sig)
Return the signal name associated with a signal.
Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
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.
const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
void AddAlias(const char *alias)
Add alias to list of aliases.
virtual void FreeDirectory(void *dirp)
Free a directory.
virtual int ClosePipe(FILE *pipe)
Close the pipe.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
void Unsetenv(const char *name)
Unset environment variable.
UserGroup_t * GetGroupInfo(Int_t gid)
Returns all group info in the UserGroup_t structure.
char * StrDup(const char *str)
Duplicate the string str.
virtual int SetSockOpt(int sock, int kind, int val)
Set socket option.
static void UnixSignal(ESignals sig, SigHandler_t h)
Set a signal handler for a signal.
TString & Remove(Ssiz_t pos)
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
const char * Getenv(const char *name)
Get environment variable.
virtual TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
static int UnixMakedir(const char *name)
Make a Unix file system directory.
virtual Int_t GetSize() const
TFdSet * fReadready
Files that should be checked for write events.
static int UnixUdpService(int port, int backlog)
Open a socket, bind to it and start listening for UDP connections on the port.
void AddAddress(UInt_t addr)
Add alternative address to list of addresses.
R__EXTERN const char * gProgPath
TString & Swap(TString &other)
void(* SigHandler_t)(ESignals)
Int_t GetEffectiveUid()
Returns the effective user id.
static int UnixUnixConnect(int port)
Connect to a Unix domain socket.
virtual Func_t DynFindSymbol(const char *module, const char *entry)
Find specific entry point in specified library.
virtual const char * GetName() const
Returns name of object.
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 select(Int_t replica=1, Int_t color=kGreen)
int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
Long64_t Atoll() const
Return long long value of string.
int RecvBuf(int sock, void *buffer, int length)
Receive a buffer headed by a length indicator.
int Rename(const char *from, const char *to)
Rename a file. Returns 0 when successful, -1 in case of failure.
int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1)
Announce TCP/IP service.
virtual const char * ExpandFileName(const char *fname)
Expand a pathname getting rid of special shell characters like ~.
void CheckChilds()
Check if children have finished.
double func(double *x, double *p)
static void UnixIgnoreSignal(ESignals sig, Bool_t ignore)
If ignore is true ignore the specified signal, else restore previous behaviour.
TFdSet * fSignals
Files with writes waiting.
#define R__LOCKGUARD(mutex)
static void * UnixOpendir(const char *name)
Open a directory.
Bool_t ChangeDirectory(const char *path)
Change directory. Returns kTRUE in case of success, kFALSE otherwise.
const char * GetLinkedLibraries()
Get list of shared libraries loaded at the start of the executable.
char * GetServiceByPort(int port)
Get name of internet service.
Binding & operator=(OUT(*fun)(void))
#define org(otri, vertexptr)
int EscChar(const char *src, char *dst, int dstlen, char *specchars, char escchar)
Escape specchars in src with escchar and copy to dst.
virtual void HandleException(Int_t sig)
Handle exceptions (kSigBus, kSigSegmentationViolation, kSigIllegalInstruction and kSigFloatingExcepti...
typedef void((*Func_t)())
void ResetSignal(ESignals sig, Bool_t reset=kTRUE)
If reset is true reset the signal handler for the specified signal to the default handler...
void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
static const char * UnixGetdirentry(void *dir)
Returns the next directory entry.
R__EXTERN const char * gRootDir
void ResetTimer(TTimer *ti)
Reset a-sync timer.
void AddDynamicPath(const char *lib)
Add a new directory to the dynamic path.
Short_t Max(Short_t a, Short_t b)
ESignals GetSignal() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
const char * GetDirEntry(void *dirp)
Get next Unix file system directory entry. Returns 0 if no more entries.
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...
TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
FILE * TempFileName(TString &base, const char *dir=0)
Create a secure temporary file by appending a unique 6 letter string to base.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
Iterator of ordered collection.
TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
int AnnounceUnixService(int port, int backlog)
Announce unix domain service on path "kServerPath/<port>".
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
int ClosePipe(FILE *pipe)
Close the pipe.
void SetDynamicPath(const char *lib)
Set the dynamic path to a new value.
int Link(const char *from, const char *to)
Create a link from file1 to file2.
void Abort(int code=0)
Abort the application.
void Unload(const char *module)
Unload a shared library.
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...
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
static void ResetErrno()
Static function resetting system error number.
void SigAlarmInterruptsSyscalls(Bool_t set)
When the argument is true the SIGALRM signal handler is set so that interrupted syscalls will not be ...
Int_t GetEffectiveGid()
Returns the effective group id.
Bool_t CheckSignals(Bool_t sync)
Check if some signals were raised and call their Notify() member.
static int UnixUdpConnect(const char *hostname, int port)
Creates a UDP socket connection Is called via the TSocket constructor.
int GetServiceByName(const char *service)
Get port # of internet service.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
TFdSet * fWriteready
Files with reads waiting.
TObject * At(Int_t idx) const
void Openlog(const char *name, Int_t options, ELogFacility facility)
Open connection to system log daemon.
R__EXTERN TInterpreter * gCling
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual const char * GetSTLIncludePath() const
UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Abstract base class defining a generic interface to the underlying Operating System.
void DispatchSignals(ESignals sig)
Handle and dispatch signals.
int SendBuf(int sock, const void *buffer, int length)
Send a buffer headed by a length indicator.
TFdSet * fWritemask
Files that should be checked for read events.
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
void ListLibraries(const char *regexp="")
List all loaded shared libraries.
const char * WorkingDirectory()
Return working directory.
int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
void Setenv(const char *name, const char *value)
Set environment variable.
int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to a service on a server.
virtual Bool_t HasReadInterest()
True if handler is interested in read events.
int AnnounceUdpService(int port, int backlog)
Announce UDP service.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.