Skip to content

Commit 4c7a07d

Browse files
authored
Merge pull request #263 from rhc54/topic/sing
Add missing schizo/singularity commit
2 parents c5ad39a + 97764b8 commit 4c7a07d

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

orte/mca/schizo/singularity/schizo_singularity.c

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int setup_fork(orte_job_t *jdata, orte_app_context_t *app)
4141
{
4242
int i;
4343
bool takeus = false;
44-
char *pth = NULL;
44+
char *pth = NULL; // Path to the directory where the Singularity binary is
4545
char *exec_args = NULL;
4646
opal_envar_t envar;
4747
char **cmd_args = NULL;
@@ -56,6 +56,9 @@ static int setup_fork(orte_job_t *jdata, orte_app_context_t *app)
5656
}
5757
}
5858
}
59+
/* If we did not find the singularity binary in the environment of the
60+
* application, we check if the arguments include the singularity
61+
* command itself (assuming full path) or a Singularity image. */
5962
if (!takeus) {
6063
/* even if they didn't specify, check to see if
6164
* this involves a singularity container */
@@ -78,24 +81,57 @@ static int setup_fork(orte_job_t *jdata, orte_app_context_t *app)
7881
if (NULL != app->env) {
7982
pth = opal_path_findv("singularity", X_OK, app->env, NULL);
8083
}
81-
if (NULL == pth) {
84+
if (NULL != pth) {
85+
/* opal_path_findv returned the absolute path to the Singularity binary,
86+
* we want the directory where the binary is. */
87+
pth = opal_dirname(pth);
88+
opal_output_verbose(1, orte_schizo_base_framework.framework_output,
89+
"%s schizo:singularity: Singularity found from env: %s\n",
90+
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), pth);
91+
} else {
8292
/* wasn't in the environment - see if it was found somewhere */
8393
if (0 < strlen(OPAL_SINGULARITY_PATH)) {
8494
if (0 != strcmp(OPAL_SINGULARITY_PATH, "DEFAULT")) {
8595
pth = OPAL_SINGULARITY_PATH;
96+
opal_output_verbose(1, orte_schizo_base_framework.framework_output,
97+
"%s schizo:singularity: using default Singularity from %s\n",
98+
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), pth);
99+
/* Update (if possible) the PATH of the app so it can find singularity otherwise
100+
it will likely not find it and create a failure. The default path to singularity
101+
that is set at configuration time may not be in the environment that is passed in
102+
by the user. */
103+
for (i = 0; NULL != app->env[i]; i++) {
104+
if (0 == strncmp(app->env[i], "PATH", 4)) {
105+
char *cur_path_val = &app->env[i][5];
106+
if (app->env[i] != NULL) {
107+
free(app->env[i]);
108+
}
109+
opal_asprintf(&app->env[i], "PATH=%s:%s", pth, cur_path_val);
110+
break;
111+
}
112+
}
86113
}
87114
} else {
88115
return ORTE_ERR_TAKE_NEXT_OPTION;
89116
}
90117
}
91-
if (NULL != pth) {
92-
/* tell the odls component to prepend this to our PATH */
93-
envar.envar = "PATH";
94-
envar.value = pth;
95-
envar.separator = ':';
96-
orte_add_attribute(&jdata->attributes, ORTE_JOB_PREPEND_ENVAR,
97-
ORTE_ATTR_GLOBAL, &envar, OPAL_ENVAR);
118+
if (NULL == pth) {
119+
// at this point, if we do not have a valid path to Singularity, there is nothing we can do
120+
return ORTE_ERR_TAKE_NEXT_OPTION;
121+
}
122+
123+
/* tell the odls component to prepend this to our PATH */
124+
envar.envar = "PATH";
125+
envar.value = pth;
126+
envar.separator = ':';
127+
orte_add_attribute(&jdata->attributes, ORTE_JOB_PREPEND_ENVAR,
128+
ORTE_ATTR_GLOBAL, &envar, OPAL_ENVAR);
129+
130+
// the final command is now singularity
131+
if (app->app) {
132+
free(app->app);
98133
}
134+
asprintf(&app->app, "%s/singularity", pth);
99135

100136
/* start building the final cmd */
101137
opal_argv_append_nosize(&cmd_args, "singularity");

0 commit comments

Comments
 (0)