Back to index

salome-kernel  6.5.0
Defines | Functions | Variables
Container_i.cxx File Reference
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
#include <dlfcn.h>
#include <unistd.h>
#include <sys/wait.h>
#include "utilities.h"
#include <SALOMEconfig.h>
#include <pthread.h>
#include "SALOME_Container_i.hxx"
#include "SALOME_Component_i.hxx"
#include "SALOME_FileRef_i.hxx"
#include "SALOME_FileTransfer_i.hxx"
#include "Salome_file_i.hxx"
#include "SALOME_NamingService.hxx"
#include "Basics_Utils.hxx"
#include <Python.h>
#include "Container_init_python.hxx"

Go to the source code of this file.

Defines

#define LIB   "lib"
#define ENGINESO   "Engine.so"
#define SEP   ':'
#define SLASH   '/'

Functions

void ActSigIntHandler ()
void SigIntHandler (int, siginfo_t *, void *)
int checkifexecutable (const std::string &)
int findpathof (const std::string &path, std::string &pth, const std::string &filename)
 Find a file by searching in a path.
void SetCpuUsed ()
 C++ method:
void CallCancelThread ()

Variables

bool _Sleeping = false
int _ArgC
char ** _ArgV
static PyObject * _pyCont

Define Documentation

#define ENGINESO   "Engine.so"

Definition at line 81 of file Container_i.cxx.

#define LIB   "lib"

Definition at line 80 of file Container_i.cxx.

#define SEP   ':'

Definition at line 91 of file Container_i.cxx.

#define SLASH   '/'

Definition at line 92 of file Container_i.cxx.


Function Documentation

void ActSigIntHandler ( )

Definition at line 1327 of file Container_i.cxx.

{
#ifndef WIN32
  struct sigaction SigIntAct ;
  SigIntAct.sa_sigaction = &SigIntHandler ;
  sigemptyset(&SigIntAct.sa_mask);
  SigIntAct.sa_flags = SA_SIGINFO ;
#endif

  // DEBUG 03.02.2005 : the first parameter of sigaction is not a mask of signals
  // (SIGINT | SIGUSR1) :
  // it must be only one signal ===> one call for SIGINT 
  // and an other one for SIGUSR1

#ifndef WIN32
  if ( sigaction( SIGINT , &SigIntAct, NULL ) ) 
  {
    perror("SALOME_Container main ") ;
    exit(0) ;
  }
  if ( sigaction( SIGUSR1 , &SigIntAct, NULL ) )
  {
    perror("SALOME_Container main ") ;
    exit(0) ;
  }
  if ( sigaction( SIGUSR2 , &SigIntAct, NULL ) )
  {
    perror("SALOME_Container main ") ;
    exit(0) ;
  }

  //PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers)
  //             use of streams (and so on) should never be used because :
  //             streams of C++ are naturally thread-safe and use pthread_mutex_lock ===>
  //             A stream operation may be interrupted by a signal and if the Handler use stream we
  //             may have a "Dead-Lock" ===HangUp
  //==INFOS is commented
  //  INFOS(pthread_self() << "SigIntHandler activated") ;

#else  
  signal( SIGINT, SigIntHandler );
  signal( SIGUSR1, SigIntHandler );
#endif

}

Here is the call graph for this function:

Here is the caller graph for this function:

void CallCancelThread ( )

Definition at line 857 of file Component_i.cxx.

{
  if ( theEngines_Component )
    theEngines_Component->CancelThread() ;
}
int checkifexecutable ( const std::string &  filename)

Definition at line 1700 of file Container_i.cxx.

{
  int result;
  struct stat statinfo;

  result = stat(filename.c_str(), &statinfo);
  if (result < 0) return 0;
  if (!S_ISREG(statinfo.st_mode)) return 0;

#ifdef WIN32
  return 1;
#else
  if (statinfo.st_uid == geteuid()) return statinfo.st_mode & S_IXUSR;
  if (statinfo.st_gid == getegid()) return statinfo.st_mode & S_IXGRP;
  return statinfo.st_mode & S_IXOTH;
#endif
}
int findpathof ( const std::string &  path,
std::string &  pth,
const std::string &  filename 
)

Find a file by searching in a path.

Parameters:
filenamefile name to search
pathpath to search in
pththe complete file path if found
Returns:
1 if found 0 if not

Definition at line 1727 of file Container_i.cxx.

{
  if ( path.size() == 0 ) return 0;

  std::string::size_type offset = 0;
  std::string::size_type pos = 0;
  int found = 0;
  struct stat statinfo;

  while(!found)
  {
    pos = path.find( SEP, offset );
    pth = path.substr( offset, pos - offset );
    if ( pth.size() > 0 )
    {
      if( pth[pth.size()-1] != SLASH ) pth += SLASH;
      pth += filename;
      int result=stat(pth.c_str(), &statinfo);
      if(result == 0) found=1;
    }
    if (pos == std::string::npos) break;
    offset = pos+1;
  }
  return found;
}
void SetCpuUsed ( )

C++ method:

Definition at line 798 of file Component_i.cxx.

{
  if ( theEngines_Component )
    theEngines_Component->SetCurCpu() ;
}
void SigIntHandler ( int  what,
siginfo_t *  siginfo,
void *  toto 
)

Definition at line 1377 of file Container_i.cxx.

{
  //PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers)
  //             use of streams (and so on) should never be used because :
  //             streams of C++ are naturally thread-safe and use pthread_mutex_lock ===>
  //             A stream operation may be interrupted by a signal and if the Handler use stream we
  //             may have a "Dead-Lock" ===HangUp
  //==MESSAGE is commented
  //  MESSAGE(pthread_self() << "SigIntHandler what     " << what << std::endl
  //          << "              si_signo " << siginfo->si_signo << std::endl
  //          << "              si_code  " << siginfo->si_code << std::endl
  //          << "              si_pid   " << siginfo->si_pid) ;

  if ( _Sleeping )
  {
    _Sleeping = false ;
    //     MESSAGE("SigIntHandler END sleeping.") ;
    return ;
  }
  else
  {
    ActSigIntHandler() ;
    if ( siginfo->si_signo == SIGUSR1 )
    {
      SetCpuUsed() ;
    }
    else if ( siginfo->si_signo == SIGUSR2 )
    {
      CallCancelThread() ;
    }
    else 
    {
      _Sleeping = true ;
      //      MESSAGE("SigIntHandler BEGIN sleeping.") ;
      int count = 0 ;
      while( _Sleeping )
      {
        sleep( 1 ) ;
        count += 1 ;
      }
      //      MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ;
    }
    return ;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int _ArgC

Definition at line 69 of file Container_i.cxx.

char** _ArgV

Definition at line 70 of file Container_i.cxx.

PyObject* _pyCont [static]

Definition at line 100 of file Container_i.cxx.

bool _Sleeping = false

Definition at line 66 of file Container_i.cxx.