TSystem


class description - source file - inheritance tree

class TSystem : public TNamed


    protected:
virtual const char* ExpandFileName(const char* fname) const public:
TSystem TSystem(const char* name = Generic, const char* title = Generic System) TSystem TSystem(TSystem&) virtual void ~TSystem() virtual void Abort(int code = 0) virtual int AcceptConnection(int sock) virtual Bool_t AccessPathName(const char* path, EAccessMode mode = kFileExists) virtual void AddFileHandler(TFileHandler* fh) virtual void AddSignalHandler(TSignalHandler* sh) virtual void AddTimer(TTimer* t) virtual int AnnounceTcpService(int port, Bool_t reuse, int backlog) virtual int AnnounceUnixService(int port, int backlog) virtual const char* BaseName(const char* pathname) const Bool_t cd(const char* path) virtual Bool_t ChangeDirectory(const char* path) static TClass* Class() virtual void CleanCompiledMacros() virtual void CloseConnection(int sock, Bool_t force = kFALSE) virtual void Closelog() virtual int ClosePipe(FILE* pipe) virtual int CompileMacro(const char* filename, Option_t* opt) virtual char* ConcatFileName(const char* dir, const char* name) virtual const char* DirName(const char* pathname) const virtual void DispatchOneEvent(Bool_t pendingOnly = kFALSE) virtual char* DynamicPathName(const char* lib, Bool_t quiet = kFALSE) virtual Func_t DynFindSymbol(const char* module, const char* entry) virtual Int_t Exec(const char* shellcmd) virtual void Exit(int code, Bool_t mode = kTRUE) void ExitLoop() virtual Bool_t ExpandPathName(TString& path) virtual char* ExpandPathName(const char* path) virtual void FreeDirectory(void* dirp) virtual const char* GetDirEntry(void* dirp) const virtual const char* Getenv(const char* env) const static Int_t GetErrno() virtual const char* GetError() const const char* GetErrorStr() const virtual TInetAddress GetHostByName(const char* server) virtual const char* GetIncludePath() const virtual const char* GetLibraries(const char* regexp, const char* option) const virtual const char* GetLinkedLibs() const virtual const char* GetMakeExe() const virtual const char* GetMakeSharedLib() const virtual const char* GetObjExt() const virtual int GetPathInfo(const char* path, Long_t* id, Long_t* size, Long_t* flags, Long_t* modtime) virtual TInetAddress GetPeerName(int sock) virtual int GetPid() virtual int GetServiceByName(const char* service) virtual char* GetServiceByPort(int port) virtual TInetAddress GetSockName(int sock) virtual int GetSockOpt(int sock, int kind, int* val) virtual const char* GetSoExt() const virtual const char* HomeDirectory(const Char_t* userName = 0) const virtual const char* HostName() const virtual void IgnoreInterrupt(Bool_t ignore = kTRUE) Bool_t InControl() const virtual Bool_t Init() void InnerLoop() virtual TClass* IsA() const virtual Bool_t IsAbsoluteFileName(const char* dir) virtual int Link(const char* from, const char* to) virtual void ListLibraries(const char* regexp) virtual void ListSymbols(const char* module, const char* re) virtual int Load(const char* module, const char* entry, Bool_t system = kFALSE) virtual int MakeDirectory(const char* name) int mkdir(const char* name) virtual Long_t NextTimeOut(Bool_t mode) virtual TTime Now() virtual int OpenConnection(const char* server, int port) virtual void* OpenDirectory(const char* name) virtual void Openlog(const char* name, Int_t options, ELogFacility facility) virtual FILE* OpenPipe(const char* command, const char* mode) virtual Bool_t ProcessEvents() const char* pwd() const virtual int RecvBuf(int sock, void* buffer, int length) virtual int RecvRaw(int sock, void* buffer, int length, int flag) virtual TFileHandler* RemoveFileHandler(TFileHandler* fh) void RemoveOnExit(TObject* obj) virtual TSignalHandler* RemoveSignalHandler(TSignalHandler* sh) virtual TTimer* RemoveTimer(TTimer* t) virtual void Rename(const char* from, const char* to) static void ResetErrno() virtual void ResetTimer(TTimer*) virtual void Run() virtual int SendBuf(int sock, const void* buffer, int length) virtual int SendRaw(int sock, const void* buffer, int length, int flag) virtual void SetDisplay() virtual void Setenv(const char* name, const char* value) virtual void SetIncludePath(const char* IncludePath) virtual void SetLinkedLibs(const char* LinkedLibs) virtual void SetMakeExe(const char* directives) virtual void SetMakeSharedLib(const char* directives) virtual void SetObjExt(const char* ObjExt) virtual void SetProgname(const char* name) virtual int SetSockOpt(int sock, int kind, int val) virtual void SetSoExt(const char* SoExt) virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Sleep(UInt_t milliSec) virtual void StackTrace() virtual void Streamer(TBuffer& b) void StreamerNVirtual(TBuffer& b) virtual int Symlink(const char* from, const char* to) virtual void Syslog(ELogLevel level, const char* mess) virtual int Umask(Int_t mask) virtual const char* UnixPathName(const char* unixpathname) const virtual int Unlink(const char* name) virtual void Unload(const char* module) virtual void Unsetenv(const char* name) virtual char* Which(const char* search, const char* file, EAccessMode mode = kFileExists) virtual const char* WorkingDirectory() const

