1
1

Bring Jeff's changes over from v1.2 that restores the automatic source of .profile for bash and ksh shells.

This commit was SVN r19709.
Этот коммит содержится в:
Ralph Castain 2008-10-08 14:21:42 +00:00
родитель 5b5d557b3d
Коммит a7afa869af

Просмотреть файл

@ -342,15 +342,13 @@ static void orte_plm_rsh_wait_daemon(pid_t pid, int status, void* cbdata)
static int setup_launch(int *argcptr, char ***argvptr, static int setup_launch(int *argcptr, char ***argvptr,
char *nodename, char *nodename,
int *node_name_index1, int *node_name_index1,
int *proc_vpid_index, char *prefix_dir, int *proc_vpid_index, char *prefix_dir)
bool *remote_sh, bool *remote_csh)
{ {
struct passwd *p; struct passwd *p;
int argc; int argc;
char **argv; char **argv;
char *param; char *param;
orte_plm_rsh_shell_t shell; orte_plm_rsh_shell_t remote_shell, local_shell;
bool local_sh = false, local_csh = false;
char *lib_base, *bin_base; char *lib_base, *bin_base;
int orted_argc; int orted_argc;
char **orted_argv; char **orted_argv;
@ -359,6 +357,7 @@ static int setup_launch(int *argcptr, char ***argvptr,
int rc; int rc;
/* What is our local shell? */ /* What is our local shell? */
local_shell = ORTE_PLM_RSH_SHELL_UNKNOWN;
p = getpwuid(getuid()); p = getpwuid(getuid());
if( NULL == p ) { if( NULL == p ) {
/* This user is unknown to the system. Therefore, there is no reason we /* This user is unknown to the system. Therefore, there is no reason we
@ -368,69 +367,51 @@ static int setup_launch(int *argcptr, char ***argvptr,
return ORTE_ERR_FATAL; return ORTE_ERR_FATAL;
} else { } else {
param = p->pw_shell; param = p->pw_shell;
shell = find_shell(p->pw_shell); local_shell = find_shell(p->pw_shell);
} }
/* If we didn't find it in getpwuid(), try looking at the $SHELL /* If we didn't find it in getpwuid(), try looking at the $SHELL
environment variable (see https://svn.open-mpi.org/trac/ompi/ticket/1060) environment variable (see https://svn.open-mpi.org/trac/ompi/ticket/1060)
*/ */
if (ORTE_PLM_RSH_SHELL_UNKNOWN == shell && if (ORTE_PLM_RSH_SHELL_UNKNOWN == local_shell &&
NULL != (param = getenv("SHELL"))) { NULL != (param = getenv("SHELL"))) {
shell = find_shell(param); local_shell = find_shell(param);
} }
switch (shell) { if (ORTE_PLM_RSH_SHELL_UNKNOWN == local_shell) {
case ORTE_PLM_RSH_SHELL_SH: /* fall through */
case ORTE_PLM_RSH_SHELL_KSH: /* fall through */
case ORTE_PLM_RSH_SHELL_ZSH: /* fall through */
case ORTE_PLM_RSH_SHELL_BASH: local_sh = true; break;
case ORTE_PLM_RSH_SHELL_TCSH: /* fall through */
case ORTE_PLM_RSH_SHELL_CSH: local_csh = true; break;
default:
opal_output(0, "WARNING: local probe returned unhandled shell:%s assuming bash\n", opal_output(0, "WARNING: local probe returned unhandled shell:%s assuming bash\n",
(NULL != param) ? param : "unknown"); (NULL != param) ? param : "unknown");
*remote_sh = true; local_shell = ORTE_PLM_RSH_SHELL_BASH;
break;
} }
OPAL_OUTPUT_VERBOSE((1, orte_plm_globals.output, OPAL_OUTPUT_VERBOSE((1, orte_plm_globals.output,
"%s plm:rsh: local csh: %s, local sh: %s", "%s plm:rsh: local shell: %d (%s)",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
(local_csh ? "TRUE" : "FALSE"), local_shell, orte_plm_rsh_shell_name[local_shell]));
(local_sh ? "TRUE" : "FALSE")));
/* What is our remote shell? */ /* What is our remote shell? */
if (mca_plm_rsh_component.assume_same_shell) { if (mca_plm_rsh_component.assume_same_shell) {
*remote_sh = local_sh; remote_shell = local_shell;
*remote_csh = local_csh;
OPAL_OUTPUT_VERBOSE((1, orte_plm_globals.output, OPAL_OUTPUT_VERBOSE((1, orte_plm_globals.output,
"%s plm:rsh: assuming same remote shell as local shell", "%s plm:rsh: assuming same remote shell as local shell",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME))); ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
} else { } else {
orte_plm_rsh_shell_t shell; rc = orte_plm_rsh_probe(nodename, &remote_shell);
rc = orte_plm_rsh_probe(nodename, &shell);
if (ORTE_SUCCESS != rc) { if (ORTE_SUCCESS != rc) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
return rc; return rc;
} }
switch (shell) { if (ORTE_PLM_RSH_SHELL_UNKNOWN == remote_shell) {
case ORTE_PLM_RSH_SHELL_SH: /* fall through */
case ORTE_PLM_RSH_SHELL_KSH: /* fall through */
case ORTE_PLM_RSH_SHELL_ZSH: /* fall through */
case ORTE_PLM_RSH_SHELL_BASH: *remote_sh = true; break;
case ORTE_PLM_RSH_SHELL_TCSH: /* fall through */
case ORTE_PLM_RSH_SHELL_CSH: *remote_csh = true; break;
default:
opal_output(0, "WARNING: rsh probe returned unhandled shell; assuming bash\n"); opal_output(0, "WARNING: rsh probe returned unhandled shell; assuming bash\n");
*remote_sh = true; remote_shell = ORTE_PLM_RSH_SHELL_BASH;
} }
} }
OPAL_OUTPUT_VERBOSE((1, orte_plm_globals.output, OPAL_OUTPUT_VERBOSE((1, orte_plm_globals.output,
"%s plm:rsh: remote csh: %d, remote sh: %d", "%s plm:rsh: remote shell: %d (%s)",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
*remote_csh, *remote_sh)); remote_shell, orte_plm_rsh_shell_name[remote_shell]));
/* Figure out the basenames for the libdir and bindir. This /* Figure out the basenames for the libdir and bindir. This
requires some explanation: requires some explanation:
@ -470,6 +451,28 @@ static int setup_launch(int *argcptr, char ***argvptr,
*node_name_index1 = argc; *node_name_index1 = argc;
opal_argv_append(&argc, &argv, "<template>"); opal_argv_append(&argc, &argv, "<template>");
/* Do we need to source .profile on the remote side?
- sh: yes (see bash(1))
- ksh: yes (see ksh(1))
- bash: no (see bash(1))
- [t]csh: no (see csh(1) and tcsh(1))
- zsh: no (see http://zsh.sourceforge.net/FAQ/zshfaq03.html#l19)
*/
if (ORTE_PLM_RSH_SHELL_SH == remote_shell ||
ORTE_PLM_RSH_SHELL_KSH == remote_shell) {
int i;
char **tmp;
tmp = opal_argv_split("( test ! -r ./.profile || . ./.profile;", ' ');
if (NULL == tmp) {
return ORTE_ERR_OUT_OF_RESOURCE;
}
for (i = 0; NULL != tmp[i]; ++i) {
opal_argv_append(&argc, &argv, tmp[i]);
}
opal_argv_free(tmp);
}
/* now get the orted cmd - as specified by user - into our tmp array. /* now get the orted cmd - as specified by user - into our tmp array.
* The function returns the location where the actual orted command is * The function returns the location where the actual orted command is
* located - usually in the final spot, but someone could * located - usually in the final spot, but someone could
@ -531,7 +534,10 @@ static int setup_launch(int *argcptr, char ***argvptr,
* with the prefix directory * with the prefix directory
*/ */
char *opal_prefix = getenv("OPAL_PREFIX"); char *opal_prefix = getenv("OPAL_PREFIX");
if (*remote_sh) { if (ORTE_PLM_RSH_SHELL_SH == remote_shell ||
ORTE_PLM_RSH_SHELL_KSH == remote_shell ||
ORTE_PLM_RSH_SHELL_ZSH == remote_shell ||
ORTE_PLM_RSH_SHELL_BASH == remote_shell) {
/* if there is nothing preceding orted, then we can just /* if there is nothing preceding orted, then we can just
* assemble the cmd with the orted_cmd at the end. Otherwise, * assemble the cmd with the orted_cmd at the end. Otherwise,
* we have to insert the orted_prefix in the right place * we have to insert the orted_prefix in the right place
@ -548,7 +554,8 @@ static int setup_launch(int *argcptr, char ***argvptr,
(orted_prefix != NULL ? orted_prefix : ""), (orted_prefix != NULL ? orted_prefix : ""),
prefix_dir, bin_base, prefix_dir, bin_base,
orted_cmd); orted_cmd);
} else if (*remote_csh) { } else if (ORTE_PLM_RSH_SHELL_TCSH == remote_shell ||
ORTE_PLM_RSH_SHELL_CSH == remote_shell) {
/* [t]csh is a bit more challenging -- we /* [t]csh is a bit more challenging -- we
have to check whether LD_LIBRARY_PATH have to check whether LD_LIBRARY_PATH
is already set before we try to set it. is already set before we try to set it.
@ -657,8 +664,7 @@ static int setup_launch(int *argcptr, char ***argvptr,
/* actually ssh the child */ /* actually ssh the child */
static void ssh_child(int argc, char **argv, static void ssh_child(int argc, char **argv,
orte_vpid_t vpid, int proc_vpid_index, orte_vpid_t vpid, int proc_vpid_index)
bool remote_sh, bool remote_csh)
{ {
char** env; char** env;
char* var; char* var;
@ -787,7 +793,6 @@ static int remote_spawn(opal_buffer_t *launch)
char *prefix; char *prefix;
int argc; int argc;
int rc; int rc;
bool remote_sh = false, remote_csh = false;
bool failed_launch = true; bool failed_launch = true;
pid_t pid; pid_t pid;
orte_std_cntr_t n; orte_std_cntr_t n;
@ -832,7 +837,7 @@ static int remote_spawn(opal_buffer_t *launch)
/* setup the launch */ /* setup the launch */
if (ORTE_SUCCESS != (rc = setup_launch(&argc, &argv, orte_process_info.nodename, &node_name_index1, if (ORTE_SUCCESS != (rc = setup_launch(&argc, &argv, orte_process_info.nodename, &node_name_index1,
&proc_vpid_index, prefix, &remote_sh, &remote_csh))) { &proc_vpid_index, prefix))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
goto cleanup; goto cleanup;
} }
@ -874,8 +879,7 @@ static int remote_spawn(opal_buffer_t *launch)
nodes[vpid]->name)); nodes[vpid]->name));
/* do the ssh launch - this will exit if it fails */ /* do the ssh launch - this will exit if it fails */
ssh_child(argc, argv, vpid, ssh_child(argc, argv, vpid, proc_vpid_index);
proc_vpid_index, remote_sh, remote_csh);
} else { /* father */ } else { /* father */
OPAL_THREAD_LOCK(&mca_plm_rsh_component.lock); OPAL_THREAD_LOCK(&mca_plm_rsh_component.lock);
@ -939,7 +943,6 @@ int orte_plm_rsh_launch(orte_job_t *jdata)
char *prefix_dir; char *prefix_dir;
int argc; int argc;
int rc; int rc;
bool remote_sh = false, remote_csh = false;
bool failed_launch = true; bool failed_launch = true;
orte_app_context_t **apps; orte_app_context_t **apps;
orte_node_t **nodes; orte_node_t **nodes;
@ -1038,7 +1041,7 @@ int orte_plm_rsh_launch(orte_job_t *jdata)
/* setup the launch */ /* setup the launch */
if (ORTE_SUCCESS != (rc = setup_launch(&argc, &argv, nodes[0]->name, &node_name_index1, if (ORTE_SUCCESS != (rc = setup_launch(&argc, &argv, nodes[0]->name, &node_name_index1,
&proc_vpid_index, prefix_dir, &remote_sh, &remote_csh))) { &proc_vpid_index, prefix_dir))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
goto cleanup; goto cleanup;
} }
@ -1164,8 +1167,7 @@ launch:
if (pid == 0) { if (pid == 0) {
/* do the ssh launch - this will exit if it fails */ /* do the ssh launch - this will exit if it fails */
ssh_child(argc, argv, nodes[nnode]->daemon->name.vpid, ssh_child(argc, argv, nodes[nnode]->daemon->name.vpid, proc_vpid_index);
proc_vpid_index, remote_sh, remote_csh);
} else { /* father */ } else { /* father */