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 # define HAVE_BACKTRACE_SYMBOLS_FD 200 #ifdef HAVE_BACKTRACE_SYMBOLS_FD 201 # include <execinfo.h> 210 #ifdef HAVE_BACKTRACE_SYMBOLS_FD 213 static const int kMAX_BACKTRACE_DEPTH = 128;
217 #if (defined(R__LINUX) && !defined(R__WINGCC)) 218 #include <fpu_control.h> 220 #include <sys/prctl.h> 223 #if defined(R__MACOSX) && defined(__SSE2__) 224 #include <xmmintrin.h> 227 #if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \ 228 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \ 232 #include <ucontext.h> 235 #include <mach/thread_status.h> 237 #define fegetenvd(x) asm volatile("mffs %0" : "=f" (x)); 238 #define fesetenvd(x) asm volatile("mtfsf 255,%0" : : "f" (x)); 241 FE_ENABLE_INEXACT = 0x00000008,
242 FE_ENABLE_DIVBYZERO = 0x00000010,
243 FE_ENABLE_UNDERFLOW = 0x00000020,
244 FE_ENABLE_OVERFLOW = 0x00000040,
245 FE_ENABLE_INVALID = 0x00000080,
246 FE_ENABLE_ALL_EXCEPT = 0x000000F8
250 #if defined(R__MACOSX) && !defined(__SSE2__) && \ 251 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__)) 263 template<typename U = T, typename std::enable_if<std::is_member_pointer<decltype(&U::ut_name)>::value,
int>
::type = 0>
264 static char getValue(U* ue,
int) {
265 return ue->ut_name[0];
268 template<typename U = T, typename std::enable_if<std::is_member_pointer<decltype(&U::ut_user)>::value,
int>::type = 0>
269 static char getValue(U* ue,
long) {
270 return ue->ut_user[0];
276 return ut_name<STRUCT_UTMP>::getValue(ue, 0);
280 struct TUtmpContent {
284 TUtmpContent() : fUtmpContents(0), fEntries(0) {}
285 ~TUtmpContent() {
free(fUtmpContents); }
295 if (get_ut_name(ue) && !strncmp(tty, ue->ut_line,
sizeof(ue->ut_line)))
307 struct stat file_stats;
318 if (fstat(fileno(utmp), &file_stats) == -1) {
322 size = file_stats.st_size;
329 if (!fUtmpContents) {
334 n_read = fread(fUtmpContents, 1, size, utmp);
336 if (fclose(utmp) != EOF && n_read == size) {
355 # define HOWMANY(x, y) (((x)+((y)-1))/(y)) 370 TFdSet() { memset(fds_bits, 0,
sizeof(fds_bits)); }
371 TFdSet(
const TFdSet &
org) { memcpy(fds_bits, org.fds_bits,
sizeof(org.fds_bits)); }
372 TFdSet &operator=(
const TFdSet &rhs) {
if (
this != &rhs) { memcpy(fds_bits, rhs.fds_bits,
sizeof(rhs.fds_bits));}
return *
this; }
373 void Zero() { memset(fds_bits, 0,
sizeof(fds_bits)); }
415 TTHREAD_TLS_DECL(
TString,exepath);
417 #if defined(R__MACOSX) 418 exepath = _dyld_get_image_name(0);
419 #elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__FBSD) 423 #if defined(R__LINUX) 424 int ret = readlink(
"/proc/self/exe", buf,
kMAXPATHLEN);
425 #elif defined(R__SOLARIS) 426 int ret = readlink(
"/proc/self/path/a.out", buf,
kMAXPATHLEN);
427 #elif defined(R__FBSD) 428 int ret = readlink(
"/proc/curproc/file", buf,
kMAXPATHLEN);
456 #if defined(HAVE_DLADDR) && !defined(R__MACOSX) 459 static void SetRootSys()
462 void *addr = (
void *)SetRootSys;
464 if (dladdr(addr, &info) && info.dli_fname && info.dli_fname[0]) {
466 if (!realpath(info.dli_fname, respath)) {
468 ::
SysError(
"TUnixSystem::SetRootSys",
"error getting realpath of libCore, please set ROOTSYS in the shell");
480 #if defined(R__MACOSX) 485 static void DylibAdded(
const struct mach_header *mh, intptr_t )
494 gLinkedDylibs = linkedDylibs;
498 TString lib = _dyld_get_image_name(i++);
500 TRegexp sovers =
"libCore\\.[0-9]+\\.*[0-9]*\\.so";
501 TRegexp dyvers =
"libCore\\.[0-9]+\\.*[0-9]*\\.dylib";
504 #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR 508 if (!realpath(lib, respath)) {
520 if (!realpath(lib, respath)) {
522 ::
SysError(
"TUnixSystem::DylibAdded",
"error getting realpath of libCore, please set ROOTSYS in the shell");
535 if (lib.
EndsWith(
"/libSystem.B.dylib"))
540 sovers =
"\\.[0-9]+\\.*[0-9]*\\.so";
546 dyvers =
"\\.[0-9]+\\.*[0-9]*\\.dylib";
547 idx = lib.
Index(dyvers);
553 if (linkedDylibs.
Length())
590 fReadmask =
new TFdSet;
591 fWritemask =
new TFdSet;
592 fReadready =
new TFdSet;
593 fWriteready =
new TFdSet;
594 fSignals =
new TFdSet;
607 #if defined(R__MACOSX) 610 _dyld_register_func_for_add_image(DylibAdded);
611 #elif defined(HAVE_DLADDR) 641 if (!name || !*name) {
647 char *w = Which(Getenv(
"PATH"),
gProgName);
658 if (!Getenv(
"DISPLAY")) {
659 char *tty = ::ttyname(0);
666 STRUCT_UTMP *utmp_entry = utmp.SearchUtmpEntry(tty);
668 if (utmp_entry->ut_host[0]) {
669 if (strchr(utmp_entry->ut_host,
':')) {
670 Setenv(
"DISPLAY", utmp_entry->ut_host);
671 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
672 utmp_entry->ut_host);
675 snprintf(disp,
sizeof(disp),
"%s:0.0", utmp_entry->ut_host);
676 Setenv(
"DISPLAY", disp);
677 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
682 else if (utmp_entry->ut_addr) {
684 struct sockaddr_in addr;
685 addr.sin_family = AF_INET;
687 memcpy(&addr.sin_addr, &utmp_entry->ut_addr,
sizeof(addr.sin_addr));
688 memset(&addr.sin_zero[0], 0,
sizeof(addr.sin_zero));
689 struct sockaddr *sa = (
struct sockaddr *) &addr;
691 char hbuf[NI_MAXHOST];
692 if (getnameinfo(sa,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, NI_NAMEREQD) == 0) {
694 snprintf(disp,
sizeof(disp),
"%s:0.0", hbuf);
695 Setenv(
"DISPLAY", disp);
696 Warning(
"SetDisplay",
"DISPLAY not set, setting it to %s",
712 if (err == 0 && GetLastErrorString() !=
"")
713 return GetLastErrorString();
715 #if defined(R__SOLARIS) || defined (R__LINUX) || defined(R__AIX) || \ 716 defined(R__FBSD) || defined(R__OBSD) || defined(R__HURD) 717 return strerror(err);
719 if (err < 0 || err >= sys_nerr)
720 return Form(
"errno out of range %d", err);
721 return sys_errlist[err];
730 if (fHostname ==
"") {
732 #if defined(R__SOLARIS) 733 sysinfo(SI_HOSTNAME, hn,
sizeof(hn));
735 gethostname(hn,
sizeof(hn));
739 return (
const char *)fHostname;
779 TIter next(fFileHandler);
785 int fd = th->
GetFd();
825 TIter next(fSignalHandler);
844 UnixResetSignal(sig);
863 UnixIgnoreSignal(sig, ignore);
876 UnixSigAlarmInterruptsSyscalls(
set);
886 #if defined(R__LINUX) && !defined(__powerpc__) 887 #if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1) 889 #if __GLIBC_MINOR__>=3 891 Int_t oldmask = fegetexcept();
898 Int_t oldmask = ~oldenv;
900 Int_t oldmask = ~oldenv.__control_word;
904 if (oldmask & FE_INVALID ) mask |=
kInvalid;
905 if (oldmask & FE_DIVBYZERO) mask |=
kDivByZero;
906 if (oldmask & FE_OVERFLOW ) mask |=
kOverflow;
907 if (oldmask & FE_UNDERFLOW) mask |=
kUnderflow;
909 if (oldmask & FE_INEXACT ) mask |=
kInexact;
914 #if defined(R__MACOSX) && defined(__SSE2__) 916 Int_t oldmask = ~_MM_GET_EXCEPTION_MASK();
918 if (oldmask & _MM_MASK_INVALID ) mask |=
kInvalid;
919 if (oldmask & _MM_MASK_DIV_ZERO ) mask |=
kDivByZero;
920 if (oldmask & _MM_MASK_OVERFLOW ) mask |=
kOverflow;
921 if (oldmask & _MM_MASK_UNDERFLOW) mask |=
kUnderflow;
922 if (oldmask & _MM_MASK_INEXACT ) mask |=
kInexact;
925 #if defined(R__MACOSX) && !defined(__SSE2__) && \ 926 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__)) 931 Int_t oldmask = ~oldenv.__fpscr;
932 #elif defined(__arm64__) 933 Int_t oldmask = ~oldenv.__fpcr;
935 Int_t oldmask = ~oldenv.__control;
938 if (oldmask & FE_INVALID ) mask |=
kInvalid;
939 if (oldmask & FE_DIVBYZERO) mask |=
kDivByZero;
940 if (oldmask & FE_OVERFLOW ) mask |=
kOverflow;
941 if (oldmask & FE_UNDERFLOW) mask |=
kUnderflow;
942 if (oldmask & FE_INEXACT ) mask |=
kInexact;
945 #if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \ 946 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \ 951 if (oldmask & FE_ENABLE_INVALID ) mask |=
kInvalid;
952 if (oldmask & FE_ENABLE_DIVBYZERO) mask |=
kDivByZero;
953 if (oldmask & FE_ENABLE_OVERFLOW ) mask |=
kOverflow;
954 if (oldmask & FE_ENABLE_UNDERFLOW) mask |=
kUnderflow;
955 if (oldmask & FE_ENABLE_INEXACT ) mask |=
kInexact;
969 Int_t old = GetFPEMask();
971 #if defined(R__LINUX) && !defined(__powerpc__) 972 #if defined(__GLIBC__) && (__GLIBC__>2 || __GLIBC__==2 && __GLIBC_MINOR__>=1) 974 if (mask &
kInvalid ) newm |= FE_INVALID;
976 if (mask &
kOverflow ) newm |= FE_OVERFLOW;
979 if (mask &
kInexact ) newm |= FE_INEXACT;
982 #if __GLIBC_MINOR__>=3 985 feclearexcept(FE_ALL_EXCEPT);
986 fedisableexcept(FE_ALL_EXCEPT);
987 feenableexcept(newm);
996 cur.__control_word &= ~newm;
1004 #if defined(R__MACOSX) && defined(__SSE2__) 1007 if (mask & kInvalid ) newm |= _MM_MASK_INVALID;
1008 if (mask & kDivByZero) newm |= _MM_MASK_DIV_ZERO;
1009 if (mask & kOverflow ) newm |= _MM_MASK_OVERFLOW;
1010 if (mask & kUnderflow) newm |= _MM_MASK_UNDERFLOW;
1011 if (mask & kInexact ) newm |= _MM_MASK_INEXACT;
1013 _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~newm);
1016 #if defined(R__MACOSX) && !defined(__SSE2__) && \ 1017 (defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__)) 1019 if (mask & kInvalid ) newm |= FE_INVALID;
1020 if (mask & kDivByZero) newm |= FE_DIVBYZERO;
1021 if (mask & kOverflow ) newm |= FE_OVERFLOW;
1022 if (mask & kUnderflow) newm |= FE_UNDERFLOW;
1023 if (mask & kInexact ) newm |= FE_INEXACT;
1027 #if defined(__arm__) 1028 cur.__fpscr &= ~newm;
1029 #elif defined(__arm64__) 1030 cur.__fpcr &= ~newm;
1032 cur.__control &= ~newm;
1037 #if defined(R__MACOSX) && !defined(__SSE2__) && !defined(__xlC__) && \ 1038 !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && \ 1041 if (mask & kInvalid ) newm |= FE_ENABLE_INVALID;
1042 if (mask & kDivByZero) newm |= FE_ENABLE_DIVBYZERO;
1043 if (mask & kOverflow ) newm |= FE_ENABLE_OVERFLOW;
1044 if (mask & kUnderflow) newm |= FE_ENABLE_UNDERFLOW;
1045 if (mask & kInexact ) newm |= FE_ENABLE_INEXACT;
1049 curmask = (curmask & ~FE_ENABLE_ALL_EXCEPT) | newm;
1061 Bool_t pollOnce = pendingOnly;
1070 if (!pendingOnly)
return;
1074 if (fNfd > 0 && fFileHandler && fFileHandler->GetSize() > 0)
1075 if (CheckDescriptors())
1076 if (!pendingOnly)
return;
1079 fWriteready->Zero();
1081 if (pendingOnly && !pollOnce)
1085 if (fSigcnt > 0 && fSignalHandler->GetSize() > 0)
1086 if (CheckSignals(
kTRUE))
1087 if (!pendingOnly)
return;
1093 if (fTimers && fTimers->GetSize() > 0)
1094 if (DispatchTimers(
kTRUE)) {
1096 nextto = NextTimeOut(
kTRUE);
1102 nextto = NextTimeOut(
kTRUE);
1104 if (fFileHandler && fFileHandler->GetSize() == 0)
1111 *fReadready = *fReadmask;
1112 *fWriteready = *fWritemask;
1118 if (mxfd == 0 && nextto == -1)
1121 fNfd = UnixSelect(mxfd, fReadready, fWriteready, nextto);
1122 if (fNfd < 0 && fNfd != -2) {
1125 for (fd = 0; fd < mxfd; fd++) {
1127 if (fReadmask->IsSet(fd)) {
1128 rc = UnixSelect(fd+1, &t, 0, 0);
1129 if (rc < 0 && rc != -2) {
1130 SysError(
"DispatchOneEvent",
"select: read error on %d", fd);
1134 if (fWritemask->IsSet(fd)) {
1135 rc = UnixSelect(fd+1, 0, &t, 0);
1136 if (rc < 0 && rc != -2) {
1137 SysError(
"DispatchOneEvent",
"select: write error on %d", fd);
1138 fWritemask->Clr(fd);
1154 tv.tv_sec = milliSec / 1000;
1155 tv.tv_usec = (milliSec % 1000) * 1000;
1157 select(0, 0, 0, 0, &tv);
1191 rc = UnixSelect(mxfd+1, &rd, &wr, to);
1232 rc = UnixSelect(mxfd+1, &rd, &wr, to);
1260 if (sync == sh->
IsSync()) {
1262 if ((fSignals->IsSet(sig) && sigdone == -1) || sigdone == sig) {
1263 if (sigdone == -1) {
1287 while ((pid = UnixWaitchild()) > 0) {
1288 TIter next(zombieHandler);
1289 register UnixPtty *pty;
1290 while ((pty = (UnixPtty*) next()))
1291 if (pty->GetPid() == pid) {
1292 zombieHandler->RemovePtr(pty);
1311 if ((fd <= fMaxrfd && fReadready->IsSet(fd) && fddone == -1) ||
1312 (fddone == fd && read)) {
1314 fReadready->Clr(fd);
1322 if ((fd <= fMaxwfd && fWriteready->IsSet(fd) && fddone == -1) ||
1323 (fddone == fd && !read)) {
1325 fWriteready->Clr(fd);
1348 TSystem *helper = FindHelper(name);
1352 return UnixMakedir(name);
1360 TSystem *helper = FindHelper(name);
1364 return UnixOpendir(name);
1372 TSystem *helper = FindHelper(0, dirp);
1379 ::closedir((DIR*)dirp);
1387 TSystem *helper = FindHelper(0, dirp);
1392 return UnixGetdirentry(dirp);
1423 return fWdpath.Data();
1433 return std::string(cwd);
1442 Error(
"WorkingDirectory",
"getcwd() failed");
1451 return UnixHomedirectory(userName);
1460 auto res = UnixHomedirectory(userName, path, mydir);
1461 if (res)
return std::string(res);
1462 else return std::string();
1489 char *
b = ConcatFileName(dir ? dir : TempDirectory(), base);
1494 char *arg =
StrDup(base);
1495 int fd = mkstemp(arg);
1503 FILE *fp = fdopen(fd,
"w+");
1505 SysError(
"TempFileName",
"converting filedescriptor (%d)", fd);
1515 if (name.
IsNull() || name ==
".") {
1518 if (dir[strlen(dir) - 1] !=
'/')
1524 if (!dir || !dir[0]) dir =
"/";
1525 else if (dir[strlen(dir) - 1] !=
'/')
1541 TSystem *helper = FindHelper(path);
1545 if (::access(StripOffProto(path,
"file:"), mode) == 0)
1547 GetLastErrorString() = GetError();
1560 if (!AccessPathName(t) && !overwrite)
1563 FILE *from = fopen(f,
"r");
1567 FILE *to = fopen(t,
"w");
1573 const int bufsize = 1024;
1576 while (!ret && !feof(from)) {
1577 size_t numread = fread (buf,
sizeof(
char), bufsize, from);
1578 size_t numwritten = fwrite(buf,
sizeof(
char), numread, to);
1579 if (numread != numwritten)
1594 int ret = ::rename(f, t);
1595 GetLastErrorString() = GetError();
1605 TSystem *helper = FindHelper(path);
1620 TSystem *helper = FindHelper(path);
1624 return UnixFilestat(path, buf);
1639 return UnixFSstat(path,
id, bsize, blocks, bfree);
1648 return ::link(from, to);
1658 return ::symlink((
char*)from, (
char*)to);
1660 return ::symlink(from, to);
1670 TSystem *helper = FindHelper(name);
1672 return helper->
Unlink(name);
1674 #if defined(R__SEEK64) 1675 struct stat64 finfo;
1676 if (lstat64(name, &finfo) < 0)
1679 if (lstat(name, &finfo) < 0)
1683 if (S_ISDIR(finfo.st_mode))
1684 return ::rmdir(name);
1686 return ::unlink(name);
1695 kShellEscape =
'\\',
1696 *kShellStuff =
"(){}<>\"'",
1701 #ifndef G__OLDEXPAND 1711 const char *p, *patbuf = (
const char *)path;
1714 while (*patbuf ==
' ')
1718 for (p = patbuf; *p; p++)
1729 return ExpandFileName(path);
1743 const char *patbuf = (
const char *)patbuf0;
1752 while (*patbuf ==
' ')
1756 for (p = patbuf; *p; p++)
1768 EscChar(patbuf, stuffedPat,
sizeof(stuffedPat), (
char*)kShellStuff, kShellEscape);
1773 if (stuffedPat[0] ==
'~') {
1774 if (stuffedPat[1] !=
'\0' && stuffedPat[1] !=
'/') {
1776 for (p = &stuffedPat[1], q = name; *p && *p !=
'/';)
1779 hd = UnixHomedirectory(name);
1787 hd = UnixHomedirectory(0);
1789 GetLastErrorString() = GetError();
1793 cmd += &stuffedPat[1];
1798 if ((pf = ::popen(cmd.
Data(),
"r")) == 0) {
1799 GetLastErrorString() = GetError();
1809 for (ch = fgetc(pf); ch != EOF && ch !=
' ' && ch !=
'\n'; ch = fgetc(pf)) {
1815 if (cnt == 0 && ch == EOF)
goto again;
1821 if (ch ==
' ' || ch ==
'\t') {
1822 GetLastErrorString() =
"expression ambigous";
1845 if (ExpandPathName(patbuf))
1855 return ::chmod(file, mode);
1863 return ::umask(mask);
1876 t.actime = (time_t)actime;
1877 t.modtime = (time_t)modtime;
1878 return ::utime(file, &t);
1891 show.
Form(
"Which: %s =", wfil.
Data());
1895 if (wfil[0] ==
'/') {
1896 #if defined(R__SEEK64) 1897 struct stat64 finfo;
1898 if (access(wfil.
Data(), mode) == 0 &&
1899 stat64(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1902 if (access(wfil.
Data(), mode) == 0 &&
1903 stat(wfil.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1920 for (
const char* ptr = search; *ptr;) {
1922 if (*ptr !=
'/' && *ptr !=
'$' && *ptr !=
'~')
1924 const char* posEndOfPart = strchr(ptr,
':');
1926 name.
Append(ptr, posEndOfPart - ptr);
1927 ptr = posEndOfPart + 1;
1938 #if defined(R__SEEK64) 1939 struct stat64 finfo;
1940 if (access(name.
Data(), mode) == 0 &&
1941 stat64(name.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1944 if (access(name.
Data(), mode) == 0 &&
1945 stat(name.
Data(), &finfo) == 0 && S_ISREG(finfo.st_mode)) {
1967 if (!user || !user[0])
1970 struct passwd *apwd = getpwnam(user);
1991 if (!group || !group[0])
1994 struct group *grp = getgrnam(group);
2017 static UserInfoCache_t gUserInfo;
2019 UserInfoCache_t::const_iterator iUserInfo = gUserInfo.find(uid);
2020 if (iUserInfo != gUserInfo.end())
2023 struct passwd *apwd = getpwuid(uid);
2036 gUserInfo[uid] = *ug;
2049 return GetUserInfo(GetUid(user));
2061 struct group *grp = getgrgid(gid);
2081 return GetGroupInfo(GetGid(group));
2091 ::setenv(name, value, 1);
2099 return ::getenv(name);
2117 return ::system(shellcmd);
2125 return ::popen(command, mode);
2133 return ::pclose(pipe);
2152 gROOT->EndOfProcessCleanups();
2174 #include <mach/mach.h> 2182 typedef CSTypeRef CSSymbolicatorRef;
2183 typedef CSTypeRef CSSourceInfoRef;
2184 typedef CSTypeRef CSSymbolOwnerRef;
2185 typedef CSTypeRef CSSymbolRef;
2187 CSSymbolicatorRef CSSymbolicatorCreateWithPid(pid_t pid);
2188 CSSourceInfoRef CSSymbolicatorGetSourceInfoWithAddressAtTime(CSSymbolicatorRef cs, vm_address_t addr, uint64_t time);
2189 CSSymbolRef CSSourceInfoGetSymbol(CSSourceInfoRef info);
2190 const char* CSSymbolGetName(CSSymbolRef
sym);
2191 CSSymbolOwnerRef CSSourceInfoGetSymbolOwner(CSSourceInfoRef info);
2192 const char* CSSymbolOwnerGetPath(CSSymbolOwnerRef symbol);
2193 const char* CSSourceInfoGetPath(CSSourceInfoRef info);
2194 int CSSourceInfoGetLineNumber(CSSourceInfoRef info);
2197 void macosx_backtrace() {
2198 void* addrlist[kMAX_BACKTRACE_DEPTH];
2200 int numstacks = backtrace( addrlist,
sizeof( addrlist ) /
sizeof(
void* ));
2202 CSSymbolicatorRef symbolicator = CSSymbolicatorCreateWithPid(getpid());
2205 static const int skipFrames = 2;
2206 for (
int i = skipFrames; i < numstacks; ++i) {
2207 CSSourceInfoRef sourceInfo
2208 = CSSymbolicatorGetSourceInfoWithAddressAtTime(symbolicator,
2209 (vm_address_t)addrlist[i],
2212 CSSymbolOwnerRef symOwner = CSSourceInfoGetSymbolOwner(sourceInfo);
2213 if (
const char* libPath = CSSymbolOwnerGetPath(symOwner)) {
2214 printf(
"[%s]", libPath);
2216 printf(
"[<unknown binary>]");
2219 CSSymbolRef
sym = CSSourceInfoGetSymbol(sourceInfo);
2220 if (
const char* symname = CSSymbolGetName(sym)) {
2221 printf(
" %s %s:%d", symname, CSSourceInfoGetPath(sourceInfo),
2222 (
int)CSSourceInfoGetLineNumber(sourceInfo));
2239 gdbscript = gdbscript.
Strip();
2240 if (gdbscript !=
"") {
2242 fprintf(stderr,
"Root.StacktraceScript %s does not exist\n", gdbscript.
Data());
2248 if (gdbscript ==
"") {
2250 gdbscript.
Form(
"%s/gdb-backtrace.sh", ROOTETCDIR);
2252 gdbscript.
Form(
"%s/etc/gdb-backtrace.sh", Getenv(
"ROOTSYS"));
2255 fprintf(stderr,
"Error in <TUnixSystem::StackTrace> script %s is missing\n", gdbscript.
Data());
2262 gdbmess = gdbmess.
Strip();
2270 int fd = STDERR_FILENO;
2272 const char *message =
" Generating stack trace...\n";
2274 if (fd && message) { }
2277 Getlinem(kCleanUp, 0);
2279 #if defined(USE_GDB_STACK_TRACE) 2282 fprintf(stderr,
"gdb not found, need it for stack trace\n");
2287 TString gdbmessf =
"gdb-message";
2288 if (gdbmess !=
"") {
2289 FILE *
f = TempFileName(gdbmessf);
2290 fprintf(f,
"%s\n", gdbmess.
Data());
2297 gdbscript += GetPid();
2298 if (gdbmess !=
"") {
2300 gdbscript += gdbmessf;
2302 gdbscript +=
" 1>&2";
2307 #elif defined(R__AIX) 2308 TString script =
"procstack ";
2312 #elif defined(R__SOLARIS) 2323 #elif defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_DLADDR) // linux + MacOS X >= 10.5 2331 const char *cppfilt =
"c++filt";
2332 const char *cppfiltarg =
"";
2334 const char *format1 =
" 0x%016lx in %.200s %s 0x%lx from %.200s\n";
2336 const char *format2 =
" 0x%016lx in %.200s\n";
2338 const char *format2 =
" 0x%016lx in %.200s at %.200s from %.200s\n";
2340 const char *format3 =
" 0x%016lx in %.200s from %.200s\n";
2341 const char *format4 =
" 0x%016lx in <unknown function>\n";
2343 const char *format1 =
" 0x%08lx in %.200s %s 0x%lx from %.200s\n";
2345 const char *format2 =
" 0x%08lx in %.200s\n";
2347 const char *format2 =
" 0x%08lx in %.200s at %.200s from %.200s\n";
2349 const char *format3 =
" 0x%08lx in %.200s from %.200s\n";
2350 const char *format4 =
" 0x%08lx in <unknown function>\n";
2362 while (help.
Gets(p)) {
2364 cppfiltarg =
"--format=gnu-v3";
2366 }
else if (help.
Index(
"gnu-new-abi") !=
kNPOS) {
2367 cppfiltarg =
"--format=gnu-new-abi";
2376 #if (defined(R__LINUX) && !defined(R__WINGCC)) 2379 #ifdef PR_SET_PTRACER 2380 prctl(PR_SET_PTRACER, getpid(), 0, 0, 0);
2386 TString gdbmessf =
"gdb-message";
2387 if (gdbmess !=
"") {
2388 FILE *
f = TempFileName(gdbmessf);
2389 fprintf(f,
"%s\n", gdbmess.
Data());
2398 gdbscript += GetPid();
2399 if (gdbmess !=
"") {
2401 gdbscript += gdbmessf;
2403 gdbscript +=
" 1>&2";
2416 if (
write(fd, message, strlen(message)) < 0)
2421 TString tmpf1 =
"gdb-backtrace";
2422 std::ofstream file1;
2424 FILE *
f = TempFileName(tmpf1);
2428 Error(
"StackTrace",
"could not open file %s", tmpf1.
Data());
2440 void *trace[kMAX_BACKTRACE_DEPTH];
2441 int depth = backtrace(trace, kMAX_BACKTRACE_DEPTH);
2442 for (
int n = 5;
n < depth;
n++) {
2446 if (dladdr(trace[
n], &info) && info.dli_fname && info.dli_fname[0]) {
2447 const char *libname = info.dli_fname;
2448 const char *symname = (info.dli_sname && info.dli_sname[0]) ?
2449 info.dli_sname :
"<unknown>";
2452 Bool_t gte = (addr >= symaddr);
2453 ULong_t diff = (gte) ? addr - symaddr : symaddr - addr;
2454 if (addr2line && symaddr) {
2458 #if defined(MAC_OS_X_VERSION_10_10) 2459 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line, GetPid(), addr);
2460 #elif defined(MAC_OS_X_VERSION_10_9) 2462 snprintf(buffer,
sizeof(buffer),
"%s -d -p %d 0x%016lx", addr2line, GetPid(), addr);
2464 snprintf(buffer,
sizeof(buffer),
"%s -p %d 0x%016lx", addr2line, GetPid(), addr);
2467 ULong_t offset = (addr >= libaddr) ? addr - libaddr :
2472 if (name[0] !=
'/') noPath =
kTRUE;
2474 if (noShare) offset = addr;
2475 if (noPath) name =
"`which " + name +
"`";
2476 snprintf(buffer,
sizeof(buffer),
"%s -e %s 0x%016lx", addr2line, name.
Data(), offset);
2478 if (FILE *pf = ::popen(buffer,
"r")) {
2480 if (fgets(buf, 2048, pf)) {
2481 buf[strlen(buf)-1] = 0;
2482 if (strncmp(buf,
"??", 2)) {
2484 snprintf(buffer,
sizeof(buffer), format2, addr, buf);
2486 snprintf(buffer,
sizeof(buffer), format2, addr, symname, buf, libname);
2494 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2495 gte ?
"+" :
"-", diff, libname);
2498 snprintf(buffer,
sizeof(buffer), format1, addr, symname,
2499 gte ?
"+" :
"-", diff, libname);
2501 snprintf(buffer,
sizeof(buffer), format3, addr, symname, libname);
2504 snprintf(buffer,
sizeof(buffer), format4, addr);
2510 if (
write(fd, buffer, ::strlen(buffer)) < 0)
2515 TString tmpf2 =
"gdb-backtrace";
2516 FILE *
f = TempFileName(tmpf2);
2519 snprintf(buffer,
sizeof(buffer),
"%s %s < %s > %s", filter, cppfiltarg, tmpf1.
Data(), tmpf2.
Data());
2521 std::ifstream file2(tmpf2);
2534 delete [] addr2line;
2537 #elif defined(HAVE_EXCPT_H) && defined(HAVE_PDSC_H) && \ 2538 defined(HAVE_RLD_INTERFACE_H) // tru64 2547 exc_capture_context (&context);
2548 while (!rc && context.sc_pc) {
2550 pdsc_crd *
func, *base, *crd
2551 = exc_remote_lookup_function_entry(0, 0, context.sc_pc, 0, &func, &base);
2552 Elf32_Addr addr = PDSC_CRD_BEGIN_ADDRESS(base, func);
2554 const char *
name =
"<unknown function>";
2555 sprintf(buffer,
" 0x%012lx %.200s + 0x%lx\n",
2556 context.sc_pc, name, context.sc_pc - addr);
2557 write(fd, buffer, ::strlen(buffer));
2558 rc = exc_virtual_unwind(0, &context);
2603 ::openlog(name, options, fac);
2613 ::syslog(level,
"%s", mess);
2653 const char *tty = ttyname(STDOUT_FILENO);
2657 if ((xh->
fStdOutDup = dup(STDOUT_FILENO)) < 0) {
2665 const char *tty = ttyname(STDERR_FILENO);
2669 if ((xh->
fStdErrDup = dup(STDERR_FILENO)) < 0) {
2671 if (outdone && dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2672 Warning(
"RedirectOutput",
"could not restore stdout (back to original redirected" 2681 const char *
m = (mode[0] ==
'a' || mode[0] ==
'w') ? mode :
"a";
2694 if (freopen(file, m, stdout) == 0) {
2698 if (freopen(file, m, stderr) == 0) {
2714 if (
close(STDOUT_FILENO) != 0) {
2716 "problems closing STDOUT_FILENO (%d) before 'dup2' (errno: %d)",
2720 if (dup2(xh->
fStdOutDup, STDOUT_FILENO) < 0) {
2721 SysError(
"RedirectOutput",
"could not restore stdout (back to original redirected" 2727 "problems closing temporary 'out' descriptor %d (errno: %d)",
2740 if (
close(STDERR_FILENO) != 0) {
2742 "problems closing STDERR_FILENO (%d) before 'dup2' (errno: %d)",
2746 if (dup2(xh->
fStdErrDup, STDERR_FILENO) < 0) {
2747 SysError(
"RedirectOutput",
"could not restore stderr (back to original redirected" 2753 "problems closing temporary 'err' descriptor %d (errno: %d)",
2798 Error(
"ListSymbols",
"not yet implemented");
2820 if (!linkedLibs.
IsNull())
2826 #if !defined(R__MACOSX) 2832 #if defined(R__MACOSX) 2834 linkedLibs = gLinkedDylibs;
2838 while (otool.
Gets(p)) {
2843 if (!linkedLibs.
IsNull())
2845 linkedLibs += dylib;
2853 #elif defined(R__LINUX) || defined(R__SOLARIS) || defined(R__AIX) 2854 #if defined(R__WINGCC ) 2855 const char *cLDD=
"cygcheck";
2856 const char *cSOEXT=
".dll";
2857 size_t lenexe = strlen(exe);
2858 if (strcmp(exe + lenexe - 4,
".exe")
2859 && strcmp(exe + lenexe - 4,
".dll")) {
2862 char* longerexe =
new char[lenexe + 5];
2863 strlcpy(longerexe, exe,lenexe+5);
2864 strlcat(longerexe,
".exe",lenexe+5);
2868 TRegexp sovers =
"\\.so\\.[0-9]+";
2870 const char *cLDD=
"ldd";
2872 const char *cSOEXT=
".a";
2873 TRegexp sovers =
"\\.a\\.[0-9]+";
2875 const char *cSOEXT=
".so";
2876 TRegexp sovers =
"\\.so\\.[0-9]+";
2882 while (ldd.
Gets(p)) {
2901 if (!linkedLibs.
IsNull())
2903 linkedLibs += solib;
2937 if (!fTimers)
return kFALSE;
2939 fInsideNotify =
kTRUE;
2948 if (mode && t->
IsSync()) {
2951 }
else if (!mode && t->
IsAsync()) {
2953 UnixSetitimer(NextTimeOut(
kFALSE));
2982 UnixSetitimer(NextTimeOut(
kFALSE));
2991 if (!fInsideNotify && ti && ti->
IsAsync())
2992 UnixSetitimer(NextTimeOut(
kFALSE));
3005 struct addrinfo hints;
3006 struct addrinfo *
result, *rp;
3007 memset(&hints, 0,
sizeof(
struct addrinfo));
3008 hints.ai_family = AF_INET;
3009 hints.ai_socktype = 0;
3010 hints.ai_protocol = 0;
3011 hints.ai_flags = AI_CANONNAME;
3014 int rc = getaddrinfo(hostname,
nullptr, &hints, &result);
3016 if (rc == EAI_NONAME) {
3017 if (
gDebug > 0)
Error(
"GetHostByName",
"unknown host '%s'", hostname);
3020 Error(
"GetHostByName",
"getaddrinfo failed for '%s': %s", hostname, gai_strerror(rc));
3026 std::string hostcanon(result->ai_canonname ? result->ai_canonname : hostname);
3028 ia.
fFamily = result->ai_family;
3029 ia.
fAddresses[0] = ntohl(((
struct sockaddr_in *)(result->ai_addr))->sin_addr.s_addr);
3031 if (hostcanon.compare(hostname) != 0) ia.
AddAlias(hostname);
3034 char tmp[
sizeof(
struct in_addr)];
3035 if (inet_pton(AF_INET, hostcanon.data(), tmp) == 1) {
3036 char hbuf[NI_MAXHOST];
3037 if (getnameinfo(result->ai_addr, result->ai_addrlen, hbuf,
sizeof(hbuf),
nullptr, 0, 0) == 0)
3042 rp = result->ai_next;
3043 for (; rp !=
nullptr; rp = rp->ai_next) {
3044 UInt_t arp = ntohl(((
struct sockaddr_in *)(rp->ai_addr))->sin_addr.s_addr);
3049 freeaddrinfo(result);
3058 struct sockaddr addr;
3059 #if defined(USE_SIZE_T) 3060 size_t len =
sizeof(addr);
3061 #elif defined(USE_SOCKLEN_T) 3062 socklen_t len =
sizeof(addr);
3064 int len =
sizeof(addr);
3068 if (getsockname(sock, &addr, &len) == -1) {
3069 SysError(
"GetSockName",
"getsockname failed");
3073 if (addr.sa_family != AF_INET)
return ia;
3075 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3076 ia.
fPort = ntohs(addrin->sin_port);
3077 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3079 char hbuf[NI_MAXHOST];
3080 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3081 Error(
"GetSockName",
"getnameinfo failed");
3094 struct sockaddr addr;
3095 #if defined(USE_SIZE_T) 3096 size_t len =
sizeof(addr);
3097 #elif defined(USE_SOCKLEN_T) 3098 socklen_t len =
sizeof(addr);
3100 int len =
sizeof(addr);
3104 if (getpeername(sock, &addr, &len) == -1) {
3105 SysError(
"GetPeerName",
"getpeername failed");
3109 if (addr.sa_family != AF_INET)
return ia;
3111 struct sockaddr_in *addrin = (
struct sockaddr_in *)&addr;
3112 ia.
fPort = ntohs(addrin->sin_port);
3113 ia.
fAddresses[0] = ntohl(addrin->sin_addr.s_addr);
3115 char hbuf[NI_MAXHOST];
3116 if (getnameinfo(&addr,
sizeof(
struct sockaddr), hbuf,
sizeof(hbuf),
nullptr, 0, 0) != 0) {
3117 Error(
"GetPeerName",
"getnameinfo failed");
3132 if ((sp = getservbyname(servicename,
kProtocolName)) == 0) {
3133 Error(
"GetServiceByName",
"no service \"%s\" with protocol \"%s\"\n",
3137 return ntohs(sp->s_port);
3147 if ((sp = getservbyport(htons(port),
kProtocolName)) == 0) {
3150 return Form(
"%d", port);
3159 int tcpwindowsize,
const char *protocol)
3161 if (!strcmp(servername,
"unix")) {
3162 return UnixUnixConnect(port);
3164 return UnixUnixConnect(servername);
3167 if (!strcmp(protocol,
"udp")){
3168 return UnixUdpConnect(servername, port);
3171 return UnixTcpConnect(servername, port, tcpwindowsize);
3184 return ConnectService(server, port, tcpwindowsize, protocol);
3201 return UnixTcpService(port, reuse, backlog, tcpwindowsize);
3209 return UnixUdpService(port, backlog);
3217 return UnixUnixService(port, backlog);
3225 return UnixUnixService(sockpath, backlog);
3237 while ((soc = ::accept(sock, 0, 0)) == -1 &&
GetErrno() == EINTR)
3244 SysError(
"AcceptConnection",
"accept");
3257 if (sock < 0)
return;
3259 #if !defined(R__AIX) || defined(_AIX41) || defined(_AIX43) 3261 ::shutdown(sock, 2);
3277 if (UnixRecv(sock, &header,
sizeof(header), 0) > 0) {
3278 int count = ntohl(header);
3280 if (count > length) {
3281 Error(
"RecvBuf",
"record header exceeds buffer size");
3283 }
else if (count > 0) {
3284 if (UnixRecv(sock, buf, count, 0) < 0) {
3285 Error(
"RecvBuf",
"cannot receive buffer");
3300 Int_t header = htonl(length);
3302 if (UnixSend(sock, &header,
sizeof(header), 0) < 0) {
3303 Error(
"SendBuf",
"cannot send header");
3307 if (UnixSend(sock, buf, length, 0) < 0) {
3308 Error(
"SendBuf",
"cannot send buffer");
3348 if ((n = UnixRecv(sock, buf, length, flag)) <= 0) {
3349 if (n == -1 &&
GetErrno() != EINTR)
3350 Error(
"RecvRaw",
"cannot receive buffer");
3383 if ((n = UnixSend(sock, buf, length, flag)) <= 0) {
3384 if (n == -1 &&
GetErrno() != EINTR)
3385 Error(
"SendRaw",
"cannot send buffer");
3396 if (sock < 0)
return -1;
3400 if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)&val,
sizeof(val)) == -1) {
3401 SysError(
"SetSockOpt",
"setsockopt(SO_SNDBUF)");
3406 if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)&val,
sizeof(val)) == -1) {
3407 SysError(
"SetSockOpt",
"setsockopt(SO_RCVBUF)");
3412 if (setsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)&val,
sizeof(val)) == -1) {
3413 SysError(
"SetSockOpt",
"setsockopt(SO_OOBINLINE)");
3418 if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)&val,
sizeof(val)) == -1) {
3419 SysError(
"SetSockOpt",
"setsockopt(SO_KEEPALIVE)");
3424 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)&val,
sizeof(val)) == -1) {
3425 SysError(
"SetSockOpt",
"setsockopt(SO_REUSEADDR)");
3430 if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)&val,
sizeof(val)) == -1) {
3431 SysError(
"SetSockOpt",
"setsockopt(TCP_NODELAY)");
3436 if (ioctl(sock, FIONBIO, (
char*)&val) == -1) {
3437 SysError(
"SetSockOpt",
"ioctl(FIONBIO)");
3443 if (ioctl(sock, SIOCSPGRP, (
char*)&val) == -1) {
3444 SysError(
"SetSockOpt",
"ioctl(SIOCSPGRP)");
3448 Error(
"SetSockOpt",
"ioctl(SIOCGPGRP) not supported on cygwin/gcc");
3455 Error(
"SetSockOpt",
"illegal option (%d)", opt);
3466 if (sock < 0)
return -1;
3468 #if defined(USE_SOCKLEN_T) || defined(_AIX43) 3469 socklen_t optlen =
sizeof(*val);
3470 #elif defined(USE_SIZE_T) 3471 size_t optlen =
sizeof(*val);
3473 int optlen =
sizeof(*val);
3478 if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (
char*)val, &optlen) == -1) {
3479 SysError(
"GetSockOpt",
"getsockopt(SO_SNDBUF)");
3484 if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (
char*)val, &optlen) == -1) {
3485 SysError(
"GetSockOpt",
"getsockopt(SO_RCVBUF)");
3490 if (getsockopt(sock, SOL_SOCKET, SO_OOBINLINE, (
char*)val, &optlen) == -1) {
3491 SysError(
"GetSockOpt",
"getsockopt(SO_OOBINLINE)");
3496 if (getsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (
char*)val, &optlen) == -1) {
3497 SysError(
"GetSockOpt",
"getsockopt(SO_KEEPALIVE)");
3502 if (getsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (
char*)val, &optlen) == -1) {
3503 SysError(
"GetSockOpt",
"getsockopt(SO_REUSEADDR)");
3508 if (getsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (
char*)val, &optlen) == -1) {
3509 SysError(
"GetSockOpt",
"getsockopt(TCP_NODELAY)");
3515 if ((flg = fcntl(sock, F_GETFL, 0)) == -1) {
3516 SysError(
"GetSockOpt",
"fcntl(F_GETFL)");
3519 *val = flg & O_NDELAY;
3522 #if !defined(R__LYNXOS) && !defined(R__WINGCC) 3523 if (ioctl(sock, SIOCGPGRP, (
char*)val) == -1) {
3524 SysError(
"GetSockOpt",
"ioctl(SIOCGPGRP)");
3528 Error(
"GetSockOpt",
"ioctl(SIOCGPGRP) not supported on LynxOS and cygwin/gcc");
3533 #if !defined(R__LYNXOS) 3534 if (ioctl(sock, SIOCATMARK, (
char*)val) == -1) {
3535 SysError(
"GetSockOpt",
"ioctl(SIOCATMARK)");
3539 Error(
"GetSockOpt",
"ioctl(SIOCATMARK) not supported on LynxOS");
3544 #if !defined(R__LYNXOS) 3545 if (ioctl(sock, FIONREAD, (
char*)val) == -1) {
3546 SysError(
"GetSockOpt",
"ioctl(FIONREAD)");
3550 Error(
"GetSockOpt",
"ioctl(FIONREAD) not supported on LynxOS");
3555 Error(
"GetSockOpt",
"illegal option (%d)", opt);
3570 static struct Signalmap_t {
3573 struct sigaction *fOldHandler;
3574 const char *fSigName;
3576 { SIGBUS, 0, 0,
"bus error" },
3577 { SIGSEGV, 0, 0,
"segmentation violation" },
3578 { SIGSYS, 0, 0,
"bad argument to system call" },
3579 { SIGPIPE, 0, 0,
"write on a pipe with no one to read it" },
3580 { SIGILL, 0, 0,
"illegal instruction" },
3581 { SIGQUIT, 0, 0,
"quit" },
3582 { SIGINT, 0, 0,
"interrupt" },
3583 { SIGWINCH, 0, 0,
"window size change" },
3584 { SIGALRM, 0, 0,
"alarm clock" },
3585 { SIGCHLD, 0, 0,
"death of a child" },
3586 { SIGURG, 0, 0,
"urgent data arrived on an I/O channel" },
3587 { SIGFPE, 0, 0,
"floating point exception" },
3588 { SIGTERM, 0, 0,
"termination signal" },
3589 { SIGUSR1, 0, 0,
"user-defined signal 1" },
3590 { SIGUSR2, 0, 0,
"user-defined signal 2" }
3623 Break(
"TUnixSystem::DispatchSignals",
"%s", UnixSigname(sig));
3635 Break(
"TUnixSystem::DispatchSignals",
"%s", UnixSigname(sig));
3647 if (fSigcnt > 0 && fSignalHandler->GetSize() > 0)
3660 struct sigaction sigact;
3663 gSignalMap[sig].fOldHandler =
new struct sigaction();
3667 #elif defined(R__SOLARIS) 3669 #elif defined(R__LYNXOS) 3678 sigemptyset(&sigact.sa_mask);
3679 sigact.sa_flags = 0;
3680 #if defined(SA_RESTART) 3681 sigact.sa_flags |= SA_RESTART;
3683 if (sigaction(
gSignalMap[sig].fCode, &sigact,
3685 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3696 TTHREAD_TLS_ARRAY(
struct sigaction,
kMAXSIGNALS,oldsigact);
3698 if (ignore != ignoreSig[sig]) {
3699 ignoreSig[sig] = ignore;
3701 struct sigaction sigact;
3703 sigact.sa_handler = (
void (*)())SIG_IGN;
3704 #elif defined(R__SOLARIS) 3705 sigact.sa_handler = (
void (*)(int))SIG_IGN;
3707 sigact.sa_handler = SIG_IGN;
3709 sigemptyset(&sigact.sa_mask);
3710 sigact.sa_flags = 0;
3711 if (sigaction(
gSignalMap[sig].fCode, &sigact, &oldsigact[sig]) < 0)
3712 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3714 if (sigaction(
gSignalMap[sig].fCode, &oldsigact[sig], 0) < 0)
3715 ::SysError(
"TUnixSystem::UnixIgnoreSignal",
"sigaction");
3731 struct sigaction sigact;
3734 #elif defined(R__SOLARIS) 3736 #elif defined(R__LYNXOS) 3745 sigemptyset(&sigact.sa_mask);
3746 sigact.sa_flags = 0;
3748 #if defined(SA_INTERRUPT) // SunOS 3749 sigact.sa_flags |= SA_INTERRUPT;
3752 #if defined(SA_RESTART) 3753 sigact.sa_flags |= SA_RESTART;
3757 ::SysError(
"TUnixSystem::UnixSigAlarmInterruptsSyscalls",
"sigaction");
3777 ::SysError(
"TUnixSystem::UnixSignal",
"sigaction");
3800 static std::atomic<time_t> jan95{0};
3811 jan95 = mktime(&tp);
3812 if ((
int)jan95 == -1) {
3813 ::SysError(
"TUnixSystem::UnixNow",
"error converting 950001 0:00 to time_t");
3819 gettimeofday(&t, 0);
3828 struct itimerval itv;
3829 itv.it_value.tv_sec = 0;
3830 itv.it_value.tv_usec = 0;
3831 itv.it_interval.tv_sec = 0;
3832 itv.it_interval.tv_usec = 0;
3834 itv.it_value.tv_sec = time_t(ms / 1000);
3835 itv.it_value.tv_usec = time_t((ms % 1000) * 1000);
3837 int st = setitimer(ITIMER_REAL, &itv, 0);
3839 ::SysError(
"TUnixSystem::UnixSetitimer",
"setitimer");
3857 fd_set *rd = (readready) ? (fd_set*)readready->GetBits() : 0;
3858 fd_set *wr = (writeready) ? (fd_set*)writeready->GetBits() : 0;
3862 tv.tv_sec =
Int_t(timeout / 1000);
3863 tv.tv_usec = (timeout % 1000) * 1000;
3864 retcode = select(nfds, rd, wr, 0, &tv);
3866 retcode = select(nfds, rd, wr, 0, 0);
3868 if (retcode == -1) {
3889 return UnixHomedirectory(name, path, mydir);
3899 pw = getpwnam(name);
3908 pw = getpwuid(getuid());
3929 return ::mkdir(StripOffProto(dir,
"file:"), 0755);
3939 const char *edir = StripOffProto(dir,
"file:");
3941 if (stat(edir, &finfo) < 0)
3944 if (!S_ISDIR(finfo.st_mode))
3947 return (
void*) opendir(edir);
3950 #if defined(_POSIX_SOURCE) 3953 # define REAL_DIR_ENTRY(dp) 1 3955 # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0) 3963 DIR *dirp = (DIR*)dirp1;
3992 const char *path = StripOffProto(fpath,
"file:");
3995 #if defined(R__SEEK64) 3997 if (path && lstat64(path, &sbuf) == 0) {
4000 if (path && lstat(path, &sbuf) == 0) {
4002 buf.
fIsLink = S_ISLNK(sbuf.st_mode);
4004 #if defined(R__SEEK64) 4005 if (stat64(path, &sbuf) == -1) {
4007 if (stat(path, &sbuf) == -1) {
4012 buf.
fDev = sbuf.st_dev;
4013 buf.
fIno = sbuf.st_ino;
4014 buf.
fMode = sbuf.st_mode;
4015 buf.
fUid = sbuf.st_uid;
4016 buf.
fGid = sbuf.st_gid;
4017 buf.
fSize = sbuf.st_size;
4018 buf.
fMtime = sbuf.st_mtime;
4037 struct statfs statfsbuf;
4038 #if (defined(R__SOLARIS) && !defined(R__LINUX)) 4039 if (statfs(path, &statfsbuf,
sizeof(
struct statfs), 0) == 0) {
4040 *
id = statfsbuf.f_fstyp;
4041 *bsize = statfsbuf.f_bsize;
4042 *blocks = statfsbuf.f_blocks;
4043 *bfree = statfsbuf.f_bfree;
4045 if (statfs((
char*)path, &statfsbuf) == 0) {
4051 if (!strcmp(statfsbuf.f_fstypename, MOUNT_FFS) ||
4052 !strcmp(statfsbuf.f_fstypename, MOUNT_MFS))
4054 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NFS))
4056 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_MSDOS))
4058 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_PROCFS))
4060 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_EXT2FS))
4062 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_CD9660))
4064 else if (!strcmp(statfsbuf.f_fstypename, MOUNT_NCPFS))
4069 *
id = statfsbuf.f_type;
4071 *bsize = statfsbuf.f_bsize;
4072 *blocks = statfsbuf.f_blocks;
4073 *bfree = statfsbuf.f_bavail;
4086 return (
int) waitpid(0, &status, WNOHANG);
4107 sport = htons(port);
4110 if (!addr.
IsValid())
return -1;
4113 struct sockaddr_in server;
4114 memset(&server, 0,
sizeof(server));
4115 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4117 server.sin_port = sport;
4121 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4122 ::SysError(
"TUnixSystem::UnixTcpConnect",
"socket (%s:%d)",
4127 if (tcpwindowsize > 0) {
4132 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4136 ::SysError(
"TUnixSystem::UnixTcpConnect",
"connect (%s:%d)",
4158 sport = htons(port);
4161 if (!addr.
IsValid())
return -1;
4164 struct sockaddr_in server;
4165 memset(&server, 0,
sizeof(server));
4166 memcpy(&server.sin_addr, &adr,
sizeof(adr));
4168 server.sin_port = sport;
4172 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4173 ::SysError(
"TUnixSystem::UnixUdpConnect",
"socket (%s:%d)",
4178 while (connect(sock, (
struct sockaddr*) &server,
sizeof(server)) == -1) {
4182 ::SysError(
"TUnixSystem::UnixUdpConnect",
"connect (%s:%d)",
4204 if (!sockpath || strlen(sockpath) <= 0) {
4205 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket path undefined");
4210 struct sockaddr_un unserver;
4211 unserver.sun_family = AF_UNIX;
4213 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4214 ::Error(
"TUnixSystem::UnixUnixConnect",
"socket path %s, longer than max allowed length (%u)",
4215 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4218 strcpy(unserver.sun_path, sockpath);
4221 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4222 ::SysError(
"TUnixSystem::UnixUnixConnect",
"socket");
4226 while (connect(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2) == -1) {
4230 ::SysError(
"TUnixSystem::UnixUnixConnect",
"connect");
4253 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4254 short sport, tryport = kSOCKET_MINPORT;
4257 if (port == 0 && reuse) {
4258 ::Error(
"TUnixSystem::UnixTcpService",
"cannot do a port scan while reuse is true");
4265 sport = htons(port);
4269 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
4270 ::SysError(
"TUnixSystem::UnixTcpService",
"socket");
4277 if (tcpwindowsize > 0) {
4282 struct sockaddr_in inserver;
4283 memset(&inserver, 0,
sizeof(inserver));
4284 inserver.sin_family = AF_INET;
4285 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4286 inserver.sin_port = sport;
4290 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4291 ::SysError(
"TUnixSystem::UnixTcpService",
"bind");
4298 inserver.sin_port = htons(tryport);
4299 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4301 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4303 ::SysError(
"TUnixSystem::UnixTcpService",
"bind (port scan)");
4310 if (::listen(sock, backlog)) {
4311 ::SysError(
"TUnixSystem::UnixTcpService",
"listen");
4328 const short kSOCKET_MINPORT = 5000, kSOCKET_MAXPORT = 15000;
4329 short sport, tryport = kSOCKET_MINPORT;
4335 sport = htons(port);
4339 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
4340 ::SysError(
"TUnixSystem::UnixUdpService",
"socket");
4344 struct sockaddr_in inserver;
4345 memset(&inserver, 0,
sizeof(inserver));
4346 inserver.sin_family = AF_INET;
4347 inserver.sin_addr.s_addr = htonl(INADDR_ANY);
4348 inserver.sin_port = sport;
4352 if (::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver))) {
4353 ::SysError(
"TUnixSystem::UnixUdpService",
"bind");
4360 inserver.sin_port = htons(tryport);
4361 bret = ::bind(sock, (
struct sockaddr*) &inserver,
sizeof(inserver));
4363 }
while (bret < 0 &&
GetErrno() == EADDRINUSE && tryport < kSOCKET_MAXPORT);
4365 ::SysError(
"TUnixSystem::UnixUdpService",
"bind (port scan)");
4372 if (::listen(sock, backlog)) {
4373 ::SysError(
"TUnixSystem::UnixUdpService",
"listen");
4390 oldumask = umask(0);
4402 unlink(sockpath.
Data());
4404 return UnixUnixService(sockpath, backlog);
4413 if (!sockpath || strlen(sockpath) <= 0) {
4414 ::SysError(
"TUnixSystem::UnixUnixService",
"socket path undefined");
4418 struct sockaddr_un unserver;
4422 memset(&unserver, 0,
sizeof(unserver));
4423 unserver.sun_family = AF_UNIX;
4425 if (strlen(sockpath) >
sizeof(unserver.sun_path)-1) {
4426 ::Error(
"TUnixSystem::UnixUnixService",
"socket path %s, longer than max allowed length (%u)",
4427 sockpath, (
UInt_t)
sizeof(unserver.sun_path)-1);
4430 strcpy(unserver.sun_path, sockpath);
4433 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
4434 ::SysError(
"TUnixSystem::UnixUnixService",
"socket");
4438 if (::bind(sock, (
struct sockaddr*) &unserver, strlen(unserver.sun_path)+2)) {
4439 ::SysError(
"TUnixSystem::UnixUnixService",
"bind");
4445 if (::listen(sock, backlog)) {
4446 ::SysError(
"TUnixSystem::UnixUnixService",
"listen");
4465 if (sock < 0)
return -1;
4472 if (flag == MSG_PEEK)
4476 char *buf = (
char *)buffer;
4478 for (n = 0; n < length; n += nrecv) {
4479 if ((nrecv = recv(sock, buf+n, length-n, flag)) <= 0) {
4482 if (flag == MSG_OOB) {
4492 ::
SysError(
"TUnixSystem::UnixRecv",
"recv");
4513 if (sock < 0)
return -1;
4522 const char *buf = (
const char *)buffer;
4524 for (n = 0; n < length; n += nsent) {
4525 if ((nsent = send(sock, buf+n, length-n, flag)) <= 0) {
4532 ::
SysError(
"TUnixSystem::UnixSend",
"send");
4563 }
else if (reset || !initialized) {
4564 initialized =
kTRUE;
4569 rdynpath =
".:"; rdynpath += ROOTLIBDIR;
4571 rdynpath =
".:"; rdynpath +=
gRootDir; rdynpath +=
"/lib";
4575 #if defined (R__AIX) 4577 #elif defined(R__MACOSX) 4591 dynpath = ldpath; dynpath +=
":"; dynpath += rdynpath;
4595 if (!dynpath.
Contains(ROOTLIBDIR)) {
4596 dynpath +=
":"; dynpath += ROOTLIBDIR;
4600 dynpath +=
":"; dynpath +=
gRootDir; dynpath +=
"/lib";
4608 #if defined(R__WINGCC) || defined(R__MACOSX) 4609 if (!dynpath.
EndsWith(
":")) dynpath +=
":";
4610 dynpath +=
"/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:";
4611 dynpath +=
"/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:";
4614 std::string cmd(
"LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls 2>&1");
4615 FILE *pf = popen(cmd.c_str (),
"r");
4619 if (fgets(buffer, 128, pf) !=
NULL)
4623 std::size_t from = result.find(
"search path=", result.find(
"(LD_LIBRARY_PATH)"));
4624 std::size_t to = result.find(
"(system search path)");
4625 if (from != std::string::npos && to != std::string::npos) {
4627 std::string sys_path = result.substr(from, to-from);
4628 sys_path.erase(std::remove_if(sys_path.begin(), sys_path.end(), isspace), sys_path.end());
4629 if (!dynpath.
EndsWith(
":")) dynpath +=
":";
4630 dynpath += sys_path.c_str();
4634 if (
gDebug > 0) std::cout <<
"dynpath = " << dynpath.
Data() << std::endl;
4680 char buf[PATH_MAX + 1];
4681 char *res = realpath(sLib.
Data(), buf);
4682 if (res) sLib = buf;
4688 const char* lib = sLib.
Data();
4690 if (len > 3 && (!strcmp(lib+len-3,
".so") ||
4691 !strcmp(lib+len-3,
".dl") ||
4692 !strcmp(lib+len-4,
".dll") ||
4693 !strcmp(lib+len-4,
".DLL") ||
4694 !strcmp(lib+len-6,
".dylib") ||
4695 !strcmp(lib+len-3,
".sl") ||
4696 !strcmp(lib+len-2,
".a"))) {
4701 Error(
"FindDynamicLibrary",
4702 "%s does not exist in %s", searchFor.
Data(), GetDynamicPath());
4705 static const char* exts[] = {
4706 ".so",
".dll",
".dylib",
".sl",
".dl",
".a", 0 };
4707 const char** ext = exts;
4719 Error(
"FindDynamicLibrary",
4720 "%s[.so | .dll | .dylib | .sl | .dl | .a] does not exist in %s",
4721 searchFor.
Data(), GetDynamicPath());
4728 #if defined(R__MACOSX) 4729 #include <sys/resource.h> 4730 #include <mach/mach.h> 4731 #include <mach/mach_error.h> 4736 static void GetDarwinSysInfo(
SysInfo_t *sysinfo)
4738 FILE *p =
gSystem->
OpenPipe(
"sysctl -n kern.ostype hw.model hw.ncpu hw.cpufrequency " 4739 "hw.busfrequency hw.l2cachesize hw.memsize",
"r");
4772 static void ReadDarwinCpu(
long *ticks)
4774 mach_msg_type_number_t count;
4776 host_cpu_load_info_data_t cpu;
4778 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
4780 count = HOST_CPU_LOAD_INFO_COUNT;
4781 kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&cpu, &count);
4782 if (kr != KERN_SUCCESS) {
4783 ::Error(
"TUnixSystem::ReadDarwinCpu",
"host_statistics: %s", mach_error_string(kr));
4785 ticks[0] = cpu.cpu_ticks[CPU_STATE_USER];
4786 ticks[1] = cpu.cpu_ticks[CPU_STATE_SYSTEM];
4787 ticks[2] = cpu.cpu_ticks[CPU_STATE_IDLE];
4788 ticks[3] = cpu.cpu_ticks[CPU_STATE_NICE];
4796 static void GetDarwinCpuInfo(
CpuInfo_t *cpuinfo,
Int_t sampleTime)
4799 if (getloadavg(avg,
sizeof(avg)) < 0) {
4800 ::Error(
"TUnixSystem::GetDarwinCpuInfo",
"getloadavg failed");
4807 Long_t cpu_ticks1[4], cpu_ticks2[4];
4808 ReadDarwinCpu(cpu_ticks1);
4810 ReadDarwinCpu(cpu_ticks2);
4812 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
4813 (cpu_ticks1[0] + cpu_ticks1[3]);
4814 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
4815 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
4816 if (userticks < 0) userticks = 0;
4817 if (systicks < 0) systicks = 0;
4818 if (idleticks < 0) idleticks = 0;
4819 Long_t totalticks = userticks + systicks + idleticks;
4831 static void GetDarwinMemInfo(
MemInfo_t *meminfo)
4833 static Int_t pshift = 0;
4835 vm_statistics_data_t vm_info;
4836 mach_msg_type_number_t count;
4841 count = HOST_VM_INFO_COUNT;
4842 kr = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_info, &count);
4843 if (kr != KERN_SUCCESS) {
4844 ::Error(
"TUnixSystem::GetDarwinMemInfo",
"host_statistics: %s", mach_error_string(kr));
4848 for (
int psize = getpagesize(); psize > 1; psize >>= 1)
4852 used = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.wire_count) << pshift;
4853 free = (
Long64_t)(vm_info.free_count) << pshift;
4854 total = (
Long64_t)(vm_info.active_count + vm_info.inactive_count + vm_info.free_count + vm_info.wire_count) << pshift;
4857 swap_used = vm_info.pageouts << pshift;
4860 dirp = opendir(
"/private/var/vm");
4865 while ((dp = readdir(dirp)) != 0) {
4867 char fname [MAXNAMLEN];
4868 if (strncmp(dp->d_name,
"swapfile", 8))
4870 strlcpy(fname,
"/private/var/vm/",MAXNAMLEN);
4871 strlcat (fname, dp->d_name,MAXNAMLEN);
4872 if (stat(fname, &sb) < 0)
4874 swap_total += sb.st_size;
4894 static void GetDarwinProcInfo(
ProcInfo_t *procinfo)
4897 #define vm_region vm_region_64 4901 #define GLOBAL_SHARED_TEXT_SEGMENT 0x90000000U 4902 #define GLOBAL_SHARED_DATA_SEGMENT 0xA0000000U 4903 #define SHARED_TEXT_REGION_SIZE 0x10000000 4904 #define SHARED_DATA_REGION_SIZE 0x10000000 4907 if (getrusage(RUSAGE_SELF, &ru) < 0) {
4908 ::SysError(
"TUnixSystem::GetDarwinProcInfo",
"getrusage failed");
4911 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
4913 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
4916 task_basic_info_data_t ti;
4917 mach_msg_type_number_t count;
4920 task_t a_task = mach_task_self();
4922 count = TASK_BASIC_INFO_COUNT;
4923 kr = task_info(a_task, TASK_BASIC_INFO, (task_info_t)&ti, &count);
4924 if (kr != KERN_SUCCESS) {
4925 ::Error(
"TUnixSystem::GetDarwinProcInfo",
"task_info: %s", mach_error_string(kr));
4930 mach_port_t object_name;
4931 vm_address_t address;
4932 vm_region_top_info_data_t info;
4933 vm_size_t vsize, vprvt, rsize, size;
4934 rsize = ti.resident_size;
4935 vsize = ti.virtual_size;
4937 for (address = 0; ; address += size) {
4939 count = VM_REGION_TOP_INFO_COUNT;
4940 if (vm_region(a_task, &address, &size,
4941 VM_REGION_TOP_INFO, (vm_region_info_t)&info, &count,
4942 &object_name) != KERN_SUCCESS) {
4947 if (address >= GLOBAL_SHARED_TEXT_SEGMENT &&
4948 address < (GLOBAL_SHARED_DATA_SEGMENT + SHARED_DATA_REGION_SIZE)) {
4953 if (info.share_mode == SM_EMPTY) {
4954 vm_region_basic_info_data_64_t b_info;
4955 count = VM_REGION_BASIC_INFO_COUNT_64;
4956 if (vm_region_64(a_task, &address,
4957 &size, VM_REGION_BASIC_INFO,
4958 (vm_region_info_t)&b_info, &count,
4959 &object_name) != KERN_SUCCESS) {
4963 if (b_info.reserved) {
4964 vsize -= (SHARED_TEXT_REGION_SIZE + SHARED_DATA_REGION_SIZE);
4971 if (info.share_mode != SM_PRIVATE) {
4975 switch (info.share_mode) {
4977 if (info.ref_count == 1) {
4980 vprvt += info.private_pages_resident * getpagesize();
5000 #if defined(R__LINUX) 5004 static void GetLinuxSysInfo(
SysInfo_t *sysinfo)
5007 FILE *
f = fopen(
"/proc/cpuinfo",
"r");
5031 f = fopen(
"/proc/meminfo",
"r");
5056 static void ReadLinuxCpu(
long *ticks)
5058 ticks[0] = ticks[1] = ticks[2] = ticks[3] = 0;
5061 FILE *
f = fopen(
"/proc/stat",
"r");
5065 sscanf(s.
Data(),
"%*s %ld %ld %ld %ld", &ticks[0], &ticks[3], &ticks[1], &ticks[2]);
5073 static void GetLinuxCpuInfo(
CpuInfo_t *cpuinfo,
Int_t sampleTime)
5075 Double_t avg[3] = { -1., -1., -1. };
5077 if (getloadavg(avg,
sizeof(avg)) < 0) {
5078 ::Error(
"TUnixSystem::GetLinuxCpuInfo",
"getloadavg failed");
5087 Long_t cpu_ticks1[4], cpu_ticks2[4];
5088 ReadLinuxCpu(cpu_ticks1);
5090 ReadLinuxCpu(cpu_ticks2);
5092 Long_t userticks = (cpu_ticks2[0] + cpu_ticks2[3]) -
5093 (cpu_ticks1[0] + cpu_ticks1[3]);
5094 Long_t systicks = cpu_ticks2[1] - cpu_ticks1[1];
5095 Long_t idleticks = cpu_ticks2[2] - cpu_ticks1[2];
5096 if (userticks < 0) userticks = 0;
5097 if (systicks < 0) systicks = 0;
5098 if (idleticks < 0) idleticks = 0;
5099 Long_t totalticks = userticks + systicks + idleticks;
5111 static void GetLinuxMemInfo(
MemInfo_t *meminfo)
5114 FILE *
f = fopen(
"/proc/meminfo",
"r");
5143 static void GetLinuxProcInfo(
ProcInfo_t *procinfo)
5146 if (getrusage(RUSAGE_SELF, &ru) < 0) {
5147 ::SysError(
"TUnixSystem::GetLinuxProcInfo",
"getrusage failed");
5150 ((
Float_t)(ru.ru_utime.tv_usec) / 1000000.);
5152 ((
Float_t)(ru.ru_stime.tv_usec) / 1000000.);
5163 sscanf(s.
Data(),
"%ld %ld", &
total, &rss);
5164 procinfo->
fMemVirtual = total * (getpagesize() / 1024);
5177 if (!info)
return -1;
5181 if (!sysinfo.
fCpus) {
5182 #if defined(R__MACOSX) 5183 GetDarwinSysInfo(&sysinfo);
5184 #elif defined(R__LINUX) 5185 GetLinuxSysInfo(&sysinfo);
5201 if (!info)
return -1;
5203 #if defined(R__MACOSX) 5204 GetDarwinCpuInfo(info, sampleTime);
5205 #elif defined(R__LINUX) 5206 GetLinuxCpuInfo(info, sampleTime);
5218 if (!info)
return -1;
5220 #if defined(R__MACOSX) 5221 GetDarwinMemInfo(info);
5222 #elif defined(R__LINUX) 5223 GetLinuxMemInfo(info);
5235 if (!info)
return -1;
5237 #if defined(R__MACOSX) 5238 GetDarwinProcInfo(info);
5239 #elif defined(R__LINUX) 5240 GetLinuxProcInfo(info);
Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
void(* SigHandler_t)(ESignals)
int GetPid()
Get process id.
virtual const char * GetSTLIncludePath() const
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
int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const
Returns cpu load average and load info into the CpuInfo_t structure.
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.
int GetErrno()
return errno
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.
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()
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
const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
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.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
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.
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.
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
TObject * At(Int_t idx) const
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 ...
void FillWithCwd(char *cwd) const
Fill buffer with current working directory.
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.
void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
int Unlink(const char *name)
Unlink, i.e.
const char * kProtocolName
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.
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.
virtual Bool_t Notify()
Notify when signal occurs.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
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.
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.
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.
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)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
int AcceptConnection(int sock)
Accept a connection.
virtual void Unload(const char *module)
Unload a shared library.
Long64_t Atoll() const
Return long long value of string.
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 Error(const char *location, const char *msgfmt,...)
void ResetSignals()
Reset signals handlers to previous behaviour.
int SetSockOpt(int sock, int option, int val)
Set socket option.
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
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.
int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
void FreeDirectory(void *dirp)
Close a Unix file system directory.
void ResetErrno()
reset errno
virtual void Setenv(const char *name, const char *value)
Set environment variable.
virtual Bool_t HasWriteInterest()
True if handler is interested in write events.
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
UInt_t GetAddress() const
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.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual void SetReadReady()
void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket.
std::string GetHomeDirectory(const char *userName=0) const
Return the user's home directory.
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,...)
ESignals GetSignal() const
void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Handles synchronous and a-synchronous timer events.
Bool_t CheckTimer(const TTime &now)
Check if timer timed out.
std::string GetWorkingDirectory() const
Return working directory.
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
Func_t DynFindSymbol(const char *module, const char *entry)
dynamic linking of module
static int UnixWaitchild()
Wait till child is finished.
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...
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.
void Warning(const char *location, const char *msgfmt,...)
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.
Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
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.
#define R__LOCKGUARD2(mutex)
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.
static unsigned int total
TString & Remove(Ssiz_t pos)
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.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
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)
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.
static int UnixTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize)
Open a socket, bind to it and start listening for TCP/IP connections on the port. ...
int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
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.
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.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
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.
#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.
static const char * UnixGetdirentry(void *dir)
Returns the next directory entry.
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
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)
const char * GetDirEntry(void *dirp)
Get next Unix file system directory entry. Returns 0 if no more entries.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
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_t Atoi() const
Return integer value of string.
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.
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
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.
void Openlog(const char *name, Int_t options, ELogFacility facility)
Open connection to system log daemon.
R__EXTERN TInterpreter * gCling
virtual const char * GetName() const
Returns name of object.
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.
#define sym(otri1, otri2)
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.
const char * Data() const
int AnnounceUdpService(int port, int backlog)
Announce UDP service.
int GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.