Skip to content

Commit e7bea27

Browse files
committed
Add support setting variables from project_name environment variables
Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 7463253 commit e7bea27

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

opal/mca/base/mca_base_var.c

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,9 +1260,6 @@ static int register_variable (const char *project_name, const char *framework_na
12601260
mca_base_var_init();
12611261
}
12621262

1263-
/* XXX -- readd project name once it is available in the component structure */
1264-
project_name = NULL;
1265-
12661263
/* See if this entry is already in the array */
12671264
var_index = var_find (project_name, framework_name, component_name, variable_name,
12681265
true);
@@ -1487,16 +1484,46 @@ int mca_base_var_register_synonym (int synonym_for, const char *project_name,
14871484
synonym_for, NULL);
14881485
}
14891486

1487+
static int var_get_env (mca_base_var_t *var, const char *name, char **source, char **value)
1488+
{
1489+
char *source_env, *value_env;
1490+
int ret;
1491+
1492+
ret = asprintf (&source_env, "%sSOURCE_%s", mca_prefix, name);
1493+
if (0 > ret) {
1494+
return OPAL_ERROR;
1495+
}
1496+
1497+
ret = asprintf (&value_env, "%s%s", mca_prefix, name);
1498+
if (0 > ret) {
1499+
free (source_env);
1500+
return OPAL_ERROR;
1501+
}
1502+
1503+
*source = getenv (source_env);
1504+
*value = getenv (value_env);
1505+
1506+
free (source_env);
1507+
free (value_env);
1508+
1509+
if (NULL == *value) {
1510+
*source = NULL;
1511+
return OPAL_ERR_NOT_FOUND;
1512+
}
1513+
1514+
return OPAL_SUCCESS;
1515+
}
1516+
14901517
/*
14911518
* Lookup a param in the environment
14921519
*/
14931520
static int var_set_from_env (mca_base_var_t *var)
14941521
{
14951522
const char *var_full_name = var->mbv_full_name;
1523+
const char *var_long_name = var->mbv_long_name;
14961524
bool deprecated = VAR_IS_DEPRECATED(var[0]);
14971525
bool is_synonym = VAR_IS_SYNONYM(var[0]);
1498-
char *source, *source_env;
1499-
char *value, *value_env;
1526+
char *source_env, *value_env;
15001527
int ret;
15011528

15021529
if (is_synonym) {
@@ -1510,25 +1537,13 @@ static int var_set_from_env (mca_base_var_t *var)
15101537
}
15111538
}
15121539

1513-
ret = asprintf (&source, "%sSOURCE_%s", mca_prefix, var_full_name);
1514-
if (0 > ret) {
1515-
return OPAL_ERROR;
1516-
}
1517-
1518-
ret = asprintf (&value, "%s%s", mca_prefix, var_full_name);
1519-
if (0 > ret) {
1520-
free (source);
1521-
return OPAL_ERROR;
1540+
ret = var_get_env (var, var_long_name, &source_env, &value_env);
1541+
if (OPAL_SUCCESS != ret) {
1542+
ret = var_get_env (var, var_full_name, &source_env, &value_env);
15221543
}
15231544

1524-
source_env = getenv (source);
1525-
value_env = getenv (value);
1526-
1527-
free (source);
1528-
free (value);
1529-
1530-
if (NULL == value_env) {
1531-
return OPAL_ERR_NOT_FOUND;
1545+
if (OPAL_SUCCESS != ret) {
1546+
return ret;
15321547
}
15331548

15341549
/* we found an environment variable but this variable is default-only. print
@@ -1598,7 +1613,6 @@ static int var_set_from_env (mca_base_var_t *var)
15981613
return var_set_from_string (var, value_env);
15991614
}
16001615

1601-
16021616
/*
16031617
* Lookup a param in the files
16041618
*/

0 commit comments

Comments
 (0)