12 #ifndef ROOT_TUnixSystem
13 #define ROOT_TUnixSystem
28 typedef void (*SigHandler_t)(ESignals);
31 class TUnixSystem :
public TSystem {
34 void FillWithCwd(
char *cwd)
const;
37 const char *FindDynamicLibrary(TString &lib, Bool_t quiet = kFALSE);
38 const char *GetLinkedLibraries();
41 static int UnixMakedir(
const char *name);
42 static void *UnixOpendir(
const char *name);
43 static const char *UnixGetdirentry(
void *dir);
44 static const char *UnixHomedirectory(
const char *user = 0);
45 static const char *UnixHomedirectory(
const char *user,
char *path,
char *mydir);
46 static Long64_t UnixNow();
47 static int UnixWaitchild();
48 static int UnixSetitimer(Long_t ms);
49 static int UnixSelect(Int_t nfds, TFdSet *readready, TFdSet *writeready,
51 static void UnixSignal(ESignals sig, SigHandler_t h);
52 static const char *UnixSigname(ESignals sig);
53 static void UnixSigAlarmInterruptsSyscalls(Bool_t set);
54 static void UnixResetSignal(ESignals sig);
55 static void UnixResetSignals();
56 static void UnixIgnoreSignal(ESignals sig, Bool_t ignore);
57 static int UnixFilestat(
const char *path, FileStat_t &buf);
58 static int UnixFSstat(
const char *path, Long_t *
id, Long_t *bsize,
59 Long_t *blocks, Long_t *bfree);
60 static int UnixTcpConnect(
const char *hostname,
int port,
int tcpwindowsize);
61 static int UnixUdpConnect(
const char *hostname,
int port);
62 static int UnixUnixConnect(
int port);
63 static int UnixUnixConnect(
const char *path);
64 static int UnixTcpService(
int port, Bool_t reuse,
int backlog,
66 static int UnixUdpService(
int port,
int backlog);
67 static int UnixUnixService(
int port,
int backlog);
68 static int UnixUnixService(
const char *sockpath,
int backlog);
69 static int UnixRecv(
int sock,
void *buf,
int len,
int flag);
70 static int UnixSend(
int sock,
const void *buf,
int len,
int flag);
74 virtual ~TUnixSystem();
78 void SetProgname(
const char *name);
80 const char *GetError();
81 const char *HostName();
84 void DispatchOneEvent(Bool_t pendingOnly = kFALSE);
85 Int_t Select(TList *active, Long_t timeout);
86 Int_t Select(TFileHandler *fh, Long_t timeout);
90 Bool_t CheckSignals(Bool_t sync);
91 Bool_t CheckDescriptors();
92 void DispatchSignals(ESignals sig);
93 void AddSignalHandler(TSignalHandler *sh);
94 TSignalHandler *RemoveSignalHandler(TSignalHandler *sh);
95 void ResetSignal(ESignals sig, Bool_t reset = kTRUE);
97 void IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE);
98 void SigAlarmInterruptsSyscalls(Bool_t set);
99 void AddFileHandler(TFileHandler *fh);
100 TFileHandler *RemoveFileHandler(TFileHandler *fh);
104 Int_t SetFPEMask(Int_t mask = kDefaultMask);
108 void AddTimer(TTimer *ti);
109 TTimer *RemoveTimer(TTimer *ti);
110 void ResetTimer(TTimer *ti);
111 Bool_t DispatchTimers(Bool_t mode);
112 void Sleep(UInt_t milliSec);
115 Int_t Exec(
const char *shellcmd);
116 FILE *OpenPipe(
const char *shellcmd,
const char *mode);
117 int ClosePipe(FILE *pipe);
118 void Exit(
int code, Bool_t mode = kTRUE);
119 void Abort(
int code = 0);
124 int MakeDirectory(
const char *name);
125 void *OpenDirectory(
const char *name);
126 void FreeDirectory(
void *dirp);
127 const char *GetDirEntry(
void *dirp);
128 Bool_t ChangeDirectory(
const char *path);
129 const char *WorkingDirectory();
130 std::string GetWorkingDirectory()
const;
131 const char *HomeDirectory(
const char *userName = 0);
132 std::string GetHomeDirectory(
const char *userName = 0)
const;
133 const char *TempDirectory()
const;
134 FILE *TempFileName(TString &base,
const char *dir = 0);
137 const char *PrependPathName(
const char *dir, TString& name);
138 Bool_t ExpandPathName(TString &patbuf);
139 char *ExpandPathName(
const char *path);
140 Bool_t AccessPathName(
const char *path, EAccessMode mode = kFileExists);
141 Bool_t IsPathLocal(
const char *path);
142 int CopyFile(
const char *from,
const char *to, Bool_t overwrite = kFALSE);
143 int Rename(
const char *from,
const char *to);
144 int Link(
const char *from,
const char *to);
145 int Symlink(
const char *from,
const char *to);
146 int Unlink(
const char *name);
147 int GetPathInfo(
const char *path, FileStat_t &buf);
148 int GetFsInfo(
const char *path, Long_t *
id, Long_t *bsize,
149 Long_t *blocks, Long_t *bfree);
150 int Chmod(
const char *file, UInt_t mode);
151 int Umask(Int_t mask);
152 int Utime(
const char *file, Long_t modtime, Long_t actime);
153 const char *FindFile(
const char *search, TString& file, EAccessMode mode = kFileExists);
156 Int_t GetUid(
const char *user = 0);
157 Int_t GetGid(
const char *group = 0);
158 Int_t GetEffectiveUid();
159 Int_t GetEffectiveGid();
160 UserGroup_t *GetUserInfo(Int_t uid);
161 UserGroup_t *GetUserInfo(
const char *user = 0);
162 UserGroup_t *GetGroupInfo(Int_t gid);
163 UserGroup_t *GetGroupInfo(
const char *group = 0);
166 const char *Getenv(
const char *name);
167 void Setenv(
const char *name,
const char *value);
168 void Unsetenv(
const char *name);
171 void Openlog(
const char *name, Int_t options, ELogFacility facility);
172 void Syslog(ELogLevel level,
const char *mess);
176 Int_t RedirectOutput(
const char *name,
const char *mode =
"a",
177 RedirectHandle_t *h = 0);
180 void AddDynamicPath(
const char *lib);
181 const char *GetDynamicPath();
182 void SetDynamicPath(
const char *lib);
183 Func_t DynFindSymbol(
const char *module,
const char *entry);
184 int Load(
const char *module,
const char *entry =
"", Bool_t system = kFALSE);
185 void Unload(
const char *module);
186 void ListSymbols(
const char *module,
const char *re =
"");
187 void ListLibraries(
const char *regexp =
"");
190 TInetAddress GetHostByName(
const char *server);
191 TInetAddress GetPeerName(
int sock);
192 TInetAddress GetSockName(
int sock);
193 int GetServiceByName(
const char *service);
194 char *GetServiceByPort(
int port);
195 int ConnectService(
const char *server,
int port,
int tcpwindowsize,
const char *protocol =
"tcp");
196 int OpenConnection(
const char *server,
int port,
int tcpwindowsize = -1,
const char *protocol =
"tcp");
197 int AnnounceTcpService(
int port, Bool_t reuse,
int backlog,
int tcpwindowsize = -1);
198 int AnnounceUdpService(
int port,
int backlog);
199 int AnnounceUnixService(
int port,
int backlog);
200 int AnnounceUnixService(
const char *sockpath,
int backlog);
201 int AcceptConnection(
int sock);
202 void CloseConnection(
int sock, Bool_t force = kFALSE);
203 int RecvRaw(
int sock,
void *buffer,
int length,
int flag);
204 int SendRaw(
int sock,
const void *buffer,
int length,
int flag);
205 int RecvBuf(
int sock,
void *buffer,
int length);
206 int SendBuf(
int sock,
const void *buffer,
int length);
207 int SetSockOpt(
int sock,
int option,
int val);
208 int GetSockOpt(
int sock,
int option,
int *val);
211 int GetSysInfo(SysInfo_t *info)
const;
212 int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime = 1000)
const;
213 int GetMemInfo(MemInfo_t *info)
const;
214 int GetProcInfo(ProcInfo_t *info)
const;
216 ClassDef(TUnixSystem,0)