Data Members

protected:
TFdSet fReadmask !Files that should be checked for read events TFdSet fWritemask !Files that should be checked for write events TFdSet fReadready !Files with reads waiting TFdSet fWriteready !Files with writes waiting TFdSet fSignals !Signals that were trapped Int_t fNfd Number of fd's in masks Int_t fMaxrfd Largest fd in read mask Int_t fMaxwfd Largest fd in write mask Int_t fSigcnt Number of pending signals TString fWdpath Working directory TString fHostname Hostname Bool_t fInsideNotify Used by DispatchTimers() Bool_t fInControl True if in eventloop Bool_t fDone True if eventloop should be finished Int_t fLevel Level of nested eventloops TString fLastErrorString Last system error message TSeqCollection* fTimers List of timers TSeqCollection* fSignalHandler List of signal handlers TSeqCollection* fFileHandler List of file handlers TSeqCollection* fOnExitList List of items to be cleaned-up on exit TString fListLibs List shared libraries. Cache used by GetLibraries TString fListPaths List of all include (fIncludePath + interpreter include path). Cache used by GetIncludePath TString fIncludePath Used to expand $IncludePath in the directives given to SetMakeSharedLib and SetMakeExe TString fLinkedLibs Used to expand $LinkedLibs in the directives given to SetMakeSharedLib and SetMakeExe TString fSoExt Extension of shared library (.so, .sl, .a, .dll, etc.) TString fObjExt Extension of object files (.o, .obj, etc.) TString fMakeSharedLib Directive used to build a shared library TString fMakeExe Directive used to build an executable TSeqCollection* fCompiled List of shared libs from compiled macros to be deleted


See also

TUnixSystem

Class Description

                                                                      
 TSystem                                                              
                                                                      
 Abstract base class defining a generic interface to the underlying   
 Operating System.                                                    
 This is not an ABC in the strict sense of the (C++) word. For        
 every member function their is an implementation (often not more     
 than a call to AbstractMethod() which prints a warning saying        
 that the method should be overridden in a derived class), which      
 allows a simple partial implementation for new OS'es.                
                                                                      


TSystem(const char *name, const char *title) : TNamed(name, title)
 Create a new OS interface.

~TSystem()
 Delete the OS interface.

Bool_t Init()
 Initialize the OS interface. Copy the OS name (i.e. Unix) and the
 ROOT name to gSystemName and gRootName, respectively.

void SetProgname(const char *name)
 Set the application name (from command line, argv[0]) and copy it in
 gProgName.

void SetDisplay()
 Set DISPLAY environment variable based on utmp entry. Only for UNIX.

const char* GetError()
 Return system error string.

