-//! Launch a new container from the current container
-Engines::Container_ptr Engines_Container_i::start_impl(
- const char* ContainerName ) {
- MESSAGE("start_impl argc " << _argc << " ContainerName " << ContainerName
- << hex << this << dec) ;
- _numInstanceMutex.lock() ; // lock on the instance number
-
- CORBA::Object_var obj = Engines::Container::_nil() ;
- bool nilvar = true ;
- try {
- string cont("/Containers/");
- cont += machineName() ;
- cont += "/" ;
- cont += ContainerName;
- INFOS(machineName() << " start_impl unknown container " << cont.c_str()
- << " try to Resolve" );
- obj = _NS->Resolve( cont.c_str() );
- nilvar = CORBA::is_nil( obj ) ;
- if ( nilvar ) {
- INFOS(machineName() << " start_impl unknown container "
- << ContainerName);
- }
- }
- catch (ServiceUnreachable&) {
- INFOS(machineName() << "Caught exception: Naming Service Unreachable");
- }
- catch (...) {
- INFOS(machineName() << "Caught unknown exception.");
- }
- if ( !nilvar ) {
- _numInstanceMutex.unlock() ;
- MESSAGE("start_impl container found without new launch") ;
- return Engines::Container::_narrow(obj);
- }
- int i = 0 ;
- while ( _argv[ i ] ) {
- MESSAGE(" argv" << i << " " << _argv[ i ]) ;
- i++ ;
- }
- string shstr = string(getenv("KERNEL_ROOT_DIR")) + "/bin/salome/SALOME_Container ";
-// string shstr( "./runSession SALOME_Container " ) ;
- shstr += ContainerName ;
- if ( _argc == 4 ) {
- shstr += " " ;
- shstr += _argv[ 2 ] ;
- shstr += " " ;
- shstr += _argv[ 3 ] ;
- }
- shstr += " > /tmp/" ;
- shstr += ContainerName ;
- shstr += ".log 2>&1 &" ;
- MESSAGE("system(" << shstr << ")") ;
- int status = system( shstr.c_str() ) ;
- if (status == -1) {
- INFOS("Engines_Container_i::start_impl SALOME_Container failed (system command status -1)") ;
- }
- else if (status == 217) {
- INFOS("Engines_Container_i::start_impl SALOME_Container failed (system command status 217)") ;
- }
- INFOS(machineName() << " Engines_Container_i::start_impl SALOME_Container launch done");
-
-// pid_t pid = fork() ;
-// if ( pid == 0 ) {
-// string anExe( _argv[ 0 ] ) ;
-// anExe += "runSession" ;
-// char * args[ 6 ] ;
-// args[ 0 ] = "runSession" ;
-// args[ 1 ] = "SALOME_Container" ;
-// args[ 2 ] = strdup( ContainerName ) ;
-// args[ 3 ] = strdup( _argv[ 2 ] ) ;
-// args[ 4 ] = strdup( _argv[ 3 ] ) ;
-// args[ 5 ] = NULL ;
-// MESSAGE("execl(" << anExe.c_str() << " , " << args[ 0 ] << " , "
-// << args[ 1 ] << " , " << args[ 2 ] << " , " << args[ 3 ]
-// << " , " << args[ 4 ] << ")") ;
-// int status = execv( anExe.c_str() , args ) ;
-// if (status == -1) {
-// INFOS("Engines_Container_i::start_impl execl failed (system command status -1)") ;
-// perror( "Engines_Container_i::start_impl execl error ") ;
-// }
-// else {
-// INFOS(machineName() << " Engines_Container_i::start_impl execl done");
-// }
-// exit(0) ;
-// }
-
- obj = Engines::Container::_nil() ;
- try {
- string cont("/Containers/");
- cont += machineName() ;
- cont += "/" ;
- cont += ContainerName;
- nilvar = true ;
- int count = 20 ;
- while ( nilvar && count >= 0) {
- sleep( 1 ) ;
- obj = _NS->Resolve(cont.c_str());
- nilvar = CORBA::is_nil( obj ) ;
- if ( nilvar ) {
- INFOS(count << ". " << machineName()
- << " start_impl unknown container " << cont.c_str());
- count -= 1 ;
- }
- }
- _numInstanceMutex.unlock() ;
- if ( !nilvar ) {
- MESSAGE("start_impl container found after new launch of SALOME_Container") ;