]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Add current directory to esm.launchServer
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 18 Jun 2019 14:04:27 +0000 (16:04 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 18 Jun 2019 14:04:27 +0000 (16:04 +0200)
idl/SALOME_ExternalServerLauncher.idl
src/Launcher/SALOME_ExternalServerLauncher.cxx
src/Launcher/SALOME_ExternalServerLauncher.hxx

index 7344d20226769eb4fe0f9ad7006194919d06daad..cee79cb764998124056124297c168492d8f82afe 100644 (file)
@@ -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);
index 39ff157a2c2961513c5b20951ac72a6e44e340e6..6ef363251df58058263b02bce276b0fdf858011d 100644 (file)
@@ -27,6 +27,8 @@
 
 #include CORBA_CLIENT_HEADER(SALOME_ExternalServerLauncher)
 
+#include <unistd.h>
+
 #include <sstream>
 #include <algorithm>
 
@@ -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<std::string> 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)
index 474949d1e82ef34709cbe79b8283791215c76ad9..32824e6d5caac5c3ea15a83e1cc377f7454a65b7 100644 (file)
@@ -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;