diff --git a/opal/runtime/opal_init.c b/opal/runtime/opal_init.c index 18e6db664b..cebf51af83 100644 --- a/opal/runtime/opal_init.c +++ b/opal/runtime/opal_init.c @@ -195,6 +195,13 @@ opal_init_util(void) /* initialize the output system */ opal_output_init(); + /* initialize install dirs code */ + if (OPAL_SUCCESS != (ret = opal_installdirs_base_open())) { + fprintf(stderr, "opal_installdirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of OPAL_INIT)\n", + __FILE__, __LINE__, ret); + return ret; + } + /* initialize the help system */ opal_show_help_init(); @@ -206,13 +213,6 @@ opal_init_util(void) goto return_error; } - /* initialize install dirs code */ - if (OPAL_SUCCESS != (ret = opal_installdirs_base_open())) { - fprintf(stderr, "opal_installdirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of OPAL_INIT)\n", - __FILE__, __LINE__, ret); - return ret; - } - /* init the trace function */ opal_trace_init(); diff --git a/opal/util/show_help.c b/opal/util/show_help.c index 15f64a705e..4ed1ce931b 100644 --- a/opal/util/show_help.c +++ b/opal/util/show_help.c @@ -40,16 +40,18 @@ static const char *default_filename = "help-messages"; static const char *dash_line = "--------------------------------------------------------------------------\n"; static int output_stream = -1; - +static char **search_dirs = NULL; int opal_show_help_init(void) { opal_output_stream_t lds; - + OBJ_CONSTRUCT(&lds, opal_output_stream_t); lds.lds_want_stderr = true; output_stream = opal_output_open(&lds); - + + opal_argv_append_nosize(&search_dirs, opal_install_dirs.pkgdatadir); + return OPAL_SUCCESS; } @@ -57,6 +59,12 @@ int opal_show_help_finalize(void) { opal_output_close(output_stream); output_stream = -1; + + /* destruct the search list */ + if (NULL != search_dirs) { + opal_argv_free(search_dirs); + }; + return OPAL_SUCCESS; } @@ -118,32 +126,36 @@ static int open_file(const char *base, const char *topic) char *filename; char *err_msg = NULL; size_t base_len; - + int i; + /* If no filename was supplied, use the default */ if (NULL == base) { base = default_filename; } - + /* Try to open the file. If we can't find it, try it with a .txt - extension. */ - - filename = opal_os_path( false, opal_install_dirs.pkgdatadir, base, NULL ); - opal_show_help_yyin = fopen(filename, "r"); - if (NULL == opal_show_help_yyin) { - asprintf(&err_msg, "%s: %s", filename, strerror(errno)); - base_len = strlen(base); - if (4 > base_len || 0 != strcmp(base + base_len - 4, ".txt")) { - free(filename); - asprintf(&filename, "%s%s%s.txt", opal_install_dirs.pkgdatadir, - OPAL_PATH_SEP, base); - opal_show_help_yyin = fopen(filename, "r"); + * extension. + */ + for (i=0; NULL != search_dirs[i]; i++) { + filename = opal_os_path( false, search_dirs[i], base, NULL ); + opal_show_help_yyin = fopen(filename, "r"); + if (NULL == opal_show_help_yyin) { + asprintf(&err_msg, "%s: %s", filename, strerror(errno)); + base_len = strlen(base); + if (4 > base_len || 0 != strcmp(base + base_len - 4, ".txt")) { + free(filename); + asprintf(&filename, "%s%s%s.txt", search_dirs[i], OPAL_PATH_SEP, base); + opal_show_help_yyin = fopen(filename, "r"); + } + } + free(filename); + if (NULL != opal_show_help_yyin) { + break; } } - free(filename); /* If we still couldn't open it, then something is wrong */ - if (NULL == opal_show_help_yyin) { opal_output(output_stream, "%sSorry! You were supposed to get help about:\n %s\nBut I couldn't open the help file:\n %s. Sorry!\n%s", dash_line, topic, err_msg, dash_line); free(err_msg); @@ -330,3 +342,9 @@ int opal_show_help(const char *filename, const char *topic, return rc; } + +int opal_show_help_add_dir(const char *directory) +{ + opal_argv_append_nosize(&search_dirs, directory); + return OPAL_SUCCESS; +} diff --git a/opal/util/show_help.h b/opal/util/show_help.h index a77b0fe513..bd5568b784 100644 --- a/opal/util/show_help.h +++ b/opal/util/show_help.h @@ -154,6 +154,21 @@ OPAL_DECLSPEC char* opal_show_help_vstring(const char *filename, const char *topic, bool want_error_header, va_list ap); +/** + * This function adds another search location for the files that + * back show_help messages. Locations will be searched starting + * with the prefix installation directory, then cycled through + * any additional directories in the order they were added + * + * This interface allows libraries that use OMPI to take advantage + * of the show_help functionality. OMPI defines the show_help directory + * based on where OMPI was installed. However, if the library wants to + * use show_help to provide error output specific to itself, then it + * nees to tell show_help how to find its own show_help files - without + * interfering with the linked ORTE libs when they need to do show_help. + */ +OPAL_DECLSPEC int opal_show_help_add_dir(const char *directory); + /** * \internal *