diff --git a/src/mca/schizo/base/help-schizo-base.txt b/src/mca/schizo/base/help-schizo-base.txt index 70e38c2ada..f635a95358 100644 --- a/src/mca/schizo/base/help-schizo-base.txt +++ b/src/mca/schizo/base/help-schizo-base.txt @@ -96,8 +96,11 @@ An incorrect value for the "--stream-buffering" option was given: Valid values are limited to 0, 1, or 2. Your application will continue, but please correct your command line in the future. # -[duplicate-value] -WARNING: an MCA parameter was listed more than once on the command line, or +[missing-envar-param] +Warning: Could not find the environment variable: %s +# +[duplicate-mca-value] +Error: an MCA parameter was listed more than once on the command line, or multiple times in one or more files, but with conflicting values: Param: %s diff --git a/src/mca/schizo/ompi/schizo_ompi.c b/src/mca/schizo/ompi/schizo_ompi.c index c29584d379..543f2c7a64 100644 --- a/src/mca/schizo/ompi/schizo_ompi.c +++ b/src/mca/schizo/ompi/schizo_ompi.c @@ -17,7 +17,7 @@ * Copyright (c) 2013-2020 Intel, Inc. All rights reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. - * Copyright (c) 2018-2020 IBM Corporation. All rights reserved. + * Copyright (c) 2018-2021 IBM Corporation. All rights reserved. * Copyright (c) 2021 Nanook Consulting. All rights reserved. * $COPYRIGHT$ * @@ -452,7 +452,7 @@ static int check_cache_noadd(char ***c1, char ***c2, if (0 != strcmp(cachevals[k], p2)) { /* this is an error */ prte_show_help("help-schizo-base.txt", - "duplicate-value", true, + "duplicate-mca-value", true, p1, p2, cachevals[k]); return PRTE_ERR_BAD_PARAM; } @@ -1162,40 +1162,6 @@ static int parse_env(prte_cmd_line_t *cmd_line, } prte_argv_free(envlist); - /* now look for -x options - not allowed to conflict with a -mca option */ - if (0 < (j = prte_cmd_line_get_ninsts(cmd_line, "x"))) { - for (i = 0; i < j; ++i) { - /* the value is the envar */ - pval = prte_cmd_line_get_param(cmd_line, "x", i, 0); - p1 = strip_quotes(pval->value.data.string); - /* if there is an '=' in it, then they are setting a value */ - if (NULL != (p2 = strchr(p1, '='))) { - *p2 = '\0'; - ++p2; - } else { - p2 = getenv(p1); - if (NULL == p2) { - free(p1); - continue; - } - } - /* not allowed to duplicate anything from an MCA param on the cmd line */ - rc = check_cache_noadd(&cache, &cachevals, p1, p2); - if (PRTE_SUCCESS != rc) { - prte_argv_free(cache); - prte_argv_free(cachevals); - free(p1); - prte_argv_free(xparams); - prte_argv_free(xvals); - return rc; - } - /* cache this for later inclusion */ - prte_argv_append_nosize(&xparams, p1); - prte_argv_append_nosize(&xvals, p2); - free(p1); - } - } - /* process the resulting cache into the dstenv */ if (NULL != cache) { for (i=0; NULL != cache[i]; i++) { @@ -1211,15 +1177,6 @@ static int parse_env(prte_cmd_line_t *cmd_line, prte_argv_free(cache); prte_argv_free(cachevals); - /* add the -x values */ - if (NULL != xparams) { - for (i=0; NULL != xparams[i]; i++) { - prte_setenv(xparams[i], xvals[i], true, dstenv); - } - prte_argv_free(xparams); - prte_argv_free(xvals); - } - return PRTE_SUCCESS; } diff --git a/src/mca/schizo/prte/schizo_prte.c b/src/mca/schizo/prte/schizo_prte.c index 1c55b38691..65f6a42f98 100644 --- a/src/mca/schizo/prte/schizo_prte.c +++ b/src/mca/schizo/prte/schizo_prte.c @@ -17,7 +17,7 @@ * Copyright (c) 2013-2020 Intel, Inc. All rights reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. - * Copyright (c) 2018 IBM Corporation. All rights reserved. + * Copyright (c) 2018-2021 IBM Corporation. All rights reserved. * Copyright (c) 2021 Nanook Consulting. All rights reserved. * $COPYRIGHT$ * @@ -545,8 +545,12 @@ static int parse_env(prte_cmd_line_t *cmd_line, char ***dstenv, bool cmdline) { - int i, j; - char *p1; + int i, j, n; + char *p1, *p2; + char **env; + prte_value_t *pval; + char **xparams=NULL, **xvals=NULL; + char *param, *value; prte_output_verbose(1, prte_schizo_base_framework.framework_output, "%s schizo:prte: parse_env", @@ -567,6 +571,80 @@ static int parse_env(prte_cmd_line_t *cmd_line, } } + env = *dstenv; + + /* now look for -x options - not allowed to conflict with a -mca option */ + if (NULL != cmd_line && 0 < (j = prte_cmd_line_get_ninsts(cmd_line, "x"))) { + for (i = 0; i < j; ++i) { + /* the value is the envar */ + pval = prte_cmd_line_get_param(cmd_line, "x", i, 0); + p1 = strip_quotes(pval->value.data.string); + /* if there is an '=' in it, then they are setting a value */ + if (NULL != (p2 = strchr(p1, '='))) { + *p2 = '\0'; + ++p2; + } else { + p2 = getenv(p1); + if (NULL == p2) { + prte_show_help("help-schizo-base.txt", + "missing-envar-param", true, + p1); + free(p1); + continue; + } + } + + /* check if it is already present in the environment */ + for (n=0; NULL != env && NULL != env[n]; n++) { + param = strdup(env[n]); + value = strchr(param, '='); + *value = '\0'; + value++; + /* check if parameter is already present */ + if (0 == strcmp(param, p1)) { + /* we do have it - check for same value */ + if (0 != strcmp(value, p2)) { + /* this is an error - different values */ + prte_show_help("help-schizo-base.txt", + "duplicate-mca-value", true, + p1, p2, value); + free(param); + return PRTE_ERR_BAD_PARAM; + } + } + free(param); + } + + /* check if we already processed a conflicting -x version with MCA prefix */ + if (NULL != xparams) { + for (i=0; NULL != xparams[i]; i++) { + if (0 == strncmp("PRTE_MCA_", p1, strlen("PRTE_MCA_")) || + 0 == strncmp("OMPI_MCA_", p1, strlen("OMPI_MCA_"))) { + /* this is an error - different values */ + prte_show_help("help-schizo-base.txt", + "duplicate-mca-value", true, + p1, p2, xvals[i]); + return PRTE_ERR_BAD_PARAM; + } + } + } + + /* cache this for later inclusion - do not modify dstenv in this loop */ + prte_argv_append_nosize(&xparams, p1); + prte_argv_append_nosize(&xvals, p2); + free(p1); + } + } + + /* add the -x values */ + if (NULL != xparams) { + for (i=0; NULL != xparams[i]; i++) { + prte_setenv(xparams[i], xvals[i], true, dstenv); + } + prte_argv_free(xparams); + prte_argv_free(xvals); + } + return PRTE_SUCCESS; } diff --git a/src/tools/prun/prun.1.md b/src/tools/prun/prun.1.md index 3fb14b81ca..ce4170621a 100644 --- a/src/tools/prun/prun.1.md +++ b/src/tools/prun/prun.1.md @@ -263,6 +263,11 @@ To manage files and runtime environment: before executing the program. Only one environment variable can be specified per `-x` option. Existing environment variables can be specified or new variable names specified with corresponding values. + If multiple `-x` options with the same variable name (regardless of value) + are provided then the last one listed on the command line will take + precedence, and the others will be ignored. The exception to this + is for PRTE_MCA_ prefixed environment variables which will report + an error in that scenario if any of the values differ. For example: `$ prun -x DISPLAY -x OFILE=/tmp/out ...` The parser for the `-x` option is not very sophisticated; it does not