From 9484eae0407296e960cb8468cf279bd87a65a41e Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Fri, 6 Mar 2015 11:59:11 +0100 Subject: [PATCH] if USER env variable is not defined, search for LOGNAME --- bin/appliskel/kill_remote_containers.py | 5 +- bin/appliskel/update_catalogs.py | 7 +- bin/killSalome.py | 3 +- bin/runSalome.py | 3 +- bin/runSession.py | 5 +- bin/salome_utils.py | 8 +- src/Container/SALOME_ContainerManager.cxx | 179 ++++++++++++---------- src/Container/SALOME_ContainerManager.hxx | 21 +-- src/Launcher/Launcher_Job.cxx | 90 +++++------ src/ModuleGenerator/IDLparser.py | 3 +- 10 files changed, 179 insertions(+), 145 deletions(-) diff --git a/bin/appliskel/kill_remote_containers.py b/bin/appliskel/kill_remote_containers.py index 82f750e46..45f16f7a1 100755 --- a/bin/appliskel/kill_remote_containers.py +++ b/bin/appliskel/kill_remote_containers.py @@ -26,6 +26,7 @@ """ import sys,os,shutil,glob,socket import optparse +from salome_utils import getUserName import getAppliPath appli_local=os.path.realpath(os.path.dirname(__file__)) @@ -90,7 +91,7 @@ class Resource: def get_user(self): userName= self.node.get("userName") if not userName: - userName=os.getenv('USER') + userName=getUserName() return userName def get_host(self): @@ -110,7 +111,7 @@ class Resource: def main(): parser = optparse.OptionParser(usage=usage) - parser.add_option('-p','--port', dest="port", + parser.add_option('-p','--port', dest="port", help="The SALOME session port (default NSPORT or 2810)") diff --git a/bin/appliskel/update_catalogs.py b/bin/appliskel/update_catalogs.py index ce54f8c4a..b9c117382 100644 --- a/bin/appliskel/update_catalogs.py +++ b/bin/appliskel/update_catalogs.py @@ -26,6 +26,7 @@ """ import sys,os,shutil,glob,socket import optparse +from salome_utils import getUserName import getAppliPath appli_local=os.path.realpath(os.path.dirname(__file__)) @@ -116,7 +117,7 @@ class Resource: def get_user(self): userName= self.node.get("userName") if not userName: - userName=os.getenv('USER') + userName=getUserName() return userName def get_host(self): @@ -143,7 +144,7 @@ class Resource: resource_dir=os.path.join(cata_dir,self.get_name()) - if hostname == "localhost" or hostname == get_hostname() and userName == os.getenv("USER"): + if hostname == "localhost" or hostname == get_hostname() and userName == getUserName(): #local machine, use cp if appliPath[0]!='/': #relative path @@ -187,7 +188,7 @@ class Resource: resource_dir=os.path.join(cata_dir,self.get_name()) catalogs_list=glob.glob(os.path.join(resource_dir,"*Catalog.xml")) - if hostname == "localhost" or hostname == get_hostname() and userName == os.getenv("USER"): + if hostname == "localhost" or hostname == get_hostname() and userName == getUserName(): #user local resource if appliPath[0]!='/': appliPath=os.path.join(os.getenv("HOME"),appliPath) diff --git a/bin/killSalome.py b/bin/killSalome.py index 24e125f07..73aaf78f1 100755 --- a/bin/killSalome.py +++ b/bin/killSalome.py @@ -30,12 +30,13 @@ import os, sys, re, signal from killSalomeWithPort import killMyPort, getPiDict #from salome_utils import getHostName, getShortHostName +from salome_utils import getUserName def killAllPorts(): """ Kill all SALOME sessions belonging to the user. """ - user = os.getenv('USER') + user = getUserName() #hostname = getHostName() #shostname = getShortHostName() # new-style dot-prefixed pidict file diff --git a/bin/runSalome.py b/bin/runSalome.py index 73a8b0df2..6439d4e54 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -773,7 +773,8 @@ def registerEnv(args, modules_list, modules_root_dir): """ from salome_utils import getTmpDir fileEnv = getTmpDir() - fileEnv += os.getenv('USER') + "_" + str(args['port']) \ + from salome_utils import getUserName + fileEnv += getUserName() + "_" + str(args['port']) \ + '_' + args['appname'].upper() + '_env' fenv=open(fileEnv,'w') pickle.dump((args, modules_list, modules_root_dir),fenv) diff --git a/bin/runSession.py b/bin/runSession.py index cbc556e83..5f6cc7822 100644 --- a/bin/runSession.py +++ b/bin/runSession.py @@ -29,6 +29,7 @@ import socket import subprocess import re from salomeContextUtils import getScriptsAndArgs, formatScriptsAndArgs, getShortAndExtraArgs +from salome_utils import getUserName # Use to display newlines (\n) in epilog class MyParser(OptionParser): @@ -132,7 +133,7 @@ User "myself" connects to remotemachine to run the script concatenate.py in # neither MACHINE nor PORT are given # --- set omniORB configuration to current session if any omniorbUserPath = os.environ['OMNIORB_USER_PATH'] - fileOmniConfig = omniorbUserPath + '/.omniORB_' + os.environ['USER'] + '_last.cfg' + fileOmniConfig = omniorbUserPath + '/.omniORB_' + getUserName() + '_last.cfg' if os.path.isfile(fileOmniConfig): os.environ['OMNIORB_CONFIG'] = fileOmniConfig # --- set environment variables for port and hostname of NamingService @@ -169,7 +170,7 @@ User "myself" connects to remotemachine to run the script concatenate.py in # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME def _writeConfigFile(port, host): path = os.environ['OMNIORB_USER_PATH'] - kwargs = {'with_username' : os.environ['USER']} + kwargs = {'with_username' : getUserName()} from ORBConfigFile import writeORBConfigFile [ filename, msgSize ] = writeORBConfigFile(path, host, port, kwargs) diff --git a/bin/salome_utils.py b/bin/salome_utils.py index c19443595..090332386 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -127,13 +127,17 @@ def getUserName(): """ Get user name: 1. try USER environment variable (USERNAME on windows) - 2. if fails, return 'unknown' as default user name + 2. if fails, try LOGNAME (un*x) + 3. if fails return 'unknown' as default user name """ import os, sys if sys.platform == "win32": return os.getenv("USERNAME", "unknown") else: - return os.getenv("USER", "unknown") + user = os.getenv("USER") + if user: + return user + return os.getenv("LOGNAME", "unknown") # --- def getHostName(): diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 6ec2f9cd6..23ff57b31 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -57,7 +57,7 @@ const int SALOME_ContainerManager::TIME_OUT_TO_LAUNCH_CONT=60; -const char *SALOME_ContainerManager::_ContainerManagerNameInNS = +const char *SALOME_ContainerManager::_ContainerManagerNameInNS = "/ContainerManager"; omni_mutex SALOME_ContainerManager::_numInstanceMutex; @@ -67,7 +67,7 @@ Utils_Mutex SALOME_ContainerManager::_getenvMutex; Utils_Mutex SALOME_ContainerManager::_systemMutex; //============================================================================= -/*! +/*! * Constructor * \param orb * Define a CORBA single thread policy for the server, which avoid to deal @@ -104,7 +104,7 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer _pid_mpiServer = -1; // the urifile name depends on pid of the process std::stringstream urifile; - urifile << GetenvThreadSafe("HOME") << "/.urifile_" << getpid(); + urifile << GetenvThreadSafeAsString("HOME") << "/.urifile_" << getpid(); setenv("OMPI_URI_FILE",urifile.str().c_str(),1); if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){ // get the pid of all ompi-server @@ -112,7 +112,7 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer // launch a new ompi-server std::string command; command = "ompi-server -r "; - command += GetenvThreadSafe("OMPI_URI_FILE"); + command += GetenvThreadSafeAsString("OMPI_URI_FILE"); int status=SystemThreadSafe(command.c_str()); if(status!=0) throw SALOME_Exception("Error when launching ompi-server"); @@ -148,7 +148,7 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer } //============================================================================= -/*! +/*! * destructor */ //============================================================================= @@ -248,7 +248,7 @@ void SALOME_ContainerManager::ShutdownContainers() MESSAGE("ShutdownContainers: " << (*iter)); cont->Shutdown(); } - else + else MESSAGE("ShutdownContainers: no container ref for " << (*iter)); } catch(CORBA::SystemException& e) @@ -314,7 +314,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con MESSAGE("[GiveContainer] - length of possible resources " << possibleResources.size()); std::vector local_resources; - // Step 3: if mode is "get" keep only machines with existing containers + // Step 3: if mode is "get" keep only machines with existing containers if(mode == "get") { for(unsigned int i=0; i < possibleResources.size(); i++) @@ -524,14 +524,14 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par else { ASSERT(GetenvThreadSafe("APPLI")); - command += GetenvThreadSafe("APPLI"); + command += GetenvThreadSafeAsString("APPLI"); } command += "/runRemote.sh "; ASSERT(GetenvThreadSafe("NSHOST")); - command += GetenvThreadSafe("NSHOST"); // hostname of CORBA name server + command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server command += " "; ASSERT(GetenvThreadSafe("NSPORT")); - command += GetenvThreadSafe("NSPORT"); // port of CORBA name server + command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server command += " \"ls /tmp >/dev/null 2>&1\""; // Launch remote command @@ -570,11 +570,13 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par //redirect stdout and stderr in a file #ifdef WIN32 - logFilename=GetenvThreadSafe("TEMP"); + logFilename=GetenvThreadSafeAsString("TEMP"); logFilename += "\\"; - user = GetenvThreadSafe( "USERNAME" ); + user = GetenvThreadSafeAsString( "USERNAME" ); #else - user = GetenvThreadSafe( "USER" ); + user = GetenvThreadSafeAsString( "USER" ); + if (user.empty()) + user = GetenvThreadSafeAsString( "LOGNAME" ); logFilename="/tmp"; char* val = GetenvThreadSafe("SALOME_TMP_DIR"); if(val) @@ -697,7 +699,7 @@ bool isPythonContainer(const char* ContainerName); //============================================================================= /*! * This is no longer valid (C++ container are also python containers) - */ + */ //============================================================================= bool isPythonContainer(const char* ContainerName) { @@ -732,7 +734,7 @@ bool isPythonContainer(const char* ContainerName) * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh) * - where workingdir is the requested working directory for the container. * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME - */ + */ //============================================================================= std::string @@ -763,17 +765,17 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& else { ASSERT(GetenvThreadSafe("APPLI")); - command += GetenvThreadSafe("APPLI"); // path relative to user@machine $HOME + command += GetenvThreadSafeAsString("APPLI"); // path relative to user@machine $HOME } command += "/runRemote.sh "; ASSERT(GetenvThreadSafe("NSHOST")); - command += GetenvThreadSafe("NSHOST"); // hostname of CORBA name server + command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server command += " "; ASSERT(GetenvThreadSafe("NSPORT")); - command += GetenvThreadSafe("NSPORT"); // port of CORBA name server + command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server std::string wdir = params.workingdir.in(); if(wdir != "") @@ -783,7 +785,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& if(wdir == "$TEMPDIR") wdir="\\$TEMPDIR"; command += wdir; // requested working directory - command += "'"; + command += "'"; } if(params.isMPI) @@ -799,11 +801,11 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace"; else{ command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:"; - command += GetenvThreadSafe("OMPI_URI_FILE"); + command += GetenvThreadSafeAsString("OMPI_URI_FILE"); } #elif defined(MPICH) command += "-nameserver " + Kernel_Utils::GetHostname(); -#endif +#endif command += " SALOME_MPIContainer "; } else @@ -822,7 +824,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& //============================================================================= /*! * builds the command to be launched. - */ + */ //============================================================================= std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe, std::string& tmpFileName) const { @@ -854,7 +856,7 @@ std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const En else { o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:"; - o << GetenvThreadSafe("OMPI_URI_FILE"); + o << GetenvThreadSafeAsString("OMPI_URI_FILE"); } #elif defined(MPICH) o << "-nameserver " + Kernel_Utils::GetHostname(); @@ -925,7 +927,7 @@ std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const En /*! * removes the generated temporary file in case of a remote launch. * This method is thread safe - */ + */ //============================================================================= void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName) @@ -936,7 +938,7 @@ void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName) #ifdef WIN32 std::string command = "del /F "; #else - std::string command = "rm "; + std::string command = "rm "; #endif if ( lenght > 4 ) command += tmpFileName.substr(0, lenght - 3 ); @@ -961,7 +963,7 @@ void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName) //============================================================================= /*! * add to command all options relative to naming service. - */ + */ //============================================================================= void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const @@ -974,7 +976,7 @@ void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const //============================================================================= /*! * add to command all options relative to naming service. - */ + */ //============================================================================= void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const @@ -985,7 +987,7 @@ void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const //============================================================================= /*! * add to command all options relative to naming service. - */ + */ //============================================================================= void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns) @@ -1009,7 +1011,7 @@ int SALOME_ContainerManager::GetTimeOutToLoaunchServer() int count(TIME_OUT_TO_LAUNCH_CONT); if (GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER") != 0) { - std::string new_count_str(GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER")); + std::string new_count_str(GetenvThreadSafeAsString("TIMEOUT_TO_LAUNCH_CONTAINER")); int new_count; std::istringstream ss(new_count_str); if (!(ss >> new_count)) @@ -1035,7 +1037,7 @@ void SALOME_ContainerManager::SleepInSecond(int ellapseTimeInSecond) //============================================================================= /*! * generate a file name in /tmp directory - */ + */ //============================================================================= std::string SALOME_ContainerManager::BuildTemporaryFileName() @@ -1053,11 +1055,11 @@ std::string SALOME_ContainerManager::BuildTemporaryFileName() //============================================================================= /*! * Builds in a temporary file the script to be launched. - * + * * Used if SALOME Application ($APPLI) is not defined. * The command is build with data from CatalogResources, in which every path * used on remote computer must be defined. - */ + */ //============================================================================= std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const std::string& resource_name, const Engines::ContainerParameters& params, std::string& tmpFileName) const @@ -1097,14 +1099,14 @@ std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace"; else{ tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:"; - tempOutputFile << GetenvThreadSafe("OMPI_URI_FILE"); + tempOutputFile << GetenvThreadSafeAsString("OMPI_URI_FILE"); } #elif defined(MPICH) tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname(); #endif } - tempOutputFile << GetenvThreadSafe("KERNEL_ROOT_DIR") << "/bin/salome/"; + tempOutputFile << GetenvThreadSafeAsString("KERNEL_ROOT_DIR") << "/bin/salome/"; if (params.isMPI) { @@ -1174,7 +1176,7 @@ std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const throw SALOME_Exception("Unknown protocol"); if(status) - throw SALOME_Exception("Error of connection on remote host"); + throw SALOME_Exception("Error of connection on remote host"); command += resInfo.HostName; command += " "; @@ -1223,17 +1225,17 @@ std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, c else { ASSERT(GetenvThreadSafe("APPLI")); - command += GetenvThreadSafe("APPLI"); // path relative to user@machine $HOME + command += GetenvThreadSafeAsString("APPLI"); // path relative to user@machine $HOME } command += "/runRemote.sh "; ASSERT(GetenvThreadSafe("NSHOST")); - command += GetenvThreadSafe("NSHOST"); // hostname of CORBA name server + command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server command += " "; ASSERT(GetenvThreadSafe("NSPORT")); - command += GetenvThreadSafe("NSPORT"); // port of CORBA name server + command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server command += " mpirun -np 1 hostname -s > " + tmpFile; } @@ -1257,7 +1259,7 @@ std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, c std::string SALOME_ContainerManager::machinesFile(const int nbproc) { std::string tmp; - std::string nodesFile = GetenvThreadSafe("LIBBATCH_NODEFILE"); + std::string nodesFile = GetenvThreadSafeAsString("LIBBATCH_NODEFILE"); std::string machinesFile = Kernel_Utils::GetTmpFileName(); std::ifstream fpi(nodesFile.c_str(),std::ios::in); std::ofstream fpo(machinesFile.c_str(),std::ios::out); @@ -1339,11 +1341,11 @@ std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocol return command.str(); } -bool +bool SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected) { bool result = true; - + // Step 1 : check ContainerParameters // Check container_name, has to be defined if (std::string(params.container_name.in()) == "") @@ -1388,12 +1390,28 @@ SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & para return result; } +/* + * :WARNING: Do not directly convert returned value to std::string + * This function may return NULL if env variable is not defined. + * And std::string(NULL) causes undefined behavior. + * Use GetenvThreadSafeAsString to properly get a std::string. +*/ char *SALOME_ContainerManager::GetenvThreadSafe(const char *name) {// getenv is not thread safe. See man 7 pthread. Utils_Locker lock (&_getenvMutex); return getenv(name); } +/* + * Return env variable as a std::string. + * Return empty string if env variable is not set. + */ +std::string SALOME_ContainerManager::GetenvThreadSafeAsString(const char *name) +{ + char* var = GetenvThreadSafe(name); + return var ? std::string(var) : std::string(); +} + int SALOME_ContainerManager::SystemThreadSafe(const char *command) { Utils_Locker lock (&_systemMutex); @@ -1444,7 +1462,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters // Step 3 : starting parallel container proxy std::string command_proxy(""); std::string proxy_machine; - try + try { command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine); } @@ -1466,7 +1484,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters // Step 4 : starting parallel container nodes std::string command_nodes(""); SALOME_ContainerManager::actual_launch_machine_t nodes_machines; - try + try { command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine); } @@ -1483,7 +1501,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters { INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !"); // Il faut tuer le proxy - try + try { Engines::Container_var proxy = Engines::Container::_narrow(container_proxy); proxy->Shutdown(); @@ -1496,7 +1514,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters } // Step 4 : connecting nodes and the proxy to actually create a parallel container - for (int i = 0; i < params.nb_proc; i++) + for (int i = 0; i < params.nb_proc; i++) { std::ostringstream tmp; tmp << i; @@ -1506,7 +1524,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters std::string theNodeMachine(nodes_machines[i]); std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str()); obj = _NS->Resolve(containerNameInNS.c_str()); - if (CORBA::is_nil(obj)) + if (CORBA::is_nil(obj)) { INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !"); INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS); @@ -1540,7 +1558,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters } // Step 5 : starting parallel container - try + try { MESSAGE ("[StarPaCOPPContainer] Starting parallel object"); container_proxy->start(); @@ -1561,7 +1579,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters } catch(std::exception& exc) { - INFOS("Caught std::exception - "<&1 & "; } } -CORBA::Object_ptr -SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, +CORBA::Object_ptr +SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, const Engines::ContainerParameters& params, const std::string & hostname) { @@ -1875,18 +1896,18 @@ SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, int count(GetTimeOutToLoaunchServer()); CORBA::Object_var obj = CORBA::Object::_nil(); - std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(), + std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(), hostname.c_str()); MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS); - while (CORBA::is_nil(obj) && count) + while (CORBA::is_nil(obj) && count) { sleep(1); count--; obj = _NS->Resolve(containerNameInNS.c_str()); } - try + try { container_proxy = PaCO::InterfaceManager::_narrow(obj); } @@ -1928,7 +1949,7 @@ SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, */ //============================================================================= bool -SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command, +SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command, const Engines::ContainerParameters& params, const std::string& name, SALOME_ContainerManager::actual_launch_machine_t & vect_machine) @@ -1946,7 +1967,7 @@ SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command, INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container"); // We are waiting all the nodes - for (int i = 0; i < params.nb_proc; i++) + for (int i = 0; i < params.nb_proc; i++) { CORBA::Object_var obj = CORBA::Object::_nil(); std::string theMachine(vect_machine[i]); @@ -1984,7 +2005,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters return ret; } -std::string +std::string SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params, std::string machine_file_name, std::string & proxy_hostname) @@ -1992,26 +2013,26 @@ SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::C return ""; } -std::string +std::string SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params, const std::string & machine_file_name, - SALOME_ContainerManager::actual_launch_machine_t & vect_machine, - const std::string & proxy_hostname) + SALOME_ContainerManager::actual_launch_machine_t & vect_machine, + const std::string & proxy_hostname) { return ""; } -void +void SALOME_ContainerManager::LogConfiguration(const std::string & log_type, const std::string & exe_type, const std::string & container_name, const std::string & hostname, - std::string & begin, + std::string & begin, std::string & end) { } -CORBA::Object_ptr -SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, +CORBA::Object_ptr +SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, const Engines::ContainerParameters& params, const std::string& hostname) { @@ -2019,8 +2040,8 @@ SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command, return ret; } -bool -SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command, +bool +SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command, const Engines::ContainerParameters& params, const std::string& name, SALOME_ContainerManager::actual_launch_machine_t & vect_machine) diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 4e6b71279..8a49e05ba 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -66,7 +66,7 @@ protected: const std::string& resource); std::string BuildCommandToLaunchRemoteContainer(const std::string & resource_name, - const Engines::ContainerParameters& params, + const Engines::ContainerParameters& params, const std::string& container_exe="SALOME_Container") const; std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, @@ -106,7 +106,7 @@ protected: SALOME_ResourcesManager_Client *_resManager; SALOME_NamingService *_NS; - //! different behaviour if $APPLI exists (SALOME Application) + //! different behaviour if $APPLI exists (SALOME Application) bool _isAppliSalomeDefined; //! attribute that contains the number of processes used in batch mode by MPI containers @@ -124,7 +124,7 @@ protected: bool checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected); - Engines::Container_ptr + Engines::Container_ptr StartPaCOPPContainer(const Engines::ContainerParameters& params, std::string resource_selected); @@ -135,29 +135,30 @@ protected: std::string BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params, const std::string & machine_file_name, - SALOME_ContainerManager::actual_launch_machine_t & vect_machine, - const std::string & proxy_hostname); + SALOME_ContainerManager::actual_launch_machine_t & vect_machine, + const std::string & proxy_hostname); void LogConfiguration(const std::string & log_type, const std::string & exe_type, const std::string & container_name, const std::string & hostname, - std::string & begin, + std::string & begin, std::string & end); - CORBA::Object_ptr - LaunchPaCOProxyContainer(const std::string& command, + CORBA::Object_ptr + LaunchPaCOProxyContainer(const std::string& command, const Engines::ContainerParameters& params, const std::string& hostname); - bool - LaunchPaCONodeContainer(const std::string& command, + bool + LaunchPaCONodeContainer(const std::string& command, const Engines::ContainerParameters& params, const std::string& name, SALOME_ContainerManager::actual_launch_machine_t & vect_machine); // End of PaCO++ Parallel extension public: static char *GetenvThreadSafe(const char *name); + static std::string GetenvThreadSafeAsString(const char *name); static int SystemThreadSafe(const char *command); static void AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns); static void MakeTheCommandToBeLaunchedASync(std::string& command); diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index 40b3abe1c..128860953 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -59,7 +59,7 @@ Launcher::Job::Job() #endif } -Launcher::Job::~Job() +Launcher::Job::~Job() { LAUNCHER_MESSAGE("Deleting job number: " << _number); #ifdef WITH_LIBBATCH @@ -76,7 +76,7 @@ Launcher::Job::stopJob() #ifdef WITH_LIBBATCH if (_batch_job_id.getReference() != "undefined") { - try + try { _batch_job_id.deleteJob(); } @@ -96,7 +96,7 @@ Launcher::Job::removeJob() #ifdef WITH_LIBBATCH if (_batch_job_id.getReference() != "undefined") { - try + try { _batch_job_id.deleteJob(); } @@ -126,7 +126,7 @@ Launcher::Job::getJobName() const return _job_name; } -void +void Launcher::Job::setState(const std::string & state) { // State of a Job: CREATED, QUEUED, RUNNING, FINISHED, FAILED @@ -144,7 +144,7 @@ Launcher::Job::setState(const std::string & state) _state = state; } -std::string +std::string Launcher::Job::getState() const { return _state; @@ -157,7 +157,7 @@ Launcher::Job::getAssignedHostnames() return _assigned_hostnames; } -void +void Launcher::Job::setNumber(const int & number) { if (_number != -1) @@ -171,7 +171,7 @@ Launcher::Job::getNumber() return _number; } -void +void Launcher::Job::setResourceDefinition(const ParserResourcesType & resource_definition) { // Check machine_definition @@ -179,9 +179,11 @@ Launcher::Job::setResourceDefinition(const ParserResourcesType & resource_defini if (resource_definition.UserName == "") { user_name = getenv("USER"); + if (user_name == "") + user_name = getenv("LOGNAME"); if (user_name == "") { - std::string mess = "You must define a user name: into your resource description or with env variable USER"; + std::string mess = "You must define a user name: into your resource description or with one of env variables USER/LOGNAME"; throw LauncherException(mess); } } @@ -192,13 +194,13 @@ Launcher::Job::setResourceDefinition(const ParserResourcesType & resource_defini _resource_definition.UserName = user_name; } -ParserResourcesType +ParserResourcesType Launcher::Job::getResourceDefinition() const { return _resource_definition; } -void +void Launcher::Job::setJobFile(const std::string & job_file) { // Check job file @@ -220,7 +222,7 @@ Launcher::Job::getJobFile() const { return _job_file; } -void +void Launcher::Job::setEnvFile(const std::string & env_file) { _env_file = env_file; @@ -232,25 +234,25 @@ Launcher::Job::getEnvFile() const return _env_file; } -void +void Launcher::Job::setWorkDirectory(const std::string & work_directory) { _work_directory = work_directory; } -void +void Launcher::Job::setLocalDirectory(const std::string & local_directory) { _local_directory = local_directory; } -void +void Launcher::Job::setResultDirectory(const std::string & result_directory) { _result_directory = result_directory; } -void +void Launcher::Job::add_in_file(const std::string & file) { std::list::iterator it = std::find(_in_files.begin(), _in_files.end(), file); @@ -260,7 +262,7 @@ Launcher::Job::add_in_file(const std::string & file) std::cerr << "Launcher::Job::add_in_file -- Warning file was already entered in in_files: " << file << std::endl; } -void +void Launcher::Job::add_out_file(const std::string & file) { std::list::iterator it = std::find(_out_files.begin(), _out_files.end(), file); @@ -270,7 +272,7 @@ Launcher::Job::add_out_file(const std::string & file) std::cerr << "Launcher::Job::add_out_file -- Warning file was already entered in out_files: " << file << std::endl; } -void +void Launcher::Job::setMaximumDuration(const std::string & maximum_duration) { checkMaximumDuration(maximum_duration); @@ -282,22 +284,22 @@ Launcher::Job::setMaximumDuration(const std::string & maximum_duration) void Launcher::Job::setLauncherFile(const std::string & launcher_file) { - _launcher_file = launcher_file; + _launcher_file = launcher_file; } void Launcher::Job::setLauncherArgs(const std::string & launcher_args) { - _launcher_args = launcher_args; + _launcher_args = launcher_args; } -void +void Launcher::Job::setResourceRequiredParams(const resourceParams & resource_required_params) { checkResourceRequiredParams(resource_required_params); _resource_required_params = resource_required_params; } -void +void Launcher::Job::setQueue(const std::string & queue) { _queue = queue; @@ -344,13 +346,13 @@ Launcher::Job::setReference(const std::string & reference) _reference = reference; } -std::string +std::string Launcher::Job::getWorkDirectory() const { return _work_directory; } -std::string +std::string Launcher::Job::getLocalDirectory() const { return _local_directory; @@ -362,19 +364,19 @@ Launcher::Job::getResultDirectory() const return _result_directory; } -const std::list & +const std::list & Launcher::Job::get_in_files() const { return _in_files; } -const std::list & +const std::list & Launcher::Job::get_out_files() const { return _out_files; } -std::string +std::string Launcher::Job::getMaximumDuration() const { return _maximum_duration; @@ -384,21 +386,21 @@ Launcher::Job::getMaximumDuration() const std::string Launcher::Job::getLauncherFile() const { - return _launcher_file; + return _launcher_file; } std::string Launcher::Job::getLauncherArgs() const { - return _launcher_args; + return _launcher_args; } -resourceParams +resourceParams Launcher::Job::getResourceRequiredParams() const { return _resource_required_params; } -std::string +std::string Launcher::Job::getQueue() const { return _queue; @@ -440,7 +442,7 @@ Launcher::Job::getReference() const return _reference; } -void +void Launcher::Job::checkMaximumDuration(const std::string & maximum_duration) { std::string result(""); @@ -454,7 +456,7 @@ Launcher::Job::checkMaximumDuration(const std::string & maximum_duration) std::string begin_edt_value = edt_value.substr(0, pos); std::string mid_edt_value = edt_value.substr(pos, 1); std::string end_edt_value = edt_value.substr(pos + 1, edt_value.npos); - + long value; std::istringstream iss(begin_edt_value); if (!(iss >> value)) { @@ -478,7 +480,7 @@ Launcher::Job::checkMaximumDuration(const std::string & maximum_duration) throw LauncherException(result); } -void +void Launcher::Job::checkResourceRequiredParams(const resourceParams & resource_required_params) { // nb_proc has be to > 0 @@ -489,7 +491,7 @@ Launcher::Job::checkResourceRequiredParams(const resourceParams & resource_requi } } -long +long Launcher::Job::convertMaximumDuration(const std::string & edt) { long hh, mm, ret; @@ -510,18 +512,18 @@ Launcher::Job::convertMaximumDuration(const std::string & edt) return ret; } -std::string +std::string Launcher::Job::getLaunchDate() const { time_t rawtime; time(&rawtime); std::string launch_date = ctime(&rawtime); int i = 0 ; - for (;i < launch_date.size(); i++) + for (;i < launch_date.size(); i++) if (launch_date[i] == '/' || launch_date[i] == '-' || launch_date[i] == ':' || - launch_date[i] == ' ') + launch_date[i] == ' ') launch_date[i] = '_'; launch_date.erase(--launch_date.end()); // Last caracter is a \n @@ -553,7 +555,7 @@ Launcher::Job::updateJobState() } #ifdef WITH_LIBBATCH -Batch::Job * +Batch::Job * Launcher::Job::getBatchJob() { update_job(); @@ -611,7 +613,7 @@ Launcher::Job::common_job_params() std::list in_files(_in_files); in_files.push_back(_job_file); if (_env_file != "") - in_files.push_back(_env_file); + in_files.push_back(_env_file); for(std::list::iterator it = in_files.begin(); it != in_files.end(); it++) { std::string file = *it; @@ -626,14 +628,14 @@ Launcher::Job::common_job_params() #else local_file = file; #endif - + // remote file -> get only file name from in_files size_t found = file.find_last_of("/"); std::string remote_file = _work_directory + "/" + file.substr(found+1); params[Batch::INFILE] += Batch::Couple(local_file, remote_file); } - + // _out_files for(std::list::iterator it = _out_files.begin(); it != _out_files.end(); it++) { @@ -683,20 +685,20 @@ Launcher::Job::common_job_params() return params; } -void +void Launcher::Job::setBatchManagerJobId(Batch::JobId batch_manager_job_id) { _batch_job_id = batch_manager_job_id; } -Batch::JobId +Batch::JobId Launcher::Job::getBatchManagerJobId() const { return _batch_job_id; } #endif -void +void Launcher::Job::addSpecificParameter(const std::string & name, const std::string & value) { diff --git a/src/ModuleGenerator/IDLparser.py b/src/ModuleGenerator/IDLparser.py index d27e083d6..44b2e063a 100644 --- a/src/ModuleGenerator/IDLparser.py +++ b/src/ModuleGenerator/IDLparser.py @@ -30,6 +30,7 @@ import pdb from xml.sax.handler import * from omniidl import idlast, idltype, idlvisitor, idlutil, output +from salome_utils import getUserName # parameters not found in IDL file, user's specified in optional parameters common_data={"AUTHOR" : "", @@ -827,7 +828,7 @@ def run(tree, args): #========= Read parameters ====================== common_data["ICON"] = getParamValue("icon", "", args) - common_data["AUTHOR"] = getParamValue("author", os.getenv("USER"), args) + common_data["AUTHOR"] = getParamValue("author", getUserName(), args) common_data["VERSION"] = getParamValue("version", "1", args) common_data["COMP_NAME"] = getParamValue("name", "", args) common_data["COMP_UNAME"] = getParamValue("username", "", args) -- 2.39.2