Int_t GetErrno()
 Static function returning system error number.

void ResetErrno()
 Static function resetting system error number.

void RemoveOnExit(TObject *obj)
 Objects that should be deleted on exit of the OS interface.

const char* HostName()
 Return the system's host name.

void Run()
 System event loop.

void ExitLoop()
 Exit from event loop.

void InnerLoop()
 Inner event loop.

Bool_t ProcessEvents()
 Process pending events (GUI, timers, sockets). Returns the result of
 TROOT::IsInterrupted(). The interrupt flag (TROOT::SetInterrupt())
 can be set during the handling of the events. This mechanism allows
 macros running in tight calculating loops to be interrupted by some
 GUI event (depending on the interval with which this method is
 called). For example hitting ctrl-c in a canvas will set the
 interrupt flag.

void DispatchOneEvent(Bool_t)
 Dispatch a single event.

void Sleep(UInt_t)
 Sleep milliSec milli seconds.

TTime Now()
 Return current time.

void AddTimer(TTimer *ti)
 Add timer to list of system timers.

TTimer* RemoveTimer(TTimer *ti)
 Remove timer from list of system timers. Returns removed timer or 0
 if timer was not active.

Long_t NextTimeOut(Bool_t mode)
 Time when next timer of mode (synchronous=kTRUE or
 asynchronous=kFALSE) will time-out (in ms).

void AddSignalHandler(TSignalHandler *h)
 Add a signal handler to list of system signal handlers.

TSignalHandler* RemoveSignalHandler(TSignalHandler *h)
 Remove a signal handler from list of signal handlers.

void AddFileHandler(TFileHandler *h)
 Add a file handler to the list of system file handlers.

TFileHandler* RemoveFileHandler(TFileHandler *h)
 Remove a file handler from the list of file handlers.

void IgnoreInterrupt(Bool_t)
 Ignore the interrupt signal if ignore == kTRUE else restore previous
 behaviour. Typically call ignore interrupt before writing to disk.

int Exec(const char*)
 Execute a command.

FILE* OpenPipe(const char*, const char*)
 Open a pipe.

int ClosePipe(FILE*)
 Close the pipe.

int GetPid()
 Get process id.

void Exit(int, Bool_t)
 Exit the application.

void Abort(int)
 Abort the application.

void StackTrace()
 Print a stack trace.

int MakeDirectory(const char*)
 Make a directory. Returns 0 in case of success and
 -1 if the directory could not be created.

void* OpenDirectory(const char*)
 Open a directory. Returns 0 if directory does not exist.

void FreeDirectory(void*)
 Free a directory.

const char* GetDirEntry(void*)
 Get a directory entry. Returns 0 if no more entries.

Bool_t ChangeDirectory(const char*)
 Change directory.

const char* WorkingDirectory()
 Return working directory.

const char* HomeDirectory(const Char_t*)
 Return the user's home directory.

const char* BaseName(const char *name)
 Base name of a file name. Base name of /user/root is root.

Bool_t IsAbsoluteFileName(const char *dir)
 Return true if dir is an absolute pathname.

const char* DirName(const char *pathname)
 Return the directory name in pathname. DirName of /user/root is /user.

const char* UnixPathName(const char *name)
 Convert from a Unix pathname to a local pathname. E.g. from /user/root to user\root.

char* ConcatFileName(const char *, const char *)
 Concatenate a directory and a file name.

const char* ExpandFileName(const char *fname)
 Expand a pathname getting rid of special shell characters like ~.$, etc.
 For Unix/Win32 compatibility use $(XXX) instead of $XXX when using
 environment variables in a pathname. If compatibility is not an issue
 you can use on Unix directly $XXX. This is a protected function called
 from the OS specific system classes, like TUnixSystem and TWinNTSystem.

Bool_t ExpandPathName(TString&)
 Expand a pathname getting rid of special shell characaters like ~.$, etc.
 For Unix/Win32 compatibility use $(XXX) instead of $XXX when using
 environment variables in a pathname. If compatibility is not an issue
 you can use on Unix directly $XXX.

