File indexing completed on 2025-01-18 10:12:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TSystem
0013 #define ROOT_TSystem
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include <cstdio>
0026 #include <cctype>
0027 #include <fcntl.h>
0028 #ifndef _WIN32
0029 #include <unistd.h>
0030 #endif
0031
0032 #include "TNamed.h"
0033 #include "TInetAddress.h"
0034 #include "TTimer.h"
0035 #include <string>
0036
0037 class TSeqCollection;
0038 class TFdSet;
0039 class TVirtualMutex;
0040
0041 enum EAccessMode {
0042 kFileExists = 0,
0043 kExecutePermission = 1,
0044 kWritePermission = 2,
0045 kReadPermission = 4
0046 };
0047
0048 enum ELogOption {
0049 kLogPid = 0x01,
0050 kLogCons = 0x02
0051 };
0052
0053 enum ELogLevel {
0054 kLogEmerg = 0,
0055 kLogAlert = 1,
0056 kLogCrit = 2,
0057 kLogErr = 3,
0058 kLogWarning = 4,
0059 kLogNotice = 5,
0060 kLogInfo = 6,
0061 kLogDebug = 7
0062 };
0063
0064 enum ELogFacility {
0065 kLogLocal0,
0066 kLogLocal1,
0067 kLogLocal2,
0068 kLogLocal3,
0069 kLogLocal4,
0070 kLogLocal5,
0071 kLogLocal6,
0072 kLogLocal7
0073 };
0074
0075 enum EFpeMask {
0076 kNoneMask = 0x00,
0077 kInvalid = 0x01,
0078 kDivByZero = 0x02,
0079 kOverflow = 0x04,
0080 kUnderflow = 0x08,
0081 kInexact = 0x10,
0082 kDefaultMask = 0x07,
0083 kAllMask = 0x1F
0084 };
0085
0086 enum EFileModeMask {
0087 kS_IFMT = 0170000,
0088 kS_IFSOCK = 0140000,
0089 kS_IFLNK = 0120000,
0090 kS_IFOFF = 0110000,
0091 kS_IFREG = 0100000,
0092 kS_IFBLK = 0060000,
0093 kS_IFDIR = 0040000,
0094 kS_IFCHR = 0020000,
0095 kS_IFIFO = 0010000,
0096 kS_ISUID = 0004000,
0097 kS_ISGID = 0002000,
0098 kS_ISVTX = 0001000,
0099 kS_IRWXU = 00700,
0100 kS_IRUSR = 00400,
0101 kS_IWUSR = 00200,
0102 kS_IXUSR = 00100,
0103 kS_IRWXG = 00070,
0104 kS_IRGRP = 00040,
0105 kS_IWGRP = 00020,
0106 kS_IXGRP = 00010,
0107 kS_IRWXO = 00007,
0108 kS_IROTH = 00004,
0109 kS_IWOTH = 00002,
0110 kS_IXOTH = 00001
0111 };
0112
0113 inline Bool_t R_ISDIR(Int_t mode) { return ((mode & kS_IFMT) == kS_IFDIR); }
0114 inline Bool_t R_ISCHR(Int_t mode) { return ((mode & kS_IFMT) == kS_IFCHR); }
0115 inline Bool_t R_ISBLK(Int_t mode) { return ((mode & kS_IFMT) == kS_IFBLK); }
0116 inline Bool_t R_ISREG(Int_t mode) { return ((mode & kS_IFMT) == kS_IFREG); }
0117 inline Bool_t R_ISLNK(Int_t mode) { return ((mode & kS_IFMT) == kS_IFLNK); }
0118 inline Bool_t R_ISFIFO(Int_t mode) { return ((mode & kS_IFMT) == kS_IFIFO); }
0119 inline Bool_t R_ISSOCK(Int_t mode) { return ((mode & kS_IFMT) == kS_IFSOCK); }
0120 inline Bool_t R_ISOFF(Int_t mode) { return ((mode & kS_IFMT) == kS_IFOFF); }
0121
0122 struct FileStat_t {
0123 Long_t fDev;
0124 Long_t fIno;
0125 Int_t fMode;
0126 Int_t fUid;
0127 Int_t fGid;
0128 Long64_t fSize;
0129 Long_t fMtime;
0130 Bool_t fIsLink;
0131 TString fUrl;
0132 FileStat_t() : fDev(0), fIno(0), fMode(0), fUid(0), fGid(0), fSize(0),
0133 fMtime(0), fIsLink(kFALSE), fUrl("") { }
0134 };
0135
0136 struct UserGroup_t {
0137 Int_t fUid;
0138 Int_t fGid;
0139 TString fUser;
0140 TString fGroup;
0141 TString fPasswd;
0142 TString fRealName;
0143 TString fShell;
0144 UserGroup_t() : fUid(0), fGid(0), fUser(), fGroup(), fPasswd(),
0145 fRealName (), fShell() { }
0146 };
0147
0148 struct SysInfo_t {
0149 TString fOS;
0150 TString fModel;
0151 TString fCpuType;
0152 Int_t fCpus;
0153 Int_t fCpuSpeed;
0154 Int_t fBusSpeed;
0155 Int_t fL2Cache;
0156 Int_t fPhysRam;
0157 SysInfo_t() : fOS(), fModel(), fCpuType(), fCpus(0), fCpuSpeed(0),
0158 fBusSpeed(0), fL2Cache(0), fPhysRam(0) { }
0159 virtual ~SysInfo_t() { }
0160 ClassDef(SysInfo_t, 1);
0161 };
0162
0163 struct CpuInfo_t {
0164 Float_t fLoad1m;
0165 Float_t fLoad5m;
0166 Float_t fLoad15m;
0167 Float_t fUser;
0168 Float_t fSys;
0169 Float_t fTotal;
0170 Float_t fIdle;
0171 CpuInfo_t() : fLoad1m(0), fLoad5m(0), fLoad15m(0),
0172 fUser(0), fSys(0), fTotal(0), fIdle(0) { }
0173 virtual ~CpuInfo_t() { }
0174 ClassDef(CpuInfo_t, 1);
0175 };
0176
0177 struct MemInfo_t {
0178 Int_t fMemTotal;
0179 Int_t fMemUsed;
0180 Int_t fMemFree;
0181 Int_t fSwapTotal;
0182 Int_t fSwapUsed;
0183 Int_t fSwapFree;
0184 MemInfo_t() : fMemTotal(0), fMemUsed(0), fMemFree(0),
0185 fSwapTotal(0), fSwapUsed(0), fSwapFree(0) { }
0186 virtual ~MemInfo_t() { }
0187 ClassDef(MemInfo_t, 1);
0188 };
0189
0190 struct ProcInfo_t {
0191 Float_t fCpuUser;
0192 Float_t fCpuSys;
0193 Long_t fMemResident;
0194 Long_t fMemVirtual;
0195 ProcInfo_t() : fCpuUser(0), fCpuSys(0), fMemResident(0),
0196 fMemVirtual(0) { }
0197 virtual ~ProcInfo_t();
0198 ClassDef(ProcInfo_t, 1);
0199 };
0200
0201 struct RedirectHandle_t {
0202 TString fFile;
0203 TString fStdOutTty;
0204 TString fStdErrTty;
0205 Int_t fStdOutDup{-1};
0206 Int_t fStdErrDup{-1};
0207 Int_t fReadOffSet{-1};
0208 RedirectHandle_t(const char *n = nullptr) : fFile(n) { }
0209 void Reset() { fFile = ""; fStdOutTty = ""; fStdErrTty = "";
0210 fStdOutDup = -1; fStdErrDup = -1; fReadOffSet = -1; }
0211 };
0212
0213 enum ESockOptions {
0214 kSendBuffer,
0215 kRecvBuffer,
0216 kOobInline,
0217 kKeepAlive,
0218 kReuseAddr,
0219 kNoDelay,
0220 kNoBlock,
0221 kProcessGroup,
0222 kAtMark,
0223 kBytesToRead
0224 };
0225
0226 enum ESendRecvOptions {
0227 kDefault,
0228 kOob,
0229 kPeek,
0230 kDontBlock
0231 };
0232
0233 typedef void (*Func_t)();
0234
0235 R__EXTERN const char *gRootDir;
0236 R__EXTERN const char *gProgName;
0237 R__EXTERN const char *gProgPath;
0238 R__EXTERN TVirtualMutex *gSystemMutex;
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 class TProcessEventTimer : public TTimer {
0252 public:
0253 TProcessEventTimer(Long_t delay);
0254 Bool_t Notify() override { return kTRUE; }
0255 Bool_t ProcessEvents();
0256 ClassDefOverride(TProcessEventTimer,0)
0257 };
0258
0259
0260 class TSystem : public TNamed {
0261
0262 public:
0263 enum EAclicMode { kDefault, kDebug, kOpt };
0264 enum EAclicProperties {
0265 kFlatBuildDir = BIT(0)
0266 };
0267
0268 protected:
0269 TFdSet *fReadmask{nullptr};
0270 TFdSet *fWritemask{nullptr};
0271 TFdSet *fReadready{nullptr};
0272 TFdSet *fWriteready{nullptr};
0273 TFdSet *fSignals{nullptr};
0274 Int_t fNfd{0};
0275 Int_t fMaxrfd{-1};
0276 Int_t fMaxwfd{-1};
0277 Int_t fSigcnt{0};
0278 TString fWdpath;
0279 TString fHostname;
0280 std::atomic<Bool_t> fInsideNotify{kFALSE};
0281 Int_t fBeepFreq{0};
0282 Int_t fBeepDuration{0};
0283
0284 Bool_t fInControl{kFALSE};
0285 Bool_t fDone{kFALSE};
0286 Int_t fLevel{0};
0287
0288 TList *fTimers{nullptr};
0289 TSeqCollection *fSignalHandler{nullptr};
0290 TSeqCollection *fFileHandler{nullptr};
0291 TSeqCollection *fStdExceptionHandler{nullptr};
0292 TSeqCollection *fOnExitList{nullptr};
0293
0294 TString fListLibs;
0295
0296 TString fBuildArch;
0297 TString fBuildCompiler;
0298 TString fBuildCompilerVersion;
0299 TString fBuildCompilerVersionStr;
0300 TString fBuildNode;
0301 TString fBuildDir;
0302 TString fFlagsDebug;
0303 TString fFlagsOpt;
0304 TString fListPaths;
0305 TString fIncludePath;
0306 TString fLinkedLibs;
0307 TString fSoExt;
0308 TString fObjExt;
0309 EAclicMode fAclicMode{kDefault};
0310 TString fMakeSharedLib;
0311 TString fMakeExe;
0312 TString fLinkdefSuffix;
0313 Int_t fAclicProperties{0};
0314 TSeqCollection *fCompiled{nullptr};
0315 TSeqCollection *fHelpers{nullptr};
0316
0317 TString &GetLastErrorString();
0318 const TString &GetLastErrorString() const;
0319
0320 TSystem *FindHelper(const char *path, void *dirptr = nullptr);
0321 virtual Bool_t ConsistentWith(const char *path, void *dirptr = nullptr);
0322 virtual const char *ExpandFileName(const char *fname);
0323 virtual Bool_t ExpandFileName(TString &fname);
0324 virtual void SigAlarmInterruptsSyscalls(Bool_t) { }
0325 virtual const char *GetLinkedLibraries();
0326 virtual void DoBeep(Int_t =-1, Int_t =-1) const { printf("\a"); fflush(stdout); }
0327
0328 static const char *StripOffProto(const char *path, const char *proto);
0329
0330 private:
0331 TSystem(const TSystem&) = delete;
0332 TSystem& operator=(const TSystem&) = delete;
0333 Bool_t ExpandFileName(const char *fname, char *xname, const int kBufSize);
0334
0335 public:
0336 TSystem(const char *name = "Generic", const char *title = "Generic System");
0337 virtual ~TSystem();
0338
0339
0340 virtual Bool_t Init();
0341 virtual void SetProgname(const char *name);
0342 virtual void SetDisplay();
0343 void SetErrorStr(const char *errstr);
0344 const char *GetErrorStr() const { return GetLastErrorString(); }
0345 virtual const char *GetError();
0346 virtual Int_t GetCryptoRandom(void *buf, Int_t len);
0347 void RemoveOnExit(TObject *obj);
0348 virtual const char *HostName();
0349 virtual void NotifyApplicationCreated();
0350
0351 static Int_t GetErrno();
0352 static void ResetErrno();
0353 void Beep(Int_t freq=-1, Int_t duration=-1, Bool_t setDefault=kFALSE);
0354 void GetBeepDefaults(Int_t &freq, Int_t &duration) const { freq = fBeepFreq; duration = fBeepDuration; }
0355
0356
0357 virtual void Run();
0358 virtual Bool_t ProcessEvents();
0359 virtual void DispatchOneEvent(Bool_t pendingOnly = kFALSE);
0360 virtual void ExitLoop();
0361 Bool_t InControl() const { return fInControl; }
0362 virtual void InnerLoop();
0363 virtual Int_t Select(TList *active, Long_t timeout);
0364 virtual Int_t Select(TFileHandler *fh, Long_t timeout);
0365
0366
0367 virtual void AddSignalHandler(TSignalHandler *sh);
0368 virtual TSignalHandler *RemoveSignalHandler(TSignalHandler *sh);
0369 virtual void ResetSignal(ESignals sig, Bool_t reset = kTRUE);
0370 virtual void ResetSignals();
0371 virtual void IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE);
0372 virtual void IgnoreInterrupt(Bool_t ignore = kTRUE);
0373 virtual TSeqCollection *GetListOfSignalHandlers() const { return fSignalHandler; }
0374 virtual void AddFileHandler(TFileHandler *fh);
0375 virtual TFileHandler *RemoveFileHandler(TFileHandler *fh);
0376 virtual TSeqCollection *GetListOfFileHandlers() const { return fFileHandler; }
0377 virtual void AddStdExceptionHandler(TStdExceptionHandler *eh);
0378 virtual TStdExceptionHandler *RemoveStdExceptionHandler(TStdExceptionHandler *eh);
0379 virtual TSeqCollection *GetListOfStdExceptionHandlers() const { return fStdExceptionHandler; }
0380
0381
0382 virtual Int_t GetFPEMask();
0383 virtual Int_t SetFPEMask(Int_t mask = kDefaultMask);
0384
0385
0386 virtual TTime Now();
0387 virtual TList *GetListOfTimers() const { return fTimers; }
0388 virtual void AddTimer(TTimer *t);
0389 virtual TTimer *RemoveTimer(TTimer *t);
0390 virtual void ResetTimer(TTimer *) { }
0391 virtual Long_t NextTimeOut(Bool_t mode);
0392 virtual void Sleep(UInt_t milliSec);
0393
0394
0395 virtual Int_t Exec(const char *shellcmd);
0396 virtual FILE *OpenPipe(const char *command, const char *mode);
0397 virtual int ClosePipe(FILE *pipe);
0398 virtual TString GetFromPipe(const char *command);
0399 virtual int GetPid();
0400 virtual void StackTrace();
0401
0402 [[ noreturn ]] virtual void Exit(int code, Bool_t mode = kTRUE);
0403 [[ noreturn ]] virtual void Abort(int code = 0);
0404
0405
0406 virtual int MakeDirectory(const char *name);
0407 virtual void *OpenDirectory(const char *name);
0408 virtual void FreeDirectory(void *dirp);
0409 virtual const char *GetDirEntry(void *dirp);
0410 virtual void *GetDirPtr() const { return nullptr; }
0411 virtual Bool_t ChangeDirectory(const char *path);
0412 virtual const char *WorkingDirectory();
0413 virtual std::string GetWorkingDirectory() const;
0414 virtual const char *HomeDirectory(const char *userName = nullptr);
0415 virtual std::string GetHomeDirectory(const char *userName = nullptr) const;
0416 virtual int mkdir(const char *name, Bool_t recursive = kFALSE);
0417 Bool_t cd(const char *path) { return ChangeDirectory(path); }
0418 const char *pwd() { return WorkingDirectory(); }
0419 virtual const char *TempDirectory() const;
0420 virtual FILE *TempFileName(TString &base, const char *dir = nullptr, const char *suffix = nullptr);
0421
0422
0423 virtual const char *BaseName(const char *pathname);
0424 virtual const char *DirName(const char *pathname);
0425 virtual TString GetDirName(const char *pathname);
0426 virtual char *ConcatFileName(const char *dir, const char *name);
0427 virtual Bool_t IsAbsoluteFileName(const char *dir);
0428 virtual Bool_t IsFileInIncludePath(const char *name, char **fullpath = nullptr);
0429 virtual const char *PrependPathName(const char *dir, TString& name);
0430 virtual Bool_t ExpandPathName(TString &path);
0431 virtual char *ExpandPathName(const char *path);
0432 virtual Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists);
0433 virtual Bool_t IsPathLocal(const char *path);
0434 virtual int CopyFile(const char *from, const char *to, Bool_t overwrite = kFALSE);
0435 virtual int Rename(const char *from, const char *to);
0436 virtual int Link(const char *from, const char *to);
0437 virtual int Symlink(const char *from, const char *to);
0438 virtual int Unlink(const char *name);
0439 int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime);
0440 int GetPathInfo(const char *path, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime);
0441 virtual int GetPathInfo(const char *path, FileStat_t &buf);
0442 virtual int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree);
0443 virtual int Chmod(const char *file, UInt_t mode);
0444 virtual int Umask(Int_t mask);
0445 virtual int Utime(const char *file, Long_t modtime, Long_t actime);
0446 virtual const char *UnixPathName(const char *unixpathname);
0447 virtual const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists);
0448 virtual char *Which(const char *search, const char *file, EAccessMode mode = kFileExists);
0449 virtual TList *GetVolumes(Option_t *) const { return nullptr; }
0450
0451
0452 virtual Int_t GetUid(const char *user = nullptr);
0453 virtual Int_t GetGid(const char *group = nullptr);
0454 virtual Int_t GetEffectiveUid();
0455 virtual Int_t GetEffectiveGid();
0456 virtual UserGroup_t *GetUserInfo(Int_t uid);
0457 virtual UserGroup_t *GetUserInfo(const char *user = nullptr);
0458 virtual UserGroup_t *GetGroupInfo(Int_t gid);
0459 virtual UserGroup_t *GetGroupInfo(const char *group = nullptr);
0460
0461
0462 virtual void Setenv(const char *name, const char *value);
0463 virtual void Unsetenv(const char *name);
0464 virtual const char *Getenv(const char *env);
0465
0466
0467 virtual void Openlog(const char *name, Int_t options, ELogFacility facility);
0468 virtual void Syslog(ELogLevel level, const char *mess);
0469 virtual void Closelog();
0470
0471
0472 virtual Int_t RedirectOutput(const char *name, const char *mode = "a", RedirectHandle_t *h = nullptr);
0473 virtual void ShowOutput(RedirectHandle_t *h);
0474
0475
0476 virtual void AddDynamicPath(const char *pathname);
0477 virtual const char *GetDynamicPath();
0478 virtual void SetDynamicPath(const char *pathname);
0479 char *DynamicPathName(const char *lib, Bool_t quiet = kFALSE);
0480 virtual const char *FindDynamicLibrary(TString& lib, Bool_t quiet = kFALSE);
0481 virtual Func_t DynFindSymbol(const char *module, const char *entry);
0482 virtual int Load(const char *module, const char *entry = "", Bool_t system = kFALSE);
0483 virtual void Unload(const char *module);
0484 virtual UInt_t LoadAllLibraries();
0485 virtual void ListSymbols(const char *module, const char *re = "");
0486 virtual void ListLibraries(const char *regexp = "");
0487 virtual const char *GetLibraries(const char *regexp = "",
0488 const char *option = "",
0489 Bool_t isRegexp = kTRUE);
0490
0491
0492 virtual TInetAddress GetHostByName(const char *server);
0493 virtual TInetAddress GetPeerName(int sock);
0494 virtual TInetAddress GetSockName(int sock);
0495 virtual int GetServiceByName(const char *service);
0496 virtual char *GetServiceByPort(int port);
0497 virtual int OpenConnection(const char *server, int port, int tcpwindowsize = -1, const char *protocol = "tcp");
0498 virtual int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize = -1);
0499 virtual int AnnounceUdpService(int port, int backlog);
0500 virtual int AnnounceUnixService(int port, int backlog);
0501 virtual int AnnounceUnixService(const char *sockpath, int backlog);
0502 virtual int AcceptConnection(int sock);
0503 virtual void CloseConnection(int sock, Bool_t force = kFALSE);
0504 virtual int RecvRaw(int sock, void *buffer, int length, int flag);
0505 virtual int SendRaw(int sock, const void *buffer, int length, int flag);
0506 virtual int RecvBuf(int sock, void *buffer, int length);
0507 virtual int SendBuf(int sock, const void *buffer, int length);
0508 virtual int SetSockOpt(int sock, int kind, int val);
0509 virtual int GetSockOpt(int sock, int kind, int *val);
0510
0511
0512 virtual int GetSysInfo(SysInfo_t *info) const;
0513 virtual int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime = 1000) const;
0514 virtual int GetMemInfo(MemInfo_t *info) const;
0515 virtual int GetProcInfo(ProcInfo_t *info) const;
0516
0517
0518 virtual void AddIncludePath(const char *includePath);
0519 virtual void AddLinkedLibs(const char *linkedLib);
0520 virtual int CompileMacro(const char *filename, Option_t *opt = "", const char *library_name = "", const char *build_dir = "", UInt_t dirmode = 0);
0521 virtual Int_t GetAclicProperties() const;
0522 virtual const char *GetBuildArch() const;
0523 virtual const char *GetBuildCompiler() const;
0524 virtual const char *GetBuildCompilerVersion() const;
0525 virtual const char *GetBuildCompilerVersionStr() const;
0526 virtual const char *GetBuildNode() const;
0527 virtual const char *GetBuildDir() const;
0528 virtual const char *GetFlagsDebug() const;
0529 virtual const char *GetFlagsOpt() const;
0530 virtual const char *GetIncludePath();
0531 virtual const char *GetLinkedLibs() const;
0532 virtual const char *GetLinkdefSuffix() const;
0533 virtual EAclicMode GetAclicMode() const;
0534 virtual const char *GetMakeExe() const;
0535 virtual const char *GetMakeSharedLib() const;
0536 virtual const char *GetSoExt() const;
0537 virtual const char *GetObjExt() const;
0538 virtual void SetBuildDir(const char* build_dir, Bool_t isflat = kFALSE);
0539 virtual void SetFlagsDebug(const char *);
0540 virtual void SetFlagsOpt(const char *);
0541 virtual void SetIncludePath(const char *includePath);
0542 virtual void SetMakeExe(const char *directives);
0543 virtual void SetAclicMode(EAclicMode mode);
0544 virtual void SetMakeSharedLib(const char *directives);
0545 virtual void SetLinkedLibs(const char *linkedLibs);
0546 virtual void SetLinkdefSuffix(const char *suffix);
0547 virtual void SetSoExt(const char *soExt);
0548 virtual void SetObjExt(const char *objExt);
0549 virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const;
0550 virtual void CleanCompiledMacros();
0551
0552 ClassDefOverride(TSystem,0)
0553 };
0554
0555 R__EXTERN TSystem *gSystem;
0556 R__EXTERN TFileHandler *gXDisplay;
0557
0558
0559 #endif