utils: Allow users to define LTTNG_MANPATH
authorOlivier Dion <odion@efficios.com>
Mon, 2 Oct 2023 19:09:44 +0000 (15:09 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 2 Oct 2023 19:34:48 +0000 (15:34 -0400)
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 <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
pre-inst-env.in
src/common/defaults.hpp
src/common/utils.cpp

index 1a0641d6a0736ee0f0e0d60d5c4938072b54445a..f779aa453f32efece3c34f4c8c67be9e01616b0e 100644 (file)
@@ -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 "$@"
index 4b4d902dd715e34bb56815ef1000fc73767f2b4a..149c483ec668cb7912dc6e5aa47b31244db5efc8 100644 (file)
@@ -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"
 
index 0f6e0362f2d32f6c557ffede0341ed0d829b2ff7..7cd61c049c3ffeae0b7bdcf74dc5a0eb9a6c58da 100644 (file)
@@ -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;
This page took 0.027138 seconds and 4 git commands to generate.