Skip to content

Commit 321abfc

Browse files
author
Ralph Castain
committed
Fix cwd and preload-binary options
Signed-off-by: Ralph Castain <[email protected]>
1 parent ad108ba commit 321abfc

File tree

3 files changed

+51
-47
lines changed

3 files changed

+51
-47
lines changed

orte/mca/odls/base/odls_base_default_fns.c

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,8 @@ int orte_odls_base_default_construct_child_list(opal_buffer_t *buffer,
534534

535535
static int setup_path(orte_app_context_t *app, char **wdir)
536536
{
537-
int rc;
537+
int rc=ORTE_SUCCESS;
538538
char dir[MAXPATHLEN];
539-
char **argvptr;
540-
char *pathenv = NULL, *mpiexec_pathenv = NULL;
541-
char *full_search;
542539

543540
if (!orte_get_attribute(&app->attributes, ORTE_APP_SSNDIR_CWD, NULL, OPAL_BOOL)) {
544541
/* Try to change to the app's cwd and check that the app
@@ -572,40 +569,6 @@ static int setup_path(orte_app_context_t *app, char **wdir)
572569
*wdir = NULL;
573570
}
574571

575-
/* Search for the OMPI_exec_path and PATH settings in the environment. */
576-
for (argvptr = app->env; *argvptr != NULL; argvptr++) {
577-
if (0 == strncmp("OMPI_exec_path=", *argvptr, 15)) {
578-
mpiexec_pathenv = *argvptr + 15;
579-
}
580-
if (0 == strncmp("PATH=", *argvptr, 5)) {
581-
pathenv = *argvptr + 5;
582-
}
583-
}
584-
585-
/* If OMPI_exec_path is set (meaning --path was used), then create a
586-
temporary environment to be used in the search for the executable.
587-
The PATH setting in this temporary environment is a combination of
588-
the OMPI_exec_path and PATH values. If OMPI_exec_path is not set,
589-
then just use existing environment with PATH in it. */
590-
if (NULL != mpiexec_pathenv) {
591-
argvptr = NULL;
592-
if (pathenv != NULL) {
593-
asprintf(&full_search, "%s:%s", mpiexec_pathenv, pathenv);
594-
} else {
595-
asprintf(&full_search, "%s", mpiexec_pathenv);
596-
}
597-
opal_setenv("PATH", full_search, true, &argvptr);
598-
free(full_search);
599-
} else {
600-
argvptr = app->env;
601-
}
602-
603-
rc = orte_util_check_context_app(app, argvptr);
604-
/* do not ERROR_LOG - it will be reported elsewhere */
605-
if (NULL != mpiexec_pathenv) {
606-
opal_argv_free(argvptr);
607-
}
608-
609572
CLEANUP:
610573
return rc;
611574
}
@@ -662,6 +625,9 @@ void orte_odls_base_spawn_proc(int fd, short sd, void *cbdata)
662625
int rc, i;
663626
bool found;
664627
orte_proc_state_t state;
628+
char **argvptr;
629+
char *pathenv = NULL, *mpiexec_pathenv = NULL;
630+
char *full_search;
665631

666632
/* thread-protect common values */
667633
cd->env = opal_argv_copy(app->env);
@@ -762,6 +728,44 @@ void orte_odls_base_spawn_proc(int fd, short sd, void *cbdata)
762728
goto errorout;
763729
}
764730

731+
/* Search for the OMPI_exec_path and PATH settings in the environment. */
732+
for (argvptr = app->env; *argvptr != NULL; argvptr++) {
733+
if (0 == strncmp("OMPI_exec_path=", *argvptr, 15)) {
734+
mpiexec_pathenv = *argvptr + 15;
735+
}
736+
if (0 == strncmp("PATH=", *argvptr, 5)) {
737+
pathenv = *argvptr + 5;
738+
}
739+
}
740+
741+
/* If OMPI_exec_path is set (meaning --path was used), then create a
742+
temporary environment to be used in the search for the executable.
743+
The PATH setting in this temporary environment is a combination of
744+
the OMPI_exec_path and PATH values. If OMPI_exec_path is not set,
745+
then just use existing environment with PATH in it. */
746+
if (NULL != mpiexec_pathenv) {
747+
argvptr = NULL;
748+
if (pathenv != NULL) {
749+
asprintf(&full_search, "%s:%s", mpiexec_pathenv, pathenv);
750+
} else {
751+
asprintf(&full_search, "%s", mpiexec_pathenv);
752+
}
753+
opal_setenv("PATH", full_search, true, &argvptr);
754+
free(full_search);
755+
} else {
756+
argvptr = app->env;
757+
}
758+
759+
rc = orte_util_check_context_app(app, argvptr);
760+
/* do not ERROR_LOG - it will be reported elsewhere */
761+
if (NULL != mpiexec_pathenv) {
762+
opal_argv_free(argvptr);
763+
}
764+
if (ORTE_SUCCESS != rc) {
765+
state = ORTE_PROC_STATE_FAILED_TO_LAUNCH;
766+
goto errorout;
767+
}
768+
765769
/* if we are indexing the argv by rank, do so now */
766770
if (cd->index_argv && !ORTE_FLAG_TEST(jobdat, ORTE_JOB_FLAG_DEBUGGER_DAEMON)) {
767771
char *param;

orte/mca/schizo/ompi/schizo_ompi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,11 @@ static int setup_child(orte_job_t *jdata,
12071207
opal_setenv("PWD", param, true, env);
12081208
/* update the initial wdir value too */
12091209
opal_setenv("OMPI_MCA_initial_wdir", param, true, env);
1210+
} else if (NULL != app->cwd) {
1211+
/* change to it */
1212+
if (0 != chdir(app->cwd)) {
1213+
return ORTE_ERROR;
1214+
}
12101215
}
12111216
return ORTE_SUCCESS;
12121217
}

orte/orted/orted_submit.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,22 +1628,17 @@ static int create_app(int argc, char* argv[],
16281628
app->num_procs = (orte_std_cntr_t)orte_cmd_options.num_procs;
16291629
total_num_apps++;
16301630

1631-
/* Capture any preload flags */
1632-
if (orte_cmd_options.preload_binaries) {
1633-
orte_set_attribute(&app->attributes, ORTE_APP_PRELOAD_BIN, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
1634-
}
1635-
/* if we were told to cwd to the session dir and the app was given in
1636-
* relative syntax, then we need to preload the binary to
1631+
/* see if we need to preload the binary to
16371632
* find the app - don't do this for java apps, however, as we
16381633
* can't easily find the class on the cmd line. Java apps have to
16391634
* preload their binary via the preload_files option
16401635
*/
1641-
if (!opal_path_is_absolute(app->argv[0]) &&
1642-
NULL == strstr(app->argv[0], "java")) {
1636+
if (NULL == strstr(app->argv[0], "java")) {
16431637
if (orte_cmd_options.preload_binaries) {
16441638
orte_set_attribute(&app->attributes, ORTE_APP_SSNDIR_CWD, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
1645-
} else if (orte_get_attribute(&app->attributes, ORTE_APP_SSNDIR_CWD, NULL, OPAL_BOOL)) {
16461639
orte_set_attribute(&app->attributes, ORTE_APP_PRELOAD_BIN, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
1640+
/* no harm in setting this attribute twice as the function will simply ignore it */
1641+
orte_set_attribute(&app->attributes, ORTE_APP_SSNDIR_CWD, ORTE_ATTR_GLOBAL, NULL, OPAL_BOOL);
16471642
}
16481643
}
16491644
if (NULL != orte_cmd_options.preload_files) {

0 commit comments

Comments
 (0)