From 962f1dde5aaf045482f19e59b647234cc187e90d Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 18 Jun 2019 16:04:27 +0200 Subject: [PATCH] Add current directory to esm.launchServer --- idl/SALOME_ExternalServerLauncher.idl | 2 +- src/Launcher/SALOME_ExternalServerLauncher.cxx | 15 ++++++++++++++- src/Launcher/SALOME_ExternalServerLauncher.hxx | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/idl/SALOME_ExternalServerLauncher.idl b/idl/SALOME_ExternalServerLauncher.idl index 7344d2022..cee79cb76 100644 --- a/idl/SALOME_ExternalServerLauncher.idl +++ b/idl/SALOME_ExternalServerLauncher.idl @@ -40,7 +40,7 @@ module SALOME interface ExternalServerLauncher { - ExternalServerHandler launchServer( in string server_name, in CmdList command_list ) raises(SALOME::SALOME_Exception); + ExternalServerHandler launchServer( in string server_name, in string working_dir, in CmdList command_list ) raises(SALOME::SALOME_Exception); void cleanServersInNS(); StringVec listServersInNS(); ExternalServerHandler retrieveServerRefGivenNSEntry( in string ns_entry ) raises(SALOME::SALOME_Exception); diff --git a/src/Launcher/SALOME_ExternalServerLauncher.cxx b/src/Launcher/SALOME_ExternalServerLauncher.cxx index 39ff157a2..6ef363251 100644 --- a/src/Launcher/SALOME_ExternalServerLauncher.cxx +++ b/src/Launcher/SALOME_ExternalServerLauncher.cxx @@ -27,6 +27,8 @@ #include CORBA_CLIENT_HEADER(SALOME_ExternalServerLauncher) +#include + #include #include @@ -48,7 +50,17 @@ SALOME_ExternalServerLauncher::~SALOME_ExternalServerLauncher() delete _NS; } -SALOME::ExternalServerHandler_ptr SALOME_ExternalServerLauncher::launchServer(const char *server_name, const SALOME::CmdList& command_list ) +class ChdirRAII +{ +public: + ChdirRAII(const std::string& wd):_wd(wd) { if(_wd.empty()) return ; char *pwd(get_current_dir_name()); _od = pwd; free(pwd); chdir(_wd.c_str()); } + ~ChdirRAII() { if(_od.empty()) return ; chdir(_od.c_str()); } +private: + std::string _wd; + std::string _od; +}; + +SALOME::ExternalServerHandler_ptr SALOME_ExternalServerLauncher::launchServer(const char *server_name, const char *working_dir, const SALOME::CmdList& command_list ) { std::vector servers(ListOfExternalServersCpp(_NS)); if(std::find(servers.begin(),servers.end(),server_name)!=servers.end()) @@ -63,6 +75,7 @@ SALOME::ExternalServerHandler_ptr SALOME_ExternalServerLauncher::launchServer(co long pid(0); try { + ChdirRAII cr(working_dir); pid = SALOME_ContainerManager::SystemWithPIDThreadSafe(cmd) ; } catch(SALOME_Exception& e) diff --git a/src/Launcher/SALOME_ExternalServerLauncher.hxx b/src/Launcher/SALOME_ExternalServerLauncher.hxx index 474949d1e..32824e6d5 100644 --- a/src/Launcher/SALOME_ExternalServerLauncher.hxx +++ b/src/Launcher/SALOME_ExternalServerLauncher.hxx @@ -38,7 +38,7 @@ class SALOMELAUNCHER_EXPORT SALOME_ExternalServerLauncher : public POA_SALOME::E SALOME_ExternalServerLauncher(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_var poa); virtual ~SALOME_ExternalServerLauncher(); public: - SALOME::ExternalServerHandler_ptr launchServer(const char *server_name, const SALOME::CmdList& command_list ) override; + SALOME::ExternalServerHandler_ptr launchServer(const char *server_name, const char *working_dir, const SALOME::CmdList& command_list ) override; void registerToKill(const char *server_name, CORBA::Long PID) override; void cleanServersInNS() override; void shutdownServers() override; -- 2.39.2