2015-04-17 19:00:31 -06:00
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2005-03-14 20:57:21 +00:00
/*
2008-05-06 18:08:45 +00:00
* Copyright ( c ) 2004 - 2008 The Trustees of Indiana University and Indiana
2005-11-05 19:57:48 +00:00
* University Research and Technology
* Corporation . All rights reserved .
2006-08-23 03:32:36 +00:00
* Copyright ( c ) 2004 - 2006 The University of Tennessee and The University
2005-11-05 19:57:48 +00:00
* of Tennessee Research Foundation . All rights
* reserved .
2015-06-23 20:59:57 -07:00
* Copyright ( c ) 2004 - 2005 High Performance Computing Center Stuttgart ,
2005-03-14 20:57:21 +00:00
* University of Stuttgart . All rights reserved .
2005-03-24 12:43:37 +00:00
* Copyright ( c ) 2004 - 2005 The Regents of the University of California .
* All rights reserved .
2015-04-17 19:00:31 -06:00
* Copyright ( c ) 2007 - 2015 Los Alamos National Security , LLC . All rights
2015-06-23 20:59:57 -07:00
* reserved .
2009-02-12 18:27:40 +00:00
* Copyright ( c ) 2008 - 2009 Sun Microsystems , Inc . All rights reserved .
2015-06-23 20:59:57 -07:00
* Copyright ( c ) 2010 Oracle and / or its affiliates . All rights
2010-11-18 19:30:04 +00:00
* reserved .
2016-08-16 06:58:20 -05:00
* Copyright ( c ) 2009 - 2016 Cisco Systems , Inc . All rights reserved .
2011-03-29 07:46:59 +00:00
* Copyright ( c ) 2011 IBM Corporation . All rights reserved .
2017-01-20 06:48:27 -08:00
* Copyright ( c ) 2015 - 2017 Intel , Inc . All rights reserved .
2005-03-14 20:57:21 +00:00
* $ COPYRIGHT $
2015-06-23 20:59:57 -07:00
*
2005-03-14 20:57:21 +00:00
* Additional copyrights may follow
2015-06-23 20:59:57 -07:00
*
2005-03-14 20:57:21 +00:00
* $ HEADER $
*
* These symbols are in a file by themselves to provide nice linker
* semantics . Since linkers generally pull in symbols by object
* files , keeping these symbols as the only symbols in this file
* prevents utility programs such as " ompi_info " from having to import
* entire components just to query their version and parameters .
*/
2006-02-12 01:33:29 +00:00
# include "orte_config.h"
2008-02-28 01:57:57 +00:00
# include "orte/constants.h"
2005-12-15 20:54:24 +00:00
2005-03-14 20:57:21 +00:00
# include <stdlib.h>
2005-06-21 22:48:57 +00:00
# ifdef HAVE_UNISTD_H
2005-03-14 20:57:21 +00:00
# include <unistd.h>
2005-06-21 22:48:57 +00:00
# endif
2005-12-15 20:54:24 +00:00
# include <ctype.h>
2005-03-14 20:57:21 +00:00
2007-06-05 03:03:59 +00:00
# include "opal/util/opal_environ.h"
2009-02-14 02:26:12 +00:00
# include "opal/util/output.h"
2005-07-04 00:13:44 +00:00
# include "opal/util/argv.h"
2015-09-24 07:16:48 -07:00
# include "opal/util/basename.h"
2005-07-04 01:59:52 +00:00
# include "opal/util/path.h"
2006-09-14 21:29:51 +00:00
2015-09-24 07:16:48 -07:00
# include "orte/mca/state/state.h"
2008-02-28 01:57:57 +00:00
# include "orte/util/name_fns.h"
2009-02-20 03:16:13 +00:00
# include "orte/runtime/orte_globals.h"
2008-06-09 14:53:58 +00:00
# include "orte/util/show_help.h"
2005-03-14 20:57:21 +00:00
2008-02-28 01:57:57 +00:00
# include "orte/mca/plm/plm.h"
# include "orte/mca/plm/base/plm_private.h"
# include "orte/mca/plm/rsh/plm_rsh.h"
2006-09-14 21:29:51 +00:00
2005-03-14 20:57:21 +00:00
/*
2008-02-28 01:57:57 +00:00
* Public string showing the plm ompi_rsh component version number
2005-03-14 20:57:21 +00:00
*/
2008-02-28 01:57:57 +00:00
const char * mca_plm_rsh_component_version_string =
" Open MPI rsh plm MCA component version " ORTE_VERSION ;
2005-03-14 20:57:21 +00:00
2013-03-27 21:09:41 +00:00
static int rsh_component_register ( void ) ;
2011-11-26 02:33:05 +00:00
static int rsh_component_open ( void ) ;
static int rsh_component_query ( mca_base_module_t * * module , int * priority ) ;
static int rsh_component_close ( void ) ;
static int rsh_launch_agent_lookup ( const char * agent_list , char * path ) ;
2013-03-27 21:09:41 +00:00
/* Local variables */
static char * mca_plm_rsh_delay_string = NULL ;
2016-08-16 06:58:20 -05:00
static int agent_var_id = - 1 ;
2013-03-27 21:09:41 +00:00
2005-03-14 20:57:21 +00:00
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
2008-02-28 01:57:57 +00:00
orte_plm_rsh_component_t mca_plm_rsh_component = {
2005-03-14 20:57:21 +00:00
{
/* First, the mca_component_t struct containing meta information
about the component itself */
2015-04-17 19:00:31 -06:00
. base_version = {
ORTE_PLM_BASE_VERSION_2_0_0 ,
/* Component name and version */
. mca_component_name = " rsh " ,
MCA_BASE_MAKE_VERSION ( component , ORTE_MAJOR_VERSION , ORTE_MINOR_VERSION ,
ORTE_RELEASE_VERSION ) ,
/* Component open and close functions */
. mca_open_component = rsh_component_open ,
. mca_close_component = rsh_component_close ,
. mca_query_component = rsh_component_query ,
. mca_register_component_params = rsh_component_register ,
} ,
. base_data = {
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
} ,
2005-03-14 20:57:21 +00:00
}
} ;
2013-03-27 21:09:41 +00:00
static int rsh_component_register ( void )
{
mca_base_component_t * c = & mca_plm_rsh_component . super . base_version ;
int var_id ;
mca_plm_rsh_component . num_concurrent = 128 ;
( void ) mca_base_component_var_register ( c , " num_concurrent " ,
" How many plm_rsh_agent instances to invoke concurrently (must be > 0) " ,
MCA_BASE_VAR_TYPE_INT , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_5 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . num_concurrent ) ;
mca_plm_rsh_component . force_rsh = false ;
( void ) mca_base_component_var_register ( c , " force_rsh " , " Force the launcher to always use rsh " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . force_rsh ) ;
mca_plm_rsh_component . disable_qrsh = false ;
( void ) mca_base_component_var_register ( c , " disable_qrsh " ,
2015-04-20 16:18:34 -07:00
" Disable the use of qrsh when under the Grid Engine parallel environment " ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . disable_qrsh ) ;
mca_plm_rsh_component . daemonize_qrsh = false ;
( void ) mca_base_component_var_register ( c , " daemonize_qrsh " ,
" Daemonize the orted under the Grid Engine parallel environment " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . daemonize_qrsh ) ;
mca_plm_rsh_component . disable_llspawn = false ;
( void ) mca_base_component_var_register ( c , " disable_llspawn " ,
" Disable the use of llspawn when under the LoadLeveler environment " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . disable_llspawn ) ;
mca_plm_rsh_component . daemonize_llspawn = false ;
( void ) mca_base_component_var_register ( c , " daemonize_llspawn " ,
" Daemonize the orted when under the LoadLeveler environment " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . daemonize_llspawn ) ;
mca_plm_rsh_component . priority = 10 ;
( void ) mca_base_component_var_register ( c , " priority " , " Priority of the rsh plm component " ,
MCA_BASE_VAR_TYPE_INT , NULL , 0 , 0 ,
OPAL_INFO_LVL_9 ,
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . priority ) ;
mca_plm_rsh_delay_string = NULL ;
( void ) mca_base_component_var_register ( c , " delay " ,
" Delay between invocations of the remote agent (sec[:usec]) " ,
MCA_BASE_VAR_TYPE_STRING , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_4 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_delay_string ) ;
2013-04-07 15:48:25 +00:00
mca_plm_rsh_component . no_tree_spawn = false ;
2013-03-27 21:09:41 +00:00
( void ) mca_base_component_var_register ( c , " no_tree_spawn " ,
" If set to true, do not launch via a tree-based topology " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_5 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
2013-04-07 15:48:25 +00:00
& mca_plm_rsh_component . no_tree_spawn ) ;
2005-03-14 20:57:21 +00:00
2013-03-27 21:09:41 +00:00
/* local rsh/ssh launch agent */
2013-12-23 17:47:43 +00:00
mca_plm_rsh_component . agent = " ssh : rsh " ;
2013-03-27 21:09:41 +00:00
var_id = mca_base_component_var_register ( c , " agent " ,
" The command used to launch executables on remote nodes (typically either \" ssh \" or \" rsh \" ) " ,
MCA_BASE_VAR_TYPE_STRING , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . agent ) ;
( void ) mca_base_var_register_synonym ( var_id , " orte " , " pls " , NULL , " rsh_agent " , MCA_BASE_VAR_SYN_FLAG_DEPRECATED ) ;
( void ) mca_base_var_register_synonym ( var_id , " orte " , " orte " , NULL , " rsh_agent " , MCA_BASE_VAR_SYN_FLAG_DEPRECATED ) ;
2016-08-16 06:58:20 -05:00
agent_var_id = var_id ;
2013-03-27 21:09:41 +00:00
mca_plm_rsh_component . assume_same_shell = true ;
var_id = mca_base_component_var_register ( c , " assume_same_shell " ,
" If set to true, assume that the shell on the remote node is the same as the shell on the local node. Otherwise, probe for what the remote shell [default: 1] " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . assume_same_shell ) ;
/* XXX -- var_conversion -- Why does this component register orte_assume_same_shell? Components should ONLY register THEIR OWN variables. */
( void ) mca_base_var_register_synonym ( var_id , " orte " , " orte " , NULL , " assume_same_shell " , 0 ) ;
mca_plm_rsh_component . pass_environ_mca_params = true ;
( void ) mca_base_component_var_register ( c , " pass_environ_mca_params " ,
" If set to false, do not include mca params from the environment on the orted cmd line " ,
MCA_BASE_VAR_TYPE_BOOL , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2013-03-27 21:09:41 +00:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . pass_environ_mca_params ) ;
2015-04-16 17:18:37 -06:00
mca_plm_rsh_component . ssh_args = NULL ;
( void ) mca_base_component_var_register ( c , " args " ,
" Arguments to add to rsh/ssh " ,
MCA_BASE_VAR_TYPE_STRING , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2015-04-16 17:18:37 -06:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . ssh_args ) ;
mca_plm_rsh_component . pass_libpath = NULL ;
( void ) mca_base_component_var_register ( c , " pass_libpath " ,
" Prepend the specified library path to the remote shell's LD_LIBRARY_PATH " ,
MCA_BASE_VAR_TYPE_STRING , NULL , 0 , 0 ,
2015-04-20 16:18:34 -07:00
OPAL_INFO_LVL_2 ,
2015-04-16 17:18:37 -06:00
MCA_BASE_VAR_SCOPE_READONLY ,
& mca_plm_rsh_component . pass_libpath ) ;
2013-03-27 21:09:41 +00:00
return ORTE_SUCCESS ;
}
2005-03-14 20:57:21 +00:00
2011-11-26 02:33:05 +00:00
static int rsh_component_open ( void )
2005-03-14 20:57:21 +00:00
{
2013-03-27 21:09:41 +00:00
char * ctmp ;
2005-04-14 14:08:21 +00:00
2005-03-14 20:57:21 +00:00
/* initialize globals */
2009-02-18 18:02:38 +00:00
mca_plm_rsh_component . using_qrsh = false ;
2011-03-29 07:46:59 +00:00
mca_plm_rsh_component . using_llspawn = false ;
2015-09-24 07:16:48 -07:00
mca_plm_rsh_component . agent_argv = NULL ;
2005-03-14 20:57:21 +00:00
/* lookup parameters */
2013-03-27 21:09:41 +00:00
if ( mca_plm_rsh_component . num_concurrent < = 0 ) {
This commit represents a bunch of work on a Mercurial side branch. As
such, the commit message back to the master SVN repository is fairly
long.
= ORTE Job-Level Output Messages =
Add two new interfaces that should be used for all new code throughout
the ORTE and OMPI layers (we already make the search-and-replace on
the existing ORTE / OMPI layers):
* orte_output(): (and corresponding friends ORTE_OUTPUT,
orte_output_verbose, etc.) This function sends the output directly
to the HNP for processing as part of a job-specific output
channel. It supports all the same outputs as opal_output()
(syslog, file, stdout, stderr), but for stdout/stderr, the output
is sent to the HNP for processing and output. More on this below.
* orte_show_help(): This function is a drop-in-replacement for
opal_show_help(), with two differences in functionality:
1. the rendered text help message output is sent to the HNP for
display (rather than outputting directly into the process' stderr
stream)
1. the HNP detects duplicate help messages and does not display them
(so that you don't see the same error message N times, once from
each of your N MPI processes); instead, it counts "new" instances
of the help message and displays a message every ~5 seconds when
there are new ones ("I got X new copies of the help message...")
opal_show_help and opal_output still exist, but they only output in
the current process. The intent for the new orte_* functions is that
they can apply job-level intelligence to the output. As such, we
recommend that all new ORTE and OMPI code use the new orte_*
functions, not thei opal_* functions.
=== New code ===
For ORTE and OMPI programmers, here's what you need to do differently
in new code:
* Do not include opal/util/show_help.h or opal/util/output.h.
Instead, include orte/util/output.h (this one header file has
declarations for both the orte_output() series of functions and
orte_show_help()).
* Effectively s/opal_output/orte_output/gi throughout your code.
Note that orte_output_open() takes a slightly different argument
list (as a way to pass data to the filtering stream -- see below),
so you if explicitly call opal_output_open(), you'll need to
slightly adapt to the new signature of orte_output_open().
* Literally s/opal_show_help/orte_show_help/. The function signature
is identical.
=== Notes ===
* orte_output'ing to stream 0 will do similar to what
opal_output'ing did, so leaving a hard-coded "0" as the first
argument is safe.
* For systems that do not use ORTE's RML or the HNP, the effect of
orte_output_* and orte_show_help will be identical to their opal
counterparts (the additional information passed to
orte_output_open() will be lost!). Indeed, the orte_* functions
simply become trivial wrappers to their opal_* counterparts. Note
that we have not tested this; the code is simple but it is quite
possible that we mucked something up.
= Filter Framework =
Messages sent view the new orte_* functions described above and
messages output via the IOF on the HNP will now optionally be passed
through a new "filter" framework before being output to
stdout/stderr. The "filter" OPAL MCA framework is intended to allow
preprocessing to messages before they are sent to their final
destinations. The first component that was written in the filter
framework was to create an XML stream, segregating all the messages
into different XML tags, etc. This will allow 3rd party tools to read
the stdout/stderr from the HNP and be able to know exactly what each
text message is (e.g., a help message, another OMPI infrastructure
message, stdout from the user process, stderr from the user process,
etc.).
Filtering is not active by default. Filter components must be
specifically requested, such as:
{{{
$ mpirun --mca filter xml ...
}}}
There can only be one filter component active.
= New MCA Parameters =
The new functionality described above introduces two new MCA
parameters:
* '''orte_base_help_aggregate''': Defaults to 1 (true), meaning that
help messages will be aggregated, as described above. If set to 0,
all help messages will be displayed, even if they are duplicates
(i.e., the original behavior).
* '''orte_base_show_output_recursions''': An MCA parameter to help
debug one of the known issues, described below. It is likely that
this MCA parameter will disappear before v1.3 final.
= Known Issues =
* The XML filter component is not complete. The current output from
this component is preliminary and not real XML. A bit more work
needs to be done to configure.m4 search for an appropriate XML
library/link it in/use it at run time.
* There are possible recursion loops in the orte_output() and
orte_show_help() functions -- e.g., if RML send calls orte_output()
or orte_show_help(). We have some ideas how to fix these, but
figured that it was ok to commit before feature freeze with known
issues. The code currently contains sub-optimal workarounds so
that this will not be a problem, but it would be good to actually
solve the problem rather than have hackish workarounds before v1.3 final.
This commit was SVN r18434.
2008-05-13 20:00:55 +00:00
orte_show_help ( " help-plm-rsh.txt " , " concurrency-less-than-zero " ,
2013-03-27 21:09:41 +00:00
true , mca_plm_rsh_component . num_concurrent ) ;
mca_plm_rsh_component . num_concurrent = 1 ;
2011-11-27 01:49:42 +00:00
}
2011-11-26 02:33:05 +00:00
2013-03-27 21:09:41 +00:00
if ( NULL ! = mca_plm_rsh_delay_string ) {
mca_plm_rsh_component . delay . tv_sec = strtol ( mca_plm_rsh_delay_string , & ctmp , 10 ) ;
if ( ctmp = = mca_plm_rsh_delay_string ) {
mca_plm_rsh_component . delay . tv_sec = 0 ;
}
if ( ' : ' = = ctmp [ 0 ] ) {
mca_plm_rsh_component . delay . tv_nsec = 1000 * strtol ( ctmp + 1 , NULL , 10 ) ;
}
2011-11-26 02:33:05 +00:00
}
2005-12-22 14:37:19 +00:00
return ORTE_SUCCESS ;
}
2011-11-26 02:33:05 +00:00
static int rsh_component_query ( mca_base_module_t * * module , int * priority )
2005-12-22 14:37:19 +00:00
{
2009-02-11 18:48:44 +00:00
char * tmp ;
2015-06-23 20:59:57 -07:00
2010-11-18 19:30:04 +00:00
/* Check if we are under Grid Engine parallel environment by looking at several
2016-08-12 07:46:39 -07:00
* environment variables . If so , setup the path and argv [ 0 ] .
* Note that we allow the user to specify the launch agent
* even if they are in a Grid Engine environment */
2016-08-16 06:58:20 -05:00
int ret ;
mca_base_var_source_t source ;
ret = mca_base_var_get_value ( agent_var_id , NULL , & source , NULL ) ;
if ( OPAL_SUCCESS ! = ret ) {
return ret ;
}
if ( MCA_BASE_VAR_SOURCE_DEFAULT ! = source ) {
2017-02-13 16:54:03 -08:00
/* if the user specified a launch agent, then
* respect that request */
goto lookup ;
}
/* check for SGE */
if ( ! mca_plm_rsh_component . disable_qrsh & &
NULL ! = getenv ( " SGE_ROOT " ) & & NULL ! = getenv ( " ARC " ) & &
NULL ! = getenv ( " PE_HOSTFILE " ) & & NULL ! = getenv ( " JOB_ID " ) ) {
/* setup the search path for qrsh */
asprintf ( & tmp , " %s/bin/%s " , getenv ( " SGE_ROOT " ) , getenv ( " ARC " ) ) ;
/* see if the agent is available */
if ( ORTE_SUCCESS ! = rsh_launch_agent_lookup ( " qrsh " , tmp ) ) {
/* can't be SGE */
opal_output_verbose ( 1 , orte_plm_base_framework . framework_output ,
" %s plm:rsh: unable to be used: SGE indicated but cannot find path "
" or execution permissions not set for launching agent qrsh " ,
ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) ) ;
free ( tmp ) ;
* module = NULL ;
return ORTE_ERROR ;
2009-02-09 20:44:44 +00:00
}
2017-02-13 16:54:03 -08:00
mca_plm_rsh_component . agent = tmp ;
mca_plm_rsh_component . using_qrsh = true ;
goto success ;
}
/* otherwise, check for LoadLeveler */
if ( ! mca_plm_rsh_component . disable_llspawn & &
NULL ! = getenv ( " LOADL_STEP_ID " ) ) {
/* Search for llspawn in the users PATH */
if ( ORTE_SUCCESS ! = rsh_launch_agent_lookup ( " llspawn " , NULL ) ) {
opal_output_verbose ( 1 , orte_plm_base_framework . framework_output ,
" %s plm:rsh: unable to be used: LoadLeveler "
" indicated but cannot find path or execution "
" permissions not set for launching agent llspawn " ,
ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) ) ;
* module = NULL ;
return ORTE_ERROR ;
}
mca_plm_rsh_component . agent = strdup ( " llspawn " ) ;
mca_plm_rsh_component . using_llspawn = true ;
goto success ;
2005-03-18 23:40:08 +00:00
}
2015-06-23 20:59:57 -07:00
2015-09-24 07:16:48 -07:00
/* if this isn't an Grid Engine or LoadLeveler environment, or
* if the user specified a launch agent , look for it */
2017-02-13 16:54:03 -08:00
lookup :
2011-11-26 02:33:05 +00:00
if ( ORTE_SUCCESS ! = rsh_launch_agent_lookup ( NULL , NULL ) ) {
2015-09-24 07:16:48 -07:00
/* if the user specified an agent and we couldn't find it,
* then we want to error out and not continue */
if ( NULL ! = mca_plm_rsh_component . agent ) {
orte_show_help ( " help-plm-rsh.txt " , " agent-not-found " , true ,
mca_plm_rsh_component . agent ) ;
ORTE_FORCED_TERMINATE ( ORTE_ERR_NOT_FOUND ) ;
return ORTE_ERR_FATAL ;
}
2009-02-09 20:44:44 +00:00
/* this isn't an error - we just cannot be selected */
2013-03-27 21:14:43 +00:00
OPAL_OUTPUT_VERBOSE ( ( 1 , orte_plm_base_framework . framework_output ,
2008-02-28 01:57:57 +00:00
" %s plm:rsh: unable to be used: cannot find path "
2015-06-23 20:59:57 -07:00
" for launching agent \" %s \" \n " ,
2009-03-05 21:50:47 +00:00
ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) ,
2011-11-26 02:33:05 +00:00
mca_plm_rsh_component . agent ) ) ;
2008-05-06 18:08:45 +00:00
* module = NULL ;
return ORTE_ERROR ;
2005-03-14 20:57:21 +00:00
}
2017-02-13 16:54:03 -08:00
success :
2009-02-09 20:44:44 +00:00
/* we are good - make ourselves available */
2008-02-28 01:57:57 +00:00
* priority = mca_plm_rsh_component . priority ;
2008-05-06 18:08:45 +00:00
* module = ( mca_base_module_t * ) & orte_plm_rsh_module ;
return ORTE_SUCCESS ;
2005-03-14 20:57:21 +00:00
}
2011-11-26 02:33:05 +00:00
static int rsh_component_close ( void )
2005-03-14 20:57:21 +00:00
{
2009-02-09 20:44:44 +00:00
return ORTE_SUCCESS ;
2005-12-15 20:54:24 +00:00
}
2011-11-26 02:33:05 +00:00
/*
* Take a colon - delimited list of agents and locate the first one that
* we are able to find in the PATH . Split that one into argv and
* return it . If nothing found , then return NULL .
*/
char * * orte_plm_rsh_search ( const char * agent_list , const char * path )
{
int i , j ;
char * line , * * lines ;
char * * tokens , * tmp ;
char cwd [ OPAL_PATH_MAX ] ;
2015-06-23 20:59:57 -07:00
2011-11-26 02:33:05 +00:00
if ( NULL = = path ) {
getcwd ( cwd , OPAL_PATH_MAX ) ;
} else {
2015-02-24 06:49:03 -05:00
strncpy ( cwd , path , OPAL_PATH_MAX - 1 ) ;
cwd [ OPAL_PATH_MAX - 1 ] = ' \0 ' ;
2011-11-26 02:33:05 +00:00
}
if ( NULL = = agent_list ) {
lines = opal_argv_split ( mca_plm_rsh_component . agent , ' : ' ) ;
} else {
lines = opal_argv_split ( agent_list , ' : ' ) ;
}
for ( i = 0 ; NULL ! = lines [ i ] ; + + i ) {
line = lines [ i ] ;
2015-06-23 20:59:57 -07:00
2011-11-26 02:33:05 +00:00
/* Trim whitespace at the beginning and end of the line */
for ( j = 0 ; ' \0 ' ! = line [ j ] & & isspace ( line [ j ] ) ; + + line ) {
continue ;
}
for ( j = strlen ( line ) - 2 ; j > 0 & & isspace ( line [ j ] ) ; + + j ) {
line [ j ] = ' \0 ' ;
}
if ( strlen ( line ) < = 0 ) {
continue ;
}
2015-06-23 20:59:57 -07:00
2011-11-26 02:33:05 +00:00
/* Split it */
tokens = opal_argv_split ( line , ' ' ) ;
2015-06-23 20:59:57 -07:00
2011-11-26 02:33:05 +00:00
/* Look for the first token in the PATH */
tmp = opal_path_findv ( tokens [ 0 ] , X_OK , environ , cwd ) ;
if ( NULL ! = tmp ) {
free ( tokens [ 0 ] ) ;
tokens [ 0 ] = tmp ;
opal_argv_free ( lines ) ;
return tokens ;
}
2015-06-23 20:59:57 -07:00
2011-11-26 02:33:05 +00:00
/* Didn't find it */
opal_argv_free ( tokens ) ;
}
2015-06-23 20:59:57 -07:00
2011-11-26 02:33:05 +00:00
/* Doh -- didn't find anything */
opal_argv_free ( lines ) ;
return NULL ;
}
static int rsh_launch_agent_lookup ( const char * agent_list , char * path )
{
2015-09-24 07:16:48 -07:00
char * bname ;
int i ;
2011-11-26 02:33:05 +00:00
2013-03-27 21:14:43 +00:00
OPAL_OUTPUT_VERBOSE ( ( 5 , orte_plm_base_framework . framework_output ,
2011-11-26 02:33:05 +00:00
" %s plm:rsh_lookup on agent %s path %s " ,
ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) ,
( NULL = = agent_list ) ? mca_plm_rsh_component . agent : agent_list ,
( NULL = = path ) ? " NULL " : path ) ) ;
2015-09-24 07:16:48 -07:00
if ( NULL = = ( mca_plm_rsh_component . agent_argv = orte_plm_rsh_search ( agent_list , path ) ) ) {
2011-11-26 02:33:05 +00:00
return ORTE_ERR_NOT_FOUND ;
}
2015-09-24 07:16:48 -07:00
/* if we got here, then one of the given agents could be found - the
* complete path is in the argv [ 0 ] position */
mca_plm_rsh_component . agent_path = strdup ( mca_plm_rsh_component . agent_argv [ 0 ] ) ;
bname = opal_basename ( mca_plm_rsh_component . agent_argv [ 0 ] ) ;
if ( NULL = = bname ) {
return ORTE_SUCCESS ;
}
/* replace the initial position with the basename */
free ( mca_plm_rsh_component . agent_argv [ 0 ] ) ;
mca_plm_rsh_component . agent_argv [ 0 ] = bname ;
/* see if we need to add an xterm argument */
if ( 0 = = strcmp ( bname , " ssh " ) ) {
/* if xterm option was given, add '-X', ensuring we don't do it twice */
if ( NULL ! = orte_xterm ) {
opal_argv_append_unique_nosize ( & mca_plm_rsh_component . agent_argv , " -X " , false ) ;
} else if ( 0 > = opal_output_get_verbosity ( orte_plm_base_framework . framework_output ) ) {
/* if debug was not specified, and the user didn't explicitly
* specify X11 forwarding / non - forwarding , add " -x " if it
* isn ' t already there ( check either case )
*/
for ( i = 1 ; NULL ! = mca_plm_rsh_component . agent_argv [ i ] ; + + i ) {
if ( 0 = = strcasecmp ( " -x " , mca_plm_rsh_component . agent_argv [ i ] ) ) {
break ;
}
}
if ( NULL = = mca_plm_rsh_component . agent_argv [ i ] ) {
opal_argv_append_nosize ( & mca_plm_rsh_component . agent_argv , " -x " ) ;
}
}
}
2011-11-26 02:33:05 +00:00
return ORTE_SUCCESS ;
}