lttng: show man page when using command's --help
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 17 Nov 2015 06:20:34 +0000 (01:20 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 18 Mar 2016 01:30:44 +0000 (21:30 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
26 files changed:
src/bin/lttng/command.h
src/bin/lttng/commands/add_context.c
src/bin/lttng/commands/calibrate.c
src/bin/lttng/commands/create.c
src/bin/lttng/commands/destroy.c
src/bin/lttng/commands/disable_channels.c
src/bin/lttng/commands/disable_events.c
src/bin/lttng/commands/enable_channels.c
src/bin/lttng/commands/enable_events.c
src/bin/lttng/commands/list.c
src/bin/lttng/commands/load.c
src/bin/lttng/commands/save.c
src/bin/lttng/commands/set_session.c
src/bin/lttng/commands/snapshot.c
src/bin/lttng/commands/start.c
src/bin/lttng/commands/status.c
src/bin/lttng/commands/stop.c
src/bin/lttng/commands/track-untrack.c
src/bin/lttng/commands/version.c
src/bin/lttng/commands/view.c
src/bin/lttng/utils.c
src/bin/lttng/utils.h
src/common/Makefile.am
src/common/defaults.h
src/common/utils.c
src/common/utils.h

index 451e30f793014877a00e0fc28917ebd8cd0867ba..05c51663b90e011d3174100e04915593a365f8d2 100644 (file)
 #define DECL_COMMAND(_name) \
        extern int cmd_##_name(int, const char **)
 
+#define SHOW_HELP()                                                    \
+       do {                                                            \
+               ret = show_cmd_man_page(argv[0]);                       \
+                                                                       \
+               if (ret) {                                              \
+                       ERR("Cannot view man page lttng-%s(1)", argv[0]); \
+                       perror("exec");                                 \
+               }                                                       \
+       } while (0)
+
 enum cmd_error_code {
        CMD_SUCCESS = 0,
        CMD_ERROR,
index 6f7c23c01e8980806fa4ed737be2fdc70f829cd9..56ee2aca44a82e7157526c87c9fed9332a486bd0 100644 (file)
@@ -841,7 +841,7 @@ int cmd_add_context(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST:
                        print_ctx_type(stdout);
index b15ce40cf924c6992d14a9c1221f0f73540c2525..ba3350fb60eeb8e6a982a6ffe26dc6aea0edeca5 100644 (file)
@@ -172,7 +172,7 @@ int cmd_calibrate(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_TRACEPOINT:
                        ret = CMD_UNDEFINED;
index 5027fce90dc1d8aca19f63566a7a6e4535b52489..efc9e60c1609c189daae7ca09f3b765568c27b4c 100644 (file)
@@ -699,7 +699,7 @@ int cmd_create(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index ad181d7c4343b72182269556bf689d593bd21d4d..661c0a2356ae42acdf7dfb0fbd047a7bff45e5b0 100644 (file)
@@ -189,7 +189,7 @@ int cmd_destroy(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        break;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index f1f2e51b9a21c2296189c6813758fe7dfc3aa183..a8bfa5deaeda8ad759eb82fee2f31412d34ab291 100644 (file)
@@ -233,7 +233,7 @@ int cmd_disable_channels(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_USERSPACE:
                        opt_userspace = 1;
index cc27115651270230a67479aec4cbb9220643b858..b853c57f7eee9b41f761a2b3e7affc35d73c7ef9 100644 (file)
@@ -361,7 +361,7 @@ int cmd_disable_events(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_TYPE_SYSCALL:
                        opt_event_type = LTTNG_EVENT_SYSCALL;
index 696b8e0947ad20ca48e8b1ef3d5913d45b32f6c1..93d81d7355167a310685f9a75209009e55d9e195 100644 (file)
@@ -401,7 +401,7 @@ int cmd_enable_channels(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_DISCARD:
                        chan.attr.overwrite = 0;
index 6a536976636e6d4f5729ccc9333f6ec066da4b48..2c366c6d2e6db46636d1f8b98701a8415608e00a 100644 (file)
@@ -1401,7 +1401,7 @@ int cmd_enable_events(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_TRACEPOINT:
                        opt_event_type = LTTNG_EVENT_TRACEPOINT;
index b122b5b789284ce78be1e1a327894575fe5dc023..7a35258b4b9d4ef2db48442210e8fefc61f716b3 100644 (file)
@@ -1737,7 +1737,7 @@ int cmd_list(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_USERSPACE:
                        opt_userspace = 1;
index cb3eb75aa8439c6813d1c5765555b37038c8773b..7a29da52da3ed780dfff56970678a5750bf3f970 100644 (file)
@@ -151,7 +151,7 @@ int cmd_load(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_ALL:
                        opt_load_all = 1;
index 6bd8732266ad2c5b4581b68445939f4eafb01284..66ec5b6ebe904f5c2ec0ff33bb32598226b367ab 100644 (file)
@@ -146,7 +146,7 @@ int cmd_save(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_ALL:
                        opt_save_all = 1;
index c0572e1275d46f273cb446bedd8010ab4a4463a2..d41dc1d191ccf2be56935c3b06e87e596a657ecd 100644 (file)
@@ -174,7 +174,7 @@ int cmd_set_session(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index 465d864de1d15c977b53f3497bd6945ce28524c2..1d7843954ecc60e6ad94ea62b8004338eb372325 100644 (file)
@@ -715,7 +715,7 @@ int cmd_snapshot(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, snapshot_opts);
index b353eb6e3888174483ac52932145f575a1089f92..90794c66990bfc5fed93e3a0949385b8d8c95217 100644 (file)
@@ -161,7 +161,7 @@ int cmd_start(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index d9b6c4f277cefb2290b2b7c66046b54df477d6b0..693527535418cb647a6b8400ccc247d6cd4e39f1 100644 (file)
@@ -83,7 +83,7 @@ int cmd_status(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index b3fff0753b1c93381e0eafe073ed1e60c4127d4e..e946d4fdb503ad274a4e58f596d3fe28647760f5 100644 (file)
@@ -189,7 +189,7 @@ int cmd_stop(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index a4f4689e7457c226821280778aff330fdc376434..6d8d91ffd73b70948c371cb69dbe0a9bc9e14210 100644 (file)
@@ -364,7 +364,7 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str,
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout, cmd_str);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index 7634f5871a0eaec92e7a4820e36e21c487905aa1..3630950bbcd0eb63b47f99fd86f2e13318f634d6 100644 (file)
@@ -148,7 +148,7 @@ int cmd_version(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index 44e0cb015c93e90bc31cc553bead112f368602cd..dac2c3e247b4e3607bafeb6de7db7c5a3799e6da 100644 (file)
@@ -444,7 +444,7 @@ int cmd_view(int argc, const char **argv)
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
index 802e0971bd6785c2853e0ffeb1d88b0edc03a5a4..912cbd5775b08bd97485c3dd3768a8ed1a6a8a71 100644 (file)
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <inttypes.h>
+#include <unistd.h>
 
 #include <common/error.h>
 #include <common/utils.h>
+#include <common/defaults.h>
 
 #include "conf.h"
 #include "utils.h"
@@ -479,3 +481,14 @@ void print_session_stats(const char *session_name)
 end:
        return;
 }
+
+int show_cmd_man_page(const char *cmd_name)
+{
+       int ret;
+       char page_name[32];
+
+       ret = sprintf(page_name, "lttng-%s", cmd_name);
+       assert(ret > 0 && ret < 32);
+
+       return utils_show_man_page(1, page_name);
+}
index 0d70cf751e48612997e6f3546ea72366724d551e..7f656df13481c06856a154ac707a356bcc1a4caa 100644 (file)
@@ -60,5 +60,6 @@ int print_missing_or_multiple_domains(unsigned int sum);
 int spawn_relayd(const char *pathname, int port);
 int check_relayd(void);
 void print_session_stats(const char *session_name);
+int show_cmd_man_page(const char *cmd_name);
 
 #endif /* _LTTNG_UTILS_H */
index c1b9d4e7a36f35d1e0c2b43712ba5b962ddbf044..5096676e096a2ed53d258e9a13da04d31178b6be 100644 (file)
@@ -1,4 +1,5 @@
-AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
+       -DMANPATH=\""$(mandir)"\"
 
 AUTOMAKE_OPTIONS = subdir-objects
 
index f45c8f6f0fc33c247637a0bfbf7cb8aaa0224c8d..6e343b50c8425b5948abd853ccad9b7c375545db 100644 (file)
 /* Environment variable to set session daemon binary path. */
 #define DEFAULT_SESSIOND_PATH_ENV               "LTTNG_SESSIOND_PATH"
 
+/* Environment variable to set man pager binary path. */
+#define DEFAULT_MAN_BIN_PATH_ENV                "LTTNG_MAN_BIN_PATH"
+
+/* Default man pager binary path. */
+#define DEFAULT_MAN_BIN_PATH                    "/usr/bin/man"
+
 /* Default trace output directory name */
 #define DEFAULT_TRACE_DIR_NAME                  "lttng-traces"
 
index d71d92446ce71e14177e26005797211c4f7f0730..df55dc9fb65880db9dc75373c390634849e0fd34 100644 (file)
@@ -1341,7 +1341,40 @@ int utils_truncate_stream_file(int fd, off_t length)
                PERROR("lseek");
                goto end;
        }
-
 end:
        return ret;
 }
+
+static const char *get_man_bin_path(void)
+{
+       char *env_man_path = getenv(DEFAULT_MAN_BIN_PATH_ENV);
+
+       if (env_man_path) {
+               return env_man_path;
+       }
+
+       return DEFAULT_MAN_BIN_PATH;
+}
+
+LTTNG_HIDDEN
+int utils_show_man_page(int section, const char *page_name)
+{
+       char section_string[8];
+       const char *man_bin_path = get_man_bin_path();
+       int ret;
+
+       /* Section integer -> section string */
+       ret = sprintf(section_string, "%d", section);
+       assert(ret > 0 && ret < 8);
+
+       /*
+        * Execute man pager.
+        *
+        * We provide --manpath to man here because LTTng-tools can
+        * 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", "--manpath", MANPATH,
+               section_string, page_name, NULL);
+       return ret;
+}
index 5272d54a6b811ba3256a2c0f7a118a41ae7676ff..7285f5c3032932ec03531ddb7ef7973f403fbc6b 100644 (file)
@@ -59,5 +59,6 @@ char *utils_generate_optstring(const struct option *long_options,
 int utils_create_lock_file(const char *filepath);
 int utils_recursive_rmdir(const char *path);
 int utils_truncate_stream_file(int fd, off_t length);
+int utils_show_man_page(int section, const char *page_name);
 
 #endif /* _COMMON_UTILS_H */
This page took 0.035039 seconds and 4 git commands to generate.