12#ifndef ROOT_TUnixSystem
13#define ROOT_TUnixSystem
49 static int UnixSelect(
Int_t nfds, TFdSet *readready, TFdSet *writeready,
60 static int UnixTcpConnect(
const char *hostname,
int port,
int tcpwindowsize);
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);
116 FILE *
OpenPipe(
const char *shellcmd,
const char *mode);
119 void Abort(
int code = 0);
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);
167 void Setenv(
const char *
name,
const char *value);
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 =
"");
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");
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);
#define ClassDef(name, id)
typedef void((*Func_t)())
void(* SigHandler_t)(ESignals)
This class represents an Internet Protocol (IP) address.
Abstract base class defining a generic interface to the underlying Operating System.
Basic time type with millisecond precision.
Handles synchronous and a-synchronous timer events.
TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
Int_t GetEffectiveGid()
Returns the effective group id.
const char * GetError()
Return system error string.
int GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
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.
Int_t Select(TList *active, Long_t timeout)
Select on file descriptors.
static int UnixUdpConnect(const char *hostname, int port)
Creates a UDP socket connection Is called via the TSocket constructor.
int SetSockOpt(int sock, int option, int val)
Set socket option.
static const char * UnixHomedirectory(const char *user=0)
Returns the user's home directory.
void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
static int UnixTcpConnect(const char *hostname, int port, int tcpwindowsize)
Open a TCP/IP connection to server and connect to a service (i.e.
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...
static const char * UnixGetdirentry(void *dir)
Returns the next directory entry.
void ListSymbols(const char *module, const char *re="")
List symbols in a shared library.
int ConnectService(const char *server, int port, int tcpwindowsize, const char *protocol="tcp")
Connect to service servicename on server servername.
void Setenv(const char *name, const char *value)
Set environment variable.
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.
int ClosePipe(FILE *pipe)
Close the pipe.
int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
Bool_t CheckSignals(Bool_t sync)
Check if some signals were raised and call their Notify() member.
static int UnixMakedir(const char *name)
Make a Unix file system directory.
std::string GetWorkingDirectory() const
Return working directory.
UserGroup_t * GetGroupInfo(Int_t gid)
Returns all group info in the UserGroup_t structure.
int Utime(const char *file, Long_t modtime, Long_t actime)
Set a files modification and access times.
int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
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 Syslog(ELogLevel level, const char *mess)
Send mess to syslog daemon.
int GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.
static int UnixUnixConnect(int port)
Connect to a Unix domain socket.
const char * WorkingDirectory()
Return working directory.
int Umask(Int_t mask)
Set the process file creation mode mask.
Int_t SetFPEMask(Int_t mask=kDefaultMask)
Set which conditions trigger a floating point exception.
int GetServiceByName(const char *service)
Get port # of internet service.
int Unlink(const char *name)
Unlink, i.e.
int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket.
virtual ~TUnixSystem()
Reset to original state.
TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to a service on a server.
void ResetSignals()
Reset signals handlers to previous behaviour.
int SendBuf(int sock, const void *buffer, int length)
Send a buffer headed by a length indicator.
static void UnixResetSignal(ESignals sig)
Restore old signal handler for specified signal.
int AnnounceUdpService(int port, int backlog)
Announce UDP service.
void SetDisplay()
Set DISPLAY environment variable based on utmp entry. Only for UNIX.
static int UnixUdpService(int port, int backlog)
Open a socket, bind to it and start listening for UDP connections on the port.
int Rename(const char *from, const char *to)
Rename a file. Returns 0 when successful, -1 in case of failure.
Bool_t ExpandPathName(TString &patbuf)
Expand a pathname getting rid of special shell characters like ~.
TTimer * RemoveTimer(TTimer *ti)
Remove timer from list of system timers.
void Sleep(UInt_t milliSec)
Sleep milliSec milliseconds.
void Abort(int code=0)
Abort the application.
void Unsetenv(const char *name)
Unset environment variable.
int GetSockOpt(int sock, int option, int *val)
Get socket option.
const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const
Returns cpu load average and load info into the CpuInfo_t structure.
Bool_t DispatchTimers(Bool_t mode)
Handle and dispatch timers.
void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
const char * GetLinkedLibraries()
Get list of shared libraries loaded at the start of the executable.
void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
void DispatchOneEvent(Bool_t pendingOnly=kFALSE)
Dispatch a single event.
TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
int AcceptConnection(int sock)
Accept a connection.
void FreeDirectory(void *dirp)
Close a Unix file system directory.
const char * GetDirEntry(void *dirp)
Get next Unix file system directory entry. Returns 0 if no more entries.
Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
void SetDynamicPath(const char *lib)
Set the dynamic path to a new value.
const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Int_t GetEffectiveUid()
Returns the effective user id.
char * GetServiceByPort(int port)
Get name of internet service.
int RecvBuf(int sock, void *buffer, int length)
Receive a buffer headed by a length indicator.
Int_t GetFPEMask()
Return the bitmap of conditions that trigger a floating point exception.
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 CheckChilds()
Check if children have finished.
static int UnixUnixService(int port, int backlog)
Open a socket, bind to it and start listening for Unix domain connections to it.
const char * HostName()
Return the system's host name.
void SigAlarmInterruptsSyscalls(Bool_t set)
When the argument is true the SIGALRM signal handler is set so that interrupted syscalls will not be ...
std::string GetHomeDirectory(const char *userName=0) const
Return the user's home directory.
const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
static const char * UnixSigname(ESignals sig)
Return the signal name associated with a signal.
static Long64_t UnixNow()
Get current time in milliseconds since 0:00 Jan 1 1995.
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 AddTimer(TTimer *ti)
Add timer to list of system timers.
void * OpenDirectory(const char *name)
Open a Unix file system directory. Returns 0 if directory does not exist.
void AddDynamicPath(const char *lib)
Add a new directory to the dynamic path.
void ResetSignal(ESignals sig, Bool_t reset=kTRUE)
If reset is true reset the signal handler for the specified signal to the default handler,...
static int UnixSetitimer(Long_t ms)
Set interval timer to time-out in ms milliseconds.
Func_t DynFindSymbol(const char *module, const char *entry)
dynamic linking of module
static int UnixSend(int sock, const void *buf, int len, int flag)
Send exactly length bytes from buffer.
static void UnixIgnoreSignal(ESignals sig, Bool_t ignore)
If ignore is true ignore the specified signal, else restore previous behaviour.
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 Symlink(const char *from, const char *to)
Create a symlink from file1 to file2.
void DispatchSignals(ESignals sig)
Handle and dispatch signals.
Int_t Exec(const char *shellcmd)
Execute a command.
Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
void Unload(const char *module)
Unload a shared library.
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...
FILE * TempFileName(TString &base, const char *dir=0)
Create a secure temporary file by appending a unique 6 letter string to base.
static void UnixSignal(ESignals sig, SigHandler_t h)
Set a signal handler for a signal.
int MakeDirectory(const char *name)
Make a Unix file system directory.
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
Bool_t ChangeDirectory(const char *path)
Change directory. Returns kTRUE in case of success, kFALSE otherwise.
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Int_t GetGid(const char *group=0)
Returns the group's id. If group = 0, returns current user's group.
TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
const char * Getenv(const char *name)
Get environment variable.
void StackTrace()
Print a stack trace.
static int UnixFilestat(const char *path, FileStat_t &buf)
Get info about a file.
static int UnixRecv(int sock, void *buf, int len, int flag)
Receive exactly length bytes into buffer.
void FillWithCwd(char *cwd) const
Fill buffer with current working directory.
static int UnixWaitchild()
Wait till child is finished.
int GetPid()
Get process id.
int AnnounceUnixService(int port, int backlog)
Announce unix domain service on path "kServerPath/<port>".
void Closelog()
Close connection to system log daemon.
int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
int Chmod(const char *file, UInt_t mode)
Set the file permission bits. Returns -1 in case or error, 0 otherwise.
void Openlog(const char *name, Int_t options, ELogFacility facility)
Open connection to system log daemon.
int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1)
Announce TCP/IP service.
void ResetTimer(TTimer *ti)
Reset a-sync timer.
static void UnixResetSignals()
Restore old signal handlers.
int Link(const char *from, const char *to)
Create a link from file1 to file2.
static void * UnixOpendir(const char *name)
Open a directory.
Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
FILE * OpenPipe(const char *shellcmd, const char *mode)
Open a pipe.
void ListLibraries(const char *regexp="")
List all loaded shared libraries.
TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
static constexpr double ms