char* ExpandPathName(const char *)
 Expand a pathname getting rid of special shell characaters like ~.$, etc.
 For Unix/Win32 compatibility use $(XXX) instead of $XXX when using
 environment variables in a pathname. If compatibility is not an issue
 you can use on Unix directly $XXX. The user must delete returned string.

Bool_t AccessPathName(const char*, EAccessMode)
 Returns FALSE if one can access a file using the specified access mode.

void Rename(const char *, const char *)
 Rename a file.

int Link(const char *, const char *)
 Create a link from file1 to file2.

int Symlink(const char *, const char *)
 Create a symbolic link from file1 to file2.

int Unlink(const char *)
 Unlink, i.e. remove, a file.

int GetPathInfo(const char*, Long_t*, Long_t*, Long_t*, Long_t*)
 Get info about a file: id, size, flags, modification time.

int Umask(Int_t)
 Set the process file creation mode mask.

char* Which(const char *, const char *, EAccessMode)
 Find location of file in a search path. User must delete returned string.

void Setenv(const char*, const char*)
 Set environment variable.

void Unsetenv(const char *name)
 Unset environment variable.

const char* Getenv(const char*)
 Get environment variable.

void Openlog(const char *, Int_t, ELogFacility)
 Open connection to system log daemon. For the use of the options and
 facility see the Unix openlog man page.

void Syslog(ELogLevel, const char *)
 Send mess to syslog daemon. Level is the logging level and mess the
 message that will be written on the log.

void Closelog()
 Close connection to system log daemon.

int Load(const char *module, const char *entry, Bool_t system)
 Load a shared library. Returns 0 on successful loading, 1 in
 case lib was already loaded and -1 in case lib does not exist
 or in case of error. When entry is specified the loaded lib is
 search for this entry point (return -1 when entry does not exist,
 0 otherwise). When the system flag is kTRUE, the library is consisdered
 a permanent systen library that should not be unloaded during the
 course of the session.

char* DynamicPathName(const char *, Bool_t)

Func_t DynFindSymbol(const char * /*lib*/, const char *entry)
 Find specific entry point in specified library. Specify "*" for lib
 to search in all libraries.

void Unload(const char *)
 Unload a shared library.

void ListSymbols(const char *, const char *)
 List symbols in a shared library.

void ListLibraries(const char *regexp)
 List all loaded shared libraries.

const char* GetLibraries(const char *regexp, const char *options)
 Return a space separated list of loaded shared libraries.
 This list is of a format suitable for a linker, i.e it may contain
 -Lpathname and/or -lNameOfLib.
 Option can be any of:
   S: shared libraries loaded at the start of the executable, because
      they were specified on the link line.
   D: shared libraries dynamically loaded after the start of the program.

TInetAddress GetHostByName(const char *)
 Get Internet Protocol (IP) address of host.

TInetAddress GetPeerName(int)
 Get Internet Protocol (IP) address of remote host and port #.

TInetAddress GetSockName(int)
 Get Internet Protocol (IP) address of host and port #.

int GetServiceByName(const char *)
 Get port # of internet service.

char* GetServiceByPort(int)
 Get name of internet service.

int OpenConnection(const char*, int)
 Open a connection to another host.

int AnnounceTcpService(int, Bool_t, int)
 Announce TCP/IP service.

int AnnounceUnixService(int, int)
 Announce unix domain service.

int AcceptConnection(int)
 Accept a connection.

void CloseConnection(int, Bool_t)
 Close socket connection.

int RecvRaw(int, void *, int, int)
 Receive exactly length bytes into buffer. Use opt to receive out-of-band
 data or to have a peek at what is in the buffer (see TSocket).

int SendRaw(int, const void *, int, int)
 Send exactly length bytes from buffer. Use opt to send out-of-band
 data (see TSocket).

int RecvBuf(int, void *, int)
 Receive a buffer headed by a length indicator.

int SendBuf(int, const void *, int)
 Send a buffer headed by a length indicator.

int SetSockOpt(int, int, int)
 Set socket option.

