From e4ccedef6502c7fdc95ee0018b2b09ba752a09d6 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 16 Sep 2019 11:27:54 +0200 Subject: [PATCH] With kill using LifeCycle destroy extra pids registered into SALOME_ExternalServerLauncher --- src/Launcher/SALOME_ExternalServerHandler.cxx | 9 +++++++-- src/Launcher/SALOME_ExternalServerHandler.hxx | 1 + src/Launcher/SALOME_ExternalServerLauncher.cxx | 8 +++++++- src/Launcher/SALOME_ExternalServerLauncher.hxx | 3 +++ src/LifeCycleCORBA/CMakeLists.txt | 2 ++ src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 18 +++++++++++++++--- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Launcher/SALOME_ExternalServerHandler.cxx b/src/Launcher/SALOME_ExternalServerHandler.cxx index ddda9a766..14ca4cbaa 100644 --- a/src/Launcher/SALOME_ExternalServerHandler.cxx +++ b/src/Launcher/SALOME_ExternalServerHandler.cxx @@ -61,13 +61,18 @@ char *SALOME_ExternalServerHandler::getName() return CORBA::string_dup(_name.c_str()); } -void SALOME_ExternalServerHandler::killMe() +void SALOME_ExternalServerHandler::KillPID(long pid) { #ifndef WIN32 - kill(_pid,SIGTERM);//SIGTERM is emitted not SIGKILL to give _pid process a chance to trap it. + kill(pid,SIGTERM);//SIGTERM is emitted not SIGKILL to give _pid process a chance to trap it. #endif } +void SALOME_ExternalServerHandler::killMe() +{ + KillPID(_pid); +} + void SALOME_ExternalServerHandler::ping() { #ifndef WIN32 diff --git a/src/Launcher/SALOME_ExternalServerHandler.hxx b/src/Launcher/SALOME_ExternalServerHandler.hxx index 045ec4c50..1d69b78fc 100644 --- a/src/Launcher/SALOME_ExternalServerHandler.hxx +++ b/src/Launcher/SALOME_ExternalServerHandler.hxx @@ -38,6 +38,7 @@ class SALOMELAUNCHER_EXPORT SALOME_ExternalServerHandler : public POA_SALOME::Ex SALOME_ExternalServerHandler(SALOME_ExternalServerLauncher *boss, const std::string& name, SALOME_NamingService *ns, long pid); virtual ~SALOME_ExternalServerHandler(); void registerToKill(const SALOME_CPythonHelper *pyHelper) const; + static void KillPID(long pid); public: CORBA::Long getPID() override; char *getName() override; diff --git a/src/Launcher/SALOME_ExternalServerLauncher.cxx b/src/Launcher/SALOME_ExternalServerLauncher.cxx index 4574819ee..7a3f01736 100644 --- a/src/Launcher/SALOME_ExternalServerLauncher.cxx +++ b/src/Launcher/SALOME_ExternalServerLauncher.cxx @@ -40,7 +40,7 @@ #include #include -constexpr char NAME_IN_NS[]="/ExternalServers"; +const char SALOME_ExternalServerLauncher::NAME_IN_NS[]="/ExternalServers"; unsigned SALOME_ExternalServerLauncher::CNT = 0; @@ -121,6 +121,7 @@ void SALOME_ExternalServerLauncher::registerToKill(const char *server_name, CORB std::ostringstream oss; oss << "Custom_"<< server_name << "_" << CNT++; _pyHelper->registerToSalomePiDict(oss.str(),PID); + _list_of_pids_to_kill.push_back(PID); } void SALOME_ExternalServerLauncher::cleanServersInNS() @@ -138,6 +139,11 @@ void SALOME_ExternalServerLauncher::cleanServersInNS() void SALOME_ExternalServerLauncher::shutdownServers() { + for(auto pid : this->_list_of_pids_to_kill) + { + SALOME_ExternalServerHandler::KillPID(pid); + } + // std::vector lioes(ListOfExternalServersCpp(_NS)); for(auto servName : lioes) { diff --git a/src/Launcher/SALOME_ExternalServerLauncher.hxx b/src/Launcher/SALOME_ExternalServerLauncher.hxx index e83016df9..9eaa3b574 100644 --- a/src/Launcher/SALOME_ExternalServerLauncher.hxx +++ b/src/Launcher/SALOME_ExternalServerLauncher.hxx @@ -58,4 +58,7 @@ class SALOMELAUNCHER_EXPORT SALOME_ExternalServerLauncher : public POA_SALOME::E SALOME_NamingService *_NS = nullptr; PortableServer::POA_var _poa; static unsigned CNT; + std::vector _list_of_pids_to_kill; + public: + static const char NAME_IN_NS[]; }; diff --git a/src/LifeCycleCORBA/CMakeLists.txt b/src/LifeCycleCORBA/CMakeLists.txt index 10563420b..3be0eff8e 100644 --- a/src/LifeCycleCORBA/CMakeLists.txt +++ b/src/LifeCycleCORBA/CMakeLists.txt @@ -33,6 +33,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Batch ${CMAKE_CURRENT_SOURCE_DIR}/../Notification ${CMAKE_CURRENT_SOURCE_DIR}/../Registry + ${CMAKE_CURRENT_SOURCE_DIR}/../Launcher ${CMAKE_CURRENT_SOURCE_DIR}/../SALOMESDS ${PROJECT_BINARY_DIR}/idl ) @@ -47,6 +48,7 @@ SET(COMMON_LIBS SALOMEBasics SalomeGenericObj SalomeIDLKernel + SalomeLauncher ) ADD_DEFINITIONS(${OMNIORB_DEFINITIONS}) diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 1e3ce0cda..5351562b6 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -44,6 +44,7 @@ #include "SALOME_LifeCycleCORBA.hxx" #include "SALOME_ResourcesManager.hxx" #include "SALOMESDS_DataServerManager.hxx" +#include "SALOME_ExternalServerLauncher.hxx" #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog) #include CORBA_CLIENT_HEADER(SALOME_Session) @@ -499,7 +500,7 @@ void SALOME_LifeCycleCORBA::shutdownServers(bool shutdownLauncher) #ifndef WIN32 nanosleep(&ts_req,0); #endif - // 4 ) Remote ScopeServer (the DataServer is hosted by SalomeLauncher shutdown right after) + // 4 ) Remote ScopeServer (the DataServer is hosted by SalomeLauncher shutdown right after on point 6) try { CORBA::Object_var objDSM(_NS->Resolve(SALOMESDS::DataServerManager::NAME_IN_NS)); @@ -511,8 +512,19 @@ void SALOME_LifeCycleCORBA::shutdownServers(bool shutdownLauncher) { // ignore and continue } - - // 5) SalomeLauncher + // 5) External server launcher (the ExternalServer is hosted by SalomeLauncher shutdown right after on point 6) + try + { + CORBA::Object_var objDSM(_NS->Resolve(SALOME_ExternalServerLauncher::NAME_IN_NS)); + SALOME::ExternalServerLauncher_var dsm(SALOME::ExternalServerLauncher::_narrow(objDSM)); + if ( !CORBA::is_nil(dsm) ) + dsm->shutdownServers(); + } + catch(const CORBA::Exception& e) + { + // ignore and continue + } + // 6) SalomeLauncher try { if(shutdownLauncher){ -- 2.39.2