2016-02-10 23:43:13 -08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel, Inc. All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "orte_config.h"
|
|
|
|
#include "orte/types.h"
|
|
|
|
#include "opal/types.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2016-03-01 13:18:23 -08:00
|
|
|
#include "opal/util/argv.h"
|
2016-02-17 08:32:17 -08:00
|
|
|
#include "opal/util/basename.h"
|
2016-02-10 23:43:13 -08:00
|
|
|
#include "opal/util/opal_environ.h"
|
2016-03-05 21:47:42 -08:00
|
|
|
#include "opal/util/os_dirpath.h"
|
|
|
|
#include "opal/util/path.h"
|
2016-02-10 23:43:13 -08:00
|
|
|
|
|
|
|
#include "orte/runtime/orte_globals.h"
|
|
|
|
#include "orte/util/name_fns.h"
|
|
|
|
#include "orte/mca/schizo/base/base.h"
|
|
|
|
|
|
|
|
#include "schizo_singularity.h"
|
|
|
|
|
2016-03-05 21:47:42 -08:00
|
|
|
static int setup_app(char **personality,
|
|
|
|
orte_app_context_t *context);
|
2016-02-10 23:43:13 -08:00
|
|
|
|
|
|
|
orte_schizo_base_module_t orte_schizo_singularity_module = {
|
2016-03-09 07:52:11 -08:00
|
|
|
.setup_app = setup_app
|
2016-02-10 23:43:13 -08:00
|
|
|
};
|
|
|
|
|
2016-03-05 21:47:42 -08:00
|
|
|
static int setup_app(char **personality,
|
|
|
|
orte_app_context_t *app)
|
2016-02-10 23:43:13 -08:00
|
|
|
{
|
|
|
|
int i;
|
2016-03-05 21:47:42 -08:00
|
|
|
char *newenv, *pth;
|
2016-02-17 08:32:17 -08:00
|
|
|
bool takeus = false;
|
2016-03-09 07:52:11 -08:00
|
|
|
char *t2;
|
2016-02-17 08:32:17 -08:00
|
|
|
|
|
|
|
/* see if we are included */
|
2016-03-05 21:47:42 -08:00
|
|
|
for (i=0; NULL != personality[i]; i++) {
|
|
|
|
if (0 == strcmp(personality[i], "singularity")) {
|
2016-02-17 08:32:17 -08:00
|
|
|
takeus = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!takeus) {
|
|
|
|
/* even if they didn't specify, check to see if
|
|
|
|
* this involves a singularity container */
|
|
|
|
if (0 != strcmp(app->argv[0],"singularity") &&
|
|
|
|
0 != strcmp(app->argv[0],"sapprun") &&
|
|
|
|
NULL == strstr(app->argv[0], ".sapp")) {
|
|
|
|
/* guess not! */
|
|
|
|
return ORTE_ERR_TAKE_NEXT_OPTION;
|
|
|
|
}
|
|
|
|
}
|
2016-02-10 23:43:13 -08:00
|
|
|
|
|
|
|
opal_output_verbose(1, orte_schizo_base_framework.framework_output,
|
|
|
|
"%s schizo:singularity: checking app %s",
|
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), app->argv[0]);
|
|
|
|
|
2016-03-05 21:47:42 -08:00
|
|
|
if (0 < strlen(OPAL_SINGULARITY_PATH)) {
|
|
|
|
asprintf(&pth, "%s/singularity", OPAL_SINGULARITY_PATH);
|
|
|
|
} else {
|
|
|
|
/* since we allow for detecting singularity's presence, it
|
|
|
|
* is possible that we found it in the PATH, but not in a
|
|
|
|
* standard location. Check for that here */
|
|
|
|
pth = opal_path_findv("singularity", X_OK, app->env, NULL);
|
|
|
|
if (NULL == pth) {
|
|
|
|
/* cannot execute */
|
|
|
|
return ORTE_ERR_TAKE_NEXT_OPTION;
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 08:32:17 -08:00
|
|
|
/* find the path and prepend it with the path to Singularity */
|
|
|
|
for (i = 0; NULL != app->env && NULL != app->env[i]; ++i) {
|
|
|
|
/* add to PATH */
|
|
|
|
if (0 == strncmp("PATH=", app->env[i], 5)) {
|
2016-03-05 21:47:42 -08:00
|
|
|
t2 = opal_dirname(pth);
|
|
|
|
asprintf(&newenv, "%s:%s", t2, app->env[i] + 5);
|
2016-02-17 08:32:17 -08:00
|
|
|
opal_setenv("PATH", newenv, true, &app->env);
|
|
|
|
free(newenv);
|
2016-03-05 21:47:42 -08:00
|
|
|
free(t2);
|
2016-02-17 08:32:17 -08:00
|
|
|
break;
|
2016-02-10 23:43:13 -08:00
|
|
|
}
|
|
|
|
}
|
2016-02-17 08:32:17 -08:00
|
|
|
|
2016-03-05 21:47:42 -08:00
|
|
|
/* export an envar to permit shared memory operations */
|
|
|
|
opal_setenv("SINGULARITY_NO_NAMESPACE_PID", "1", true, &app->env);
|
|
|
|
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|