int GetSockOpt(int, int, int*)
 Get socket option.

int CompileMacro(const char *filename, Option_t * opt)
 This method compiles and loads a shared library containing
 the code from the file "filename".

 The possible options are:
     k : keep the shared library after the session end.
     f : force recompilation.

 It uses the directive fMakeSharedLibs to create a shared library.
 If loading the shared library fails, it tries to output a list of missing
 symbols by creating an executable (on some platforms like OSF, this does
 not HAVE to be an executable) containing the script. It uses the
 directive fMakeExe to do so.
 For both directives, before passing them to TSystem::Exec, it expands the
 variables $SourceFiles, $SharedLib, $LibName, $IncludePath, $LinkedLibs,
 $ExeName and $ObjectFiles. See SetMakeSharedLib() for more information on
 those variables.

 This method is used to implement the following feature:

 Synopsis:

 The purpose of this addition is to allow the user to use an external
 compiler to create a shared library from its C++ macro (scripts).
 Currently in order to execute a script, a user has to type at the root
 prompt

  .X myfunc.C(arg1,arg2)

 We allow him to type:

  .X myfunc.C++(arg1,arg2)
 or
  .X myfunc.C+(arg1,arg2)

 In which case an external compiler will be called to create a shared
 library.  This shared library will then be loaded and the function
 myfunc will be called with the two arguments.  With '++' the shared library
 is always recompiled.  With '+' the shared library is recompiled only
 if it does not exist yet or the macro file is newer than the shared
 library.

 HOWEVER, CompileMacro currently does NOT detect if any of the file that
 are included by the macro file has been changed!!!

 Of course the + and ++ notation is supported in similar way for .x and .L.

 Through the function TSystem::SetMakeSharedLib(), the user will be able to
 indicate, with shell commands, how to build a shared library (a good
 default will be provided). The most common change, namely where to find
 header files, will be available through the function
 TSystem::SetIncludePath().
 A good default will be provided so that a typical user session should be at
 most:

 root[1] gSystem->SetIncludePath("-I$ROOTSYS/include
 -I$HOME/mypackage/include");
 root[2] .x myfunc.C++(10,20);

 The user may sometimes try to compile a script before it has loaded all the
 needed shared libraries.  In this case we want to be helpfull and output a
 list of the unresolved symbols. So if the loading of the created shared
 library fails, we will try to build a executable that contains the
 script. The linker should then output a list of missing symbols.

 To support this we provide a TSystem::SetMakeExe() function, that sets the
 directive telling how to create an executable. The loader will need
 to be informed of all the libraries available. The information about
 the libraries that has been loaded by .L and TSystem::Load() is accesible
 to the script compiler. However, the information about
 the libraries that have been selected at link time by the application
 builder (like the root libraries for root.exe) are not available and need
 to be explictly listed in fLinkedLibs (either by default or by a call to
 TSystem::SetLinkedLibs()).

 To simplify customization we could also add to the .rootrc support for the
 variables

 Unix.*.Root.IncludePath:     -I$ROOTSYS/include
 WinNT.*.Root.IncludePath:    -I%ROOTSYS%/include

 Unix.*.Root.LinkedLibs:      -L$ROOTSYS/lib -lBase ....
 WinNT.*.Root.LinkedLibs:     %ROOTSYS%/lib/*.lib msvcrt.lib ....

 And also support for MakeSharedLibs() and MakeExe().

 (the ... have to be replaced by the actual values and are here only to
 shorten this comment).

const char* GetMakeSharedLib() const

const char* GetMakeExe() const

const char* GetIncludePath()

const char* GetLinkedLibs() const

const char* GetSoExt() const

const char* GetObjExt() const

void SetMakeExe(const char *directives)
 Directives has the same syntax as the argument of SetMakeSharedLib but is
 used to create an executable. This creation is used as a means to output
 a list of unresolved symbols, when loading a shared library has failed.
 The required variable is $ExeName rather than $SharedLib, e.g.:
 gSystem->SetMakeExe(
 "g++ -Wall -fPIC $IncludePath $SourceFiles
  -o $ExeName $LinkedLibs -L/usr/X11R6/lib -lX11 -lm -ldl -rdynamic");

void SetMakeSharedLib(const char *directives)
 Directives should contain the description on how to compile and link a
 shared lib. This description can be any valid shell command, including
 the use of ';' to separate several instructions. However, shell specific
 construct should be avoided. In particular this description can contain
 environment variables, like $ROOTSYS (or %ROOTSYS% on windows).

 Five special variables will be expanded before execution:
   Variable name       Expands to
   -------------       ----------
   $SourceFiles        Name of source files to be compiled
   $SharedLib          Name of the shared library being created
   $LibName            Name of shared library without extension
   $BuildDir           Directory where the files will be created
   $IncludePath        value of fIncludePath
   $LinkedLibs         value of fLinkedLibs
   $ObjectFiles        Name of source files to be compiler with
                       their extension changed to .o or .obj
 e.g.:
 gSystem->SetMakeSharedLib(
 "KCC -n32 --strict $IncludePath -K0 -O0 -g $SourceFile
  --no_exceptions --signed_chars --display_error_number
  --diag_suppress 68 -o $SharedLib");

 gSystem->setMakeSharedLib(
 "Cxx $IncludePath -c $SourceFile;
  ld  -L/usr/lib/cmplrs/cxx -rpath /usr/lib/cmplrs/cxx -expect_unresolved
  -g0 -O1 -shared /usr/lib/cmplrs/cc/crt0.o /usr/lib/cmplrs/cxx/_main.o
  -o $SharedLib $ObjectFile -lcxxstd -lcxx -lexc -lots -lc"

 gSystem->SetMakeSharedLib(
 "$HOME/mygcc/bin/g++ -Wall -fPIC $IncludePath $SourceFile
  -shared -o $SharedLib");

 gSystem->SetMakeSharedLib(
 "cl -DWIN32  -D_WIN32 -D_MT -D_DLL -MD /O2 /G5 /MD -DWIN32
  -DVISUAL_CPLUSPLUS -D_WINDOWS $IncludePath $SourceFile
  /link -PDB:NONE /NODEFAULTLIB /INCREMENTAL:NO /RELEASE /NOLOGO
  $LinkedLibs -entry:_DllMainCRTStartup@12 -dll /out:$SharedLib")

void SetIncludePath(const char *IncludePath)
 IncludePath should contain the list of compiler flags to indicate where
 to find user defined header files. It is used to expand $IncludePath in
 the directives given to SetMakeSharedLib() and SetMakeExe(), e.g.:
    gSystem->SetInclude("-I$ROOTSYS/include -Imydirectory/include");
 the default value of IncludePath on Unix is:
    "-I$ROOTSYS/include "
 and on Windows:
    "/I%ROOTSYS%/include "

void SetLinkedLibs(const char *LinkedLibs)
 LinkedLibs should contain the library directory and list of libraries
 needed to recreate the current executable. It is used to expand $LinkedLibs
 in the directives given to SetMakeSharedLib() and SetMakeExe()
 The default value on Unix is: root-config --glibs

void SetSoExt(const char *SoExt)
 Set shared library extension, should be either .so, .sl, .a, .dll, etc.

void SetObjExt(const char *ObjExt)
 Set object files extension, should be either .o, .obj, etc.

void CleanCompiledMacros()
 Remove the shared libs produced by the CompileMacro() function.



Inline Functions


        const char* GetErrorStr() const
             Bool_t InControl() const
               void ResetTimer(TTimer*)
                int mkdir(const char* name)
             Bool_t cd(const char* path)
        const char* pwd() const
            TClass* Class()
            TClass* IsA() const
               void ShowMembers(TMemberInspector& insp, char* parent)
               void Streamer(TBuffer& b)
               void StreamerNVirtual(TBuffer& b)
            TSystem TSystem(TSystem&)


Author: Fons Rademakers 15/09/95
Last update: root/base:$Name: $:$Id: TSystem.cxx,v 1.9 2000/12/07 07:25:16 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.