00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TUnixSystem
00013 #define ROOT_TUnixSystem
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef ROOT_TSystem
00025 #include "TSystem.h"
00026 #endif
00027 #ifndef ROOT_TSysEvtHandler
00028 #include "TSysEvtHandler.h"
00029 #endif
00030 #ifndef ROOT_TTimer
00031 #include "TTimer.h"
00032 #endif
00033
00034 typedef void (*SigHandler_t)(ESignals);
00035
00036
00037 class TUnixSystem : public TSystem {
00038
00039 protected:
00040 char *DynamicPathName(const char *lib, Bool_t quiet = kFALSE);
00041 const char *GetLinkedLibraries();
00042
00043
00044 static int UnixMakedir(const char *name);
00045 static void *UnixOpendir(const char *name);
00046 static const char *UnixGetdirentry(void *dir);
00047 static const char *UnixHomedirectory(const char *user = 0);
00048 static Long64_t UnixNow();
00049 static int UnixWaitchild();
00050 static int UnixSetitimer(Long_t ms);
00051 static int UnixSelect(Int_t nfds, TFdSet *readready, TFdSet *writeready,
00052 Long_t timeout);
00053 static void UnixSignal(ESignals sig, SigHandler_t h);
00054 static const char *UnixSigname(ESignals sig);
00055 static void UnixSigAlarmInterruptsSyscalls(Bool_t set);
00056 static void UnixResetSignal(ESignals sig);
00057 static void UnixResetSignals();
00058 static void UnixIgnoreSignal(ESignals sig, Bool_t ignore);
00059 static int UnixFilestat(const char *path, FileStat_t &buf);
00060 static int UnixFSstat(const char *path, Long_t *id, Long_t *bsize,
00061 Long_t *blocks, Long_t *bfree);
00062 static int UnixTcpConnect(const char *hostname, int port, int tcpwindowsize);
00063 static int UnixUnixConnect(int port);
00064 static int UnixUnixConnect(const char *path);
00065 static int UnixTcpService(int port, Bool_t reuse, int backlog,
00066 int tcpwindowsize);
00067 static int UnixUnixService(int port, int backlog);
00068 static int UnixUnixService(const char *sockpath, int backlog);
00069 static int UnixRecv(int sock, void *buf, int len, int flag);
00070 static int UnixSend(int sock, const void *buf, int len, int flag);
00071
00072 static void *FindDynLib(const char *lib);
00073 static int UnixDynLoad(const char *lib);
00074 static Func_t UnixDynFindSymbol(const char *lib, const char *entry);
00075 static void UnixDynUnload(const char *lib);
00076 static void UnixDynListSymbols(const char *lib, const char *re = "");
00077 static void UnixDynListLibs(const char *lib = "");
00078
00079 static void *SearchUtmpEntry(int nentries, const char *tty);
00080 static int ReadUtmpFile();
00081
00082 public:
00083 TUnixSystem();
00084 virtual ~TUnixSystem();
00085
00086
00087 Bool_t Init();
00088 void SetProgname(const char *name);
00089 void SetDisplay();
00090 const char *GetError();
00091 const char *HostName();
00092
00093
00094 void DispatchOneEvent(Bool_t pendingOnly = kFALSE);
00095 Int_t Select(TList *active, Long_t timeout);
00096 Int_t Select(TFileHandler *fh, Long_t timeout);
00097
00098
00099 void CheckChilds();
00100 Bool_t CheckSignals(Bool_t sync);
00101 Bool_t CheckDescriptors();
00102 void DispatchSignals(ESignals sig);
00103 void AddSignalHandler(TSignalHandler *sh);
00104 TSignalHandler *RemoveSignalHandler(TSignalHandler *sh);
00105 void ResetSignal(ESignals sig, Bool_t reset = kTRUE);
00106 void IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE);
00107 void SigAlarmInterruptsSyscalls(Bool_t set);
00108 void AddFileHandler(TFileHandler *fh);
00109 TFileHandler *RemoveFileHandler(TFileHandler *fh);
00110
00111
00112 Int_t GetFPEMask();
00113 Int_t SetFPEMask(Int_t mask = kDefaultMask);
00114
00115
00116 TTime Now();
00117 void AddTimer(TTimer *ti);
00118 TTimer *RemoveTimer(TTimer *ti);
00119 void ResetTimer(TTimer *ti);
00120 Bool_t DispatchTimers(Bool_t mode);
00121 void Sleep(UInt_t milliSec);
00122
00123
00124 Int_t Exec(const char *shellcmd);
00125 FILE *OpenPipe(const char *shellcmd, const char *mode);
00126 int ClosePipe(FILE *pipe);
00127 void Exit(int code, Bool_t mode = kTRUE);
00128 void Abort(int code = 0);
00129 int GetPid();
00130 void StackTrace();
00131
00132
00133 int MakeDirectory(const char *name);
00134 void *OpenDirectory(const char *name);
00135 void FreeDirectory(void *dirp);
00136 const char *GetDirEntry(void *dirp);
00137 Bool_t ChangeDirectory(const char *path);
00138 const char *WorkingDirectory();
00139 const char *HomeDirectory(const char *userName = 0);
00140 const char *TempDirectory() const;
00141 FILE *TempFileName(TString &base, const char *dir = 0);
00142
00143
00144 const char *PrependPathName(const char *dir, TString& name);
00145 Bool_t ExpandPathName(TString &patbuf);
00146 char *ExpandPathName(const char *path);
00147 Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists);
00148 Bool_t IsPathLocal(const char *path);
00149 int CopyFile(const char *from, const char *to, Bool_t overwrite = kFALSE);
00150 int Rename(const char *from, const char *to);
00151 int Link(const char *from, const char *to);
00152 int Symlink(const char *from, const char *to);
00153 int Unlink(const char *name);
00154 int GetPathInfo(const char *path, FileStat_t &buf);
00155 int GetFsInfo(const char *path, Long_t *id, Long_t *bsize,
00156 Long_t *blocks, Long_t *bfree);
00157 int Chmod(const char *file, UInt_t mode);
00158 int Umask(Int_t mask);
00159 int Utime(const char *file, Long_t modtime, Long_t actime);
00160 const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists);
00161
00162
00163 Int_t GetUid(const char *user = 0);
00164 Int_t GetGid(const char *group = 0);
00165 Int_t GetEffectiveUid();
00166 Int_t GetEffectiveGid();
00167 UserGroup_t *GetUserInfo(Int_t uid);
00168 UserGroup_t *GetUserInfo(const char *user = 0);
00169 UserGroup_t *GetGroupInfo(Int_t gid);
00170 UserGroup_t *GetGroupInfo(const char *group = 0);
00171
00172
00173 const char *Getenv(const char *name);
00174 void Setenv(const char *name, const char *value);
00175
00176
00177 void Openlog(const char *name, Int_t options, ELogFacility facility);
00178 void Syslog(ELogLevel level, const char *mess);
00179 void Closelog();
00180
00181
00182 Int_t RedirectOutput(const char *name, const char *mode = "a",
00183 RedirectHandle_t *h = 0);
00184
00185
00186 void AddDynamicPath(const char *lib);
00187 const char *GetDynamicPath();
00188 void SetDynamicPath(const char *lib);
00189 Func_t DynFindSymbol(const char *module, const char *entry);
00190 int Load(const char *module, const char *entry = "", Bool_t system = kFALSE);
00191 void Unload(const char *module);
00192 void ListSymbols(const char *module, const char *re = "");
00193 void ListLibraries(const char *regexp = "");
00194
00195
00196 TInetAddress GetHostByName(const char *server);
00197 TInetAddress GetPeerName(int sock);
00198 TInetAddress GetSockName(int sock);
00199 int GetServiceByName(const char *service);
00200 char *GetServiceByPort(int port);
00201 int ConnectService(const char *server, int port, int tcpwindowsize);
00202 int OpenConnection(const char *server, int port, int tcpwindowsize = -1);
00203 int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize = -1);
00204 int AnnounceUnixService(int port, int backlog);
00205 int AnnounceUnixService(const char *sockpath, int backlog);
00206 int AcceptConnection(int sock);
00207 void CloseConnection(int sock, Bool_t force = kFALSE);
00208 int RecvRaw(int sock, void *buffer, int length, int flag);
00209 int SendRaw(int sock, const void *buffer, int length, int flag);
00210 int RecvBuf(int sock, void *buffer, int length);
00211 int SendBuf(int sock, const void *buffer, int length);
00212 int SetSockOpt(int sock, int option, int val);
00213 int GetSockOpt(int sock, int option, int *val);
00214
00215
00216 int GetSysInfo(SysInfo_t *info) const;
00217 int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime = 1000) const;
00218 int GetMemInfo(MemInfo_t *info) const;
00219 int GetProcInfo(ProcInfo_t *info) const;
00220
00221 ClassDef(TUnixSystem,0)
00222 };
00223
00224 #endif