diff --git a/ompi/tools/ompi_info/components.cc b/ompi/tools/ompi_info/components.cc index 0ba7cdfbdc..2edf934d9f 100644 --- a/ompi/tools/ompi_info/components.cc +++ b/ompi/tools/ompi_info/components.cc @@ -143,10 +143,13 @@ void ompi_info::open_components() { ompi_info::type_vector_t::size_type i; string env; - char *target; + char *target, *save; + vector env_save; + vector::iterator esi; - if (opened_components) - return; + if (opened_components) { + return; + } // Clear out the environment. Use strdup() to orphan the resulting // strings because items are placed in the environment by reference, @@ -154,8 +157,9 @@ void ompi_info::open_components() for (i = 0; i < mca_types.size(); ++i) { env = "OMPI_MCA_" + mca_types[i]; - if (NULL != getenv(env.c_str())) { + if (NULL != (save = getenv(env.c_str()))) { env += "="; + env_save.push_back(env + save); target = strdup(env.c_str()); putenv(target); } @@ -313,6 +317,17 @@ void ompi_info::open_components() component_map["crcp"] = &ompi_crcp_base_components_available; #endif + // Restore the environment to what it was before we started so that + // if users setenv OMPI_MCA_ to some value, they'll + // see that value when it is shown via --param output. + + if (!env_save.empty()) { + for (esi = env_save.begin(); esi != env_save.end(); ++esi) { + target = strdup(esi->c_str()); + putenv(target); + } + } + // All done opened_components = true;