From: Olivier Dion Date: Mon, 2 Oct 2023 19:09:44 +0000 (-0400) Subject: utils: Allow users to define LTTNG_MANPATH X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=ef4a570db1fbc6ffa5f645e76c4cf25e8098aee1;hp=46d51dbdc8b9c93871c34416006cf7f28b987c90 utils: Allow users to define LTTNG_MANPATH Currently, the configured value `MANPATH` is used when executing `man`. This forces `lttng --help` to use man pages where they will be installed, even with the `pre-inst-env` script. Instead, let the user provide a `LTTNG_MANPATH` environment variable. If not defined, fallback to the configured `MANPATH`. This allows developers to do: $ ./pre-inst-env lttng --help to read the locally generated man pages where the `pre-inst-env` script was generated. Also adding the `LTTNG_MAN_BIN_PATH` to `pre-inst-env` since `man` could be installed someplace else. Change-Id: I32d9af480737bb80732dc5d690f947242aacac4f Signed-off-by: Olivier Dion Signed-off-by: Jérémie Galarneau --- diff --git a/pre-inst-env.in b/pre-inst-env.in index 1a0641d6a..f779aa453 100644 --- a/pre-inst-env.in +++ b/pre-inst-env.in @@ -28,4 +28,12 @@ export PATH MANPATH="$builddir/doc/man" export MANPATH +# Use local path to search manual pages for lttng --help. +LTTNG_MANPATH="$builddir/doc/man" +export LTTNG_MANPATH + +# Use system man instead of /usr/bin/man. +LTTNG_MAN_BIN_PATH=$(type -p man) +export LTTNG_MAN_BIN_PATH + exec "$@" diff --git a/src/common/defaults.hpp b/src/common/defaults.hpp index 4b4d902dd..149c483ec 100644 --- a/src/common/defaults.hpp +++ b/src/common/defaults.hpp @@ -30,6 +30,9 @@ /* Environment variable to set man pager binary path. */ #define DEFAULT_MAN_BIN_PATH_ENV "LTTNG_MAN_BIN_PATH" +/* Environment variable to set man manpath. */ +#define DEFAULT_MANPATH "LTTNG_MANPATH" + /* Default man pager binary path. */ #define DEFAULT_MAN_BIN_PATH "/usr/bin/man" diff --git a/src/common/utils.cpp b/src/common/utils.cpp index 0f6e0362f..7cd61c049 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -1020,10 +1020,23 @@ static const char *get_man_bin_path() return DEFAULT_MAN_BIN_PATH; } +static const char *get_manpath() +{ + char *manpath = lttng_secure_getenv(DEFAULT_MANPATH); + + if (manpath) { + return manpath; + } + + /* As defined during configuration. */ + return MANPATH; +} + int utils_show_help(int section, const char *page_name, const char *help_msg) { char section_string[8]; const char *man_bin_path = get_man_bin_path(); + const char *manpath = get_manpath(); int ret = 0; if (help_msg) { @@ -1042,7 +1055,7 @@ int utils_show_help(int section, const char *page_name, const char *help_msg) * be installed outside /usr, in which case its man pages are * not located in the default /usr/share/man directory. */ - ret = execlp(man_bin_path, "man", "-M", MANPATH, section_string, page_name, NULL); + ret = execlp(man_bin_path, "man", "-M", manpath, section_string, page_name, NULL); end: return ret;