Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:31

0001 // @(#)root/unix:$Id$
0002 // Author: Fons Rademakers   15/09/95
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TUnixSystem
0013 #define ROOT_TUnixSystem
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TUnixSystem                                                          //
0019 //                                                                      //
0020 // Class providing an interface to the UNIX Operating System.           //
0021 //                                                                      //
0022 //////////////////////////////////////////////////////////////////////////
0023 
0024 #include "TSystem.h"
0025 #include "TSysEvtHandler.h"
0026 #include "TTimer.h"
0027 #include <string>
0028 
0029 typedef void (*SigHandler_t)(ESignals);
0030 
0031 
0032 class TUnixSystem : public TSystem {
0033 
0034 private:
0035    void FillWithCwd(char *cwd) const;
0036 
0037 protected:
0038    const char    *GetLinkedLibraries() override;
0039 
0040    // static functions providing semi-low level interface to raw Unix
0041    static int          UnixMakedir(const char *name);
0042    static void        *UnixOpendir(const char *name);
0043    static const char  *UnixGetdirentry(void *dir);
0044    static const char  *UnixHomedirectory(const char *user = nullptr);
0045    static const char  *UnixHomedirectory(const char *user, char *path, char *mydir);
0046    static Long64_t     UnixNow();
0047    static int          UnixWaitchild();
0048    static int          UnixSetitimer(Long_t ms);
0049    static int          UnixSelect(Int_t nfds, TFdSet *readready, TFdSet *writeready,
0050                                   Long_t timeout);
0051    static void         UnixSignal(ESignals sig, SigHandler_t h);
0052    static const char  *UnixSigname(ESignals sig);
0053    static void         UnixSigAlarmInterruptsSyscalls(Bool_t set);
0054    static void         UnixResetSignal(ESignals sig);
0055    static void         UnixResetSignals();
0056    static void         UnixIgnoreSignal(ESignals sig, Bool_t ignore);
0057    static int          UnixFilestat(const char *path, FileStat_t &buf);
0058    static int          UnixFSstat(const char *path, Long_t *id, Long_t *bsize,
0059                                   Long_t *blocks, Long_t *bfree);
0060    static int          UnixTcpConnect(const char *hostname, int port, int tcpwindowsize);
0061    static int          UnixUdpConnect(const char *hostname, int port);
0062    static int          UnixUnixConnect(int port);
0063    static int          UnixUnixConnect(const char *path);
0064    static int          UnixTcpService(int port, Bool_t reuse, int backlog,
0065                                       int tcpwindowsize);
0066    static int          UnixUdpService(int port, int backlog);
0067    static int          UnixUnixService(int port, int backlog);
0068    static int          UnixUnixService(const char *sockpath, int backlog);
0069    static int          UnixRecv(int sock, void *buf, int len, int flag);
0070    static int          UnixSend(int sock, const void *buf, int len, int flag);
0071 
0072 public:
0073    TUnixSystem();
0074    virtual ~TUnixSystem();
0075 
0076    //---- Misc -------------------------------------------------
0077    Bool_t            Init() override;
0078    void              SetProgname(const char *name) override;
0079    void              SetDisplay() override;
0080    const char       *GetError() override;
0081    Int_t             GetCryptoRandom(void *buf, Int_t len) override;
0082    const char       *HostName() override;
0083 
0084    //---- EventLoop --------------------------------------------
0085    void              DispatchOneEvent(Bool_t pendingOnly = kFALSE) override;
0086    Int_t             Select(TList *active, Long_t timeout) override;
0087    Int_t             Select(TFileHandler *fh, Long_t timeout) override;
0088 
0089    //---- Handling of system events ----------------------------
0090    void              CheckChilds();
0091    Bool_t            CheckSignals(Bool_t sync);
0092    Bool_t            CheckDescriptors();
0093    void              DispatchSignals(ESignals sig);
0094    void              AddSignalHandler(TSignalHandler *sh) override;
0095    TSignalHandler   *RemoveSignalHandler(TSignalHandler *sh) override;
0096    void              ResetSignal(ESignals sig, Bool_t reset = kTRUE) override;
0097    void              ResetSignals() override;
0098    void              IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE) override;
0099    void              SigAlarmInterruptsSyscalls(Bool_t set) override;
0100    void              AddFileHandler(TFileHandler *fh) override;
0101    TFileHandler     *RemoveFileHandler(TFileHandler *fh) override;
0102 
0103    //---- Floating Point Exceptions Control --------------------
0104    Int_t             GetFPEMask() override;
0105    Int_t             SetFPEMask(Int_t mask = kDefaultMask) override;
0106 
0107    //---- Time & Date ------------------------------------------
0108    TTime             Now() override;
0109    void              AddTimer(TTimer *ti) override;
0110    TTimer           *RemoveTimer(TTimer *ti) override;
0111    void              ResetTimer(TTimer *ti) override;
0112    Bool_t            DispatchTimers(Bool_t mode);
0113    void              Sleep(UInt_t milliSec) override;
0114 
0115    //---- Processes --------------------------------------------
0116    Int_t             Exec(const char *shellcmd) override;
0117    FILE             *OpenPipe(const char *shellcmd, const char *mode) override;
0118    int               ClosePipe(FILE *pipe) override;
0119    int               GetPid() override;
0120    void              StackTrace() override;
0121 
0122    [[ noreturn ]] void Exit (int code, Bool_t mode = kTRUE) override;
0123    [[ noreturn ]] void Abort (int code = 0) override;
0124 
0125    //---- Directories ------------------------------------------
0126    int               MakeDirectory(const char *name) override;
0127    void             *OpenDirectory(const char *name) override;
0128    void              FreeDirectory(void *dirp) override;
0129    const char       *GetDirEntry(void *dirp) override;
0130    Bool_t            ChangeDirectory(const char *path) override;
0131    const char       *WorkingDirectory() override;
0132    std::string       GetWorkingDirectory() const override;
0133    const char       *HomeDirectory(const char *userName = nullptr) override;
0134    std::string       GetHomeDirectory(const char *userName = nullptr) const override;
0135    const char       *TempDirectory() const override;
0136    FILE             *TempFileName(TString &base, const char *dir = nullptr, const char *suffix = nullptr) override;
0137 
0138    //---- Paths & Files ----------------------------------------
0139    const char       *PrependPathName(const char *dir, TString& name) override;
0140    Bool_t            ExpandPathName(TString &patbuf) override;
0141    char             *ExpandPathName(const char *path) override;
0142    Bool_t            AccessPathName(const char *path, EAccessMode mode = kFileExists) override;
0143    Bool_t            IsPathLocal(const char *path) override;
0144    int               CopyFile(const char *from, const char *to, Bool_t overwrite = kFALSE) override;
0145    int               Rename(const char *from, const char *to) override;
0146    int               Link(const char *from, const char *to) override;
0147    int               Symlink(const char *from, const char *to) override;
0148    int               Unlink(const char *name) override;
0149    int               GetPathInfo(const char *path, FileStat_t &buf) override;
0150    int               GetFsInfo(const char *path, Long_t *id, Long_t *bsize,
0151                                Long_t *blocks, Long_t *bfree) override;
0152    int               Chmod(const char *file, UInt_t mode) override;
0153    int               Umask(Int_t mask) override;
0154    int               Utime(const char *file, Long_t modtime, Long_t actime) override;
0155    const char       *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists) override;
0156 
0157    //---- Users & Groups ---------------------------------------
0158    Int_t             GetUid(const char *user = nullptr) override;
0159    Int_t             GetGid(const char *group = nullptr) override;
0160    Int_t             GetEffectiveUid() override;
0161    Int_t             GetEffectiveGid() override;
0162    UserGroup_t      *GetUserInfo(Int_t uid) override;
0163    UserGroup_t      *GetUserInfo(const char *user = nullptr) override;
0164    UserGroup_t      *GetGroupInfo(Int_t gid) override;
0165    UserGroup_t      *GetGroupInfo(const char *group = nullptr) override;
0166 
0167    //---- Environment Manipulation -----------------------------
0168    const char       *Getenv(const char *name) override;
0169    void              Setenv(const char *name, const char *value) override;
0170    void              Unsetenv(const char *name) override;
0171 
0172    //---- System Logging ---------------------------------------
0173    void              Openlog(const char *name, Int_t options, ELogFacility facility) override;
0174    void              Syslog(ELogLevel level, const char *mess) override;
0175    void              Closelog() override;
0176 
0177    //---- Standard Output redirection --------------------------
0178    Int_t             RedirectOutput(const char *name, const char *mode = "a",
0179                                     RedirectHandle_t *h = nullptr) override;
0180 
0181    //---- Dynamic Loading --------------------------------------
0182    void              AddDynamicPath(const char *lib) override;
0183    const char       *GetDynamicPath() override;
0184    void              SetDynamicPath(const char *lib) override;
0185    const char       *FindDynamicLibrary(TString &lib, Bool_t quiet = kFALSE) override;
0186    Func_t            DynFindSymbol(const char *module, const char *entry) override;
0187    int               Load(const char *module, const char *entry = "", Bool_t system = kFALSE) override;
0188    void              Unload(const char *module) override;
0189    void              ListSymbols(const char *module, const char *re = "") override;
0190    void              ListLibraries(const char *regexp = "") override;
0191 
0192    //---- RPC --------------------------------------------------
0193    TInetAddress      GetHostByName(const char *server) override;
0194    TInetAddress      GetPeerName(int sock) override;
0195    TInetAddress      GetSockName(int sock) override;
0196    int               GetServiceByName(const char *service) override;
0197    char             *GetServiceByPort(int port) override;
0198    int               ConnectService(const char *server, int port, int tcpwindowsize, const char *protocol = "tcp");
0199    int               OpenConnection(const char *server, int port, int tcpwindowsize = -1, const char *protocol = "tcp") override;
0200    int               AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize = -1) override;
0201    int               AnnounceUdpService(int port, int backlog) override;
0202    int               AnnounceUnixService(int port, int backlog) override;
0203    int               AnnounceUnixService(const char *sockpath, int backlog) override;
0204    int               AcceptConnection(int sock) override;
0205    void              CloseConnection(int sock, Bool_t force = kFALSE) override;
0206    int               RecvRaw(int sock, void *buffer, int length, int flag) override;
0207    int               SendRaw(int sock, const void *buffer, int length, int flag) override;
0208    int               RecvBuf(int sock, void *buffer, int length) override;
0209    int               SendBuf(int sock, const void *buffer, int length) override;
0210    int               SetSockOpt(int sock, int option, int val) override;
0211    int               GetSockOpt(int sock, int option, int *val) override;
0212 
0213    //---- System, CPU and Memory info
0214    int               GetSysInfo(SysInfo_t *info) const override;
0215    int               GetCpuInfo(CpuInfo_t *info, Int_t sampleTime = 1000) const override;
0216    int               GetMemInfo(MemInfo_t *info) const override;
0217    int               GetProcInfo(ProcInfo_t *info) const override;
0218 
0219    ClassDefOverride(TUnixSystem,0)  //Interface to Unix OS services
0220 };
0221 
0222 #endif