Add --enable-embedded-help option to embed --help messages in binaries
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 1 Dec 2016 06:29:38 +0000 (01:29 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 5 May 2017 13:32:33 +0000 (09:32 -0400)
This patch adds a configuration option to embed the help message within
the various executables of LTTng-tools instead of always launching the
man pager. This applies to the following commands:

    lttng --help
    lttng CMD --help
    lttng help CMD
    lttng-crash --help
    lttng-relayd --help
    lttng-sessiond --help

This is meant to be used by distributions which remove man pages or do
not have a man pager (embedded distributions, mostly). For example,
Buildroot is known to remove all man pages before it creates the final
image:

    rm -rf $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/man

If you pass the `--enable-embedded-help` option to the `configure`
script:

1. The configure script checks if `man` exists in the `PATH` environment
   variable. This tool is needed to generate the text versions of the
   man pages.

2. When you build LTTng-tools with `make`, the man pages are generated
   as usual (or they already exist in their troff version from a
   tarball), and their text versions are generated with `man`, with a
   fixed width set to 80 columns.

3. The text versions of the man pages are converted to literal C strings
   thanks to some `sed` magic:

   a. Replace `\` with `\\`.
   b. Replace `"` with `\"`.
   c. Add `"` prefix and `\n"` suffix to each line.

   This file is named `NAME.SECTION.h`, where `NAME` is the name of the
   man page and `SECTION` is its section. For example,
   `lttng-create.1.h`.

   I needed to add a `.PRECIOUS` target in `doc/man/Makefile.am` because
   otherwise `make` treats the troff man page files as intermediate
   files and removes them automatically. Then they need to be rebuilt
   to be installed.

4. In each C file where to show a help message, we check if the
   `--enable-embedded-help` option is set, and if so, we assign the
   included help message string to a static variable to be printed
   instead of executing the man pager.

This string added to the object file in #4 takes binary space, why is
why the `--enable-embedded-help` option is turned off by default.

The directories in the "master" `SUBDIRS` (`Makefile.am`) are reordered
so that `doc` is built before `src` since there's a direct dependency
when you pass `--enable-embedded-help`.

The `--disable-man-pages` and `--enable-embedded-help` options do not
form a valid configuration.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
38 files changed:
.gitignore
Makefile.am
configure.ac
doc/man/Makefile.am
src/bin/lttng-crash/Makefile.am
src/bin/lttng-crash/lttng-crash.c
src/bin/lttng-relayd/Makefile.am
src/bin/lttng-relayd/main.c
src/bin/lttng-sessiond/Makefile.am
src/bin/lttng-sessiond/main.c
src/bin/lttng/Makefile.am
src/bin/lttng/command.h
src/bin/lttng/commands/add_context.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/help.c
src/bin/lttng/commands/list.c
src/bin/lttng/commands/load.c
src/bin/lttng/commands/metadata.c
src/bin/lttng/commands/regenerate.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/lttng.c
src/bin/lttng/utils.c
src/bin/lttng/utils.h
src/common/utils.c
src/common/utils.h

index 93ef389358c7a4903bc558602f56d673442b34c9..3ee0821914e2cd9758d7767d68ed592cf8ae01cf 100644 (file)
@@ -116,6 +116,7 @@ tests/regression/ust/python-logging/test_python_logging
 /doc/man/*.8
 /doc/man/*.xml
 /doc/man/*.html
 /doc/man/*.8
 /doc/man/*.xml
 /doc/man/*.html
+/doc/man/*.h
 /doc/man/asciidoc-attrs.conf
 !/doc/man/lttng-health-check.3
 
 /doc/man/asciidoc-attrs.conf
 !/doc/man/lttng-health-check.3
 
index 63101c541ce5f9f68c52736d24d7d4bcc15f600a..6ebdb589a7033704e87affbbb47fb58f82094d28 100644 (file)
@@ -1,8 +1,8 @@
 ACLOCAL_AMFLAGS = -I m4
 
 ACLOCAL_AMFLAGS = -I m4
 
-DIST_SUBDIRS = include src extras doc tests
+DIST_SUBDIRS = include doc src extras tests
 
 
-SUBDIRS = include src doc tests
+SUBDIRS = include doc src tests
 
 if BUILD_EXTRAS
 SUBDIRS += extras
 
 if BUILD_EXTRAS
 SUBDIRS += extras
index 191dd838c1c42e9db1510d3cdb0ea5bf69ad2139..b19d9d0d591837763ac1ef478990fdfe25be02cd 100644 (file)
@@ -653,6 +653,29 @@ AM_CONDITIONAL([HAVE_ASCIIDOC_XMLTO], [test "x$have_asciidoc_xmlto" = "xyes"])
 
 AC_DEFINE_UNQUOTED([MANPATH], ["`eval eval echo $mandir`"], [Path to man pages.])
 
 
 AC_DEFINE_UNQUOTED([MANPATH], ["`eval eval echo $mandir`"], [Path to man pages.])
 
+# embedded --help message
+AC_ARG_ENABLE(
+       [embedded-help],
+       AS_HELP_STRING(
+               [--enable-embedded-help],
+               [Embed the --help messages in the executable files]
+       ),
+       [embedded_help=$enableval],
+       [embedded_help=no]
+)
+AS_IF([test "x$embedded_help" = "xyes"], [
+       AS_IF([test "x$man_pages_opt" = "xno"], [
+               AC_MSG_ERROR([You need the --enable-man-pages option with the --enable-embedded-help option.])
+       ])
+       AC_PATH_PROG([man_prog_path], [man], [no])
+       AS_IF([test "x$man_prog_path" = "xno"], [
+               AC_MSG_ERROR([You need man with the --enable-embedded-help option.])
+       ])
+       AC_DEFINE_UNQUOTED([LTTNG_EMBED_HELP], 1, [Embed --help messages.])
+       AC_SUBST([MANPROG], [$man_prog_path])
+])
+AM_CONDITIONAL([EMBED_HELP], [test "x$embedded_help" != "xno"])
+
 # Python agent test
 UST_PYTHON_AGENT="lttngust"
 
 # Python agent test
 UST_PYTHON_AGENT="lttngust"
 
@@ -1186,6 +1209,9 @@ AS_IF([test "x$man_pages_opt" != "xno"], [
 
 m4_popdef([build_man_pages_msg])
 
 
 m4_popdef([build_man_pages_msg])
 
+test "x$embedded_help" = xyes && value=1 || value=0
+PPRINT_PROP_BOOL([Embed --help messages], $value, $PPRINT_COLOR_SUBTITLE)
+
 PPRINT_SET_INDENT(1)
 
 report_bindir="`eval eval echo $bindir`"
 PPRINT_SET_INDENT(1)
 
 report_bindir="`eval eval echo $bindir`"
index 845e475dd4e82c0c73fccc2927a76da7bd7ec756..2258890f018b07c2fdbd8748f33f137ac817affd 100644 (file)
@@ -73,6 +73,34 @@ MAN3_NO_ASCIIDOC = $(addsuffix .3,$(MAN3_NO_ASCIIDOC_NAMES))
 MAN8_NO_ASCIIDOC = $(addsuffix .8,$(MAN8_NO_ASCIIDOC_NAMES))
 MAN = $(MAN1) $(MAN3) $(MAN8)
 
 MAN8_NO_ASCIIDOC = $(addsuffix .8,$(MAN8_NO_ASCIIDOC_NAMES))
 MAN = $(MAN1) $(MAN3) $(MAN8)
 
+# initially empty
+CLEANFILES =
+
+if EMBED_HELP
+MAN1_H = $(addsuffix .1.h,$(MAN1_NAMES))
+MAN3_H = $(addsuffix .3.h,$(MAN3_NAMES))
+MAN8_H = $(addsuffix .8.h,$(MAN8_NAMES))
+MAN_H = $(MAN1_H) $(MAN3_H) $(MAN8_H)
+MAN_H_RECIPE = \
+       MANWIDTH=80 @MANPROG@ --encoding=UTF-8 --no-hyphenation --no-justification --local-file $< > $@ ; \
+       $(SED) -i 's/\\/\\\\/g' $@ ; \
+       $(SED) -i 's/"/\\"/g' $@ ; \
+       $(SED) -i 's/^\(.*\)$$/"\1\\n"/' $@
+
+%.1.h: %.1
+       $(MAN_H_RECIPE)
+
+%.3.h: %.3
+       $(MAN_H_RECIPE)
+
+%.8.h: %.8
+       $(MAN_H_RECIPE)
+
+all-local: $(MAN_H)
+
+CLEANFILES += $(MAN_H)
+endif # EMBED_HELP
+
 if MAN_PAGES_OPT
 # at this point, we know the user asked to build the man pages
 if HAVE_ASCIIDOC_XMLTO
 if MAN_PAGES_OPT
 # at this point, we know the user asked to build the man pages
 if HAVE_ASCIIDOC_XMLTO
@@ -106,7 +134,7 @@ COMMON_DEPS += $(ASCIIDOC_ATTRS_CONF)
        $(XTO) $<
 
 # only clean the generated files if we have the tools to generate them again
        $(XTO) $<
 
 # only clean the generated files if we have the tools to generate them again
-CLEANFILES = $(MAN_XML) $(MAN)
+CLEANFILES += $(MAN_XML) $(MAN)
 else # HAVE_ASCIIDOC_XMLTO
 # create man page targets used to stop the build if we want to
 # build the man pages, but we don't have the necessary tools to do so
 else # HAVE_ASCIIDOC_XMLTO
 # create man page targets used to stop the build if we want to
 # build the man pages, but we don't have the necessary tools to do so
@@ -148,3 +176,6 @@ endif # !MAN_PAGES_OPT
 # always distribute the source files
 EXTRA_DIST = $(MAN_TXT) $(COMMON_TXT) $(XSL_SRC_FILES) \
        $(ASCIIDOC_CONF) $(ASCIIDOC_ATTRS_CONF).in
 # always distribute the source files
 EXTRA_DIST = $(MAN_TXT) $(COMMON_TXT) $(XSL_SRC_FILES) \
        $(ASCIIDOC_CONF) $(ASCIIDOC_ATTRS_CONF).in
+
+# keep generated man pages that can be considered intermediate files
+.PRECIOUS: %.1 %.3 %.8
index a0adfbc84f28df3e967c3e0e6ae253260c5bd098..ae4776f7e086b23efc5ed2652fd38608f14a8658 100644 (file)
@@ -1,6 +1,10 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
                          -DINSTALL_BIN_PATH=\""$(bindir)"\"
 
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
                          -DINSTALL_BIN_PATH=\""$(bindir)"\"
 
+if EMBED_HELP
+AM_CPPFLAGS += -I$(top_builddir)/doc/man
+endif
+
 bin_PROGRAMS = lttng-crash
 
 lttng_crash_SOURCES = lttng-crash.c
 bin_PROGRAMS = lttng-crash
 
 lttng_crash_SOURCES = lttng-crash.c
index ba28af9afa9003f2f92decb5ade2275634b38a02..53de81bd46b640bb77862d6af48a472217844310 100644 (file)
                0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF,     \
        }
 
                0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF,     \
        }
 
+static const char *help_msg =
+#ifdef LTTNG_EMBED_HELP
+#include <lttng-crash.1.h>
+#else
+NULL
+#endif
+;
+
 /*
  * Non-static to ensure the compiler does not optimize away the xor.
  */
 /*
  * Non-static to ensure the compiler does not optimize away the xor.
  */
@@ -207,10 +215,10 @@ static struct option long_options[] = {
 
 static void usage(void)
 {
 
 static void usage(void)
 {
-       int ret = utils_show_man_page(1, "lttng-crash");
+       int ret = utils_show_help(1, "lttng-crash", help_msg);
 
        if (ret) {
 
        if (ret) {
-               ERR("Cannot view man page lttng-crash(1)");
+               ERR("Cannot show --help for `lttng-crash`");
                perror("exec");
                exit(EXIT_FAILURE);
        }
                perror("exec");
                exit(EXIT_FAILURE);
        }
index df87bc3005311d6b297d3680d1d7fe06306d914c..31859b564cba54be4b3ff2c882d50e283b3a2923 100644 (file)
@@ -2,6 +2,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
                          -DINSTALL_BIN_PATH=\""$(lttnglibexecdir)"\" \
                          -DINSTALL_LIB_PATH=\""$(libdir)"\"
 
                          -DINSTALL_BIN_PATH=\""$(lttnglibexecdir)"\" \
                          -DINSTALL_LIB_PATH=\""$(libdir)"\"
 
+if EMBED_HELP
+AM_CPPFLAGS += -I$(top_builddir)/doc/man
+endif
+
 AM_CFLAGS = -fno-strict-aliasing
 
 bin_PROGRAMS = lttng-relayd
 AM_CFLAGS = -fno-strict-aliasing
 
 bin_PROGRAMS = lttng-relayd
index 919c5a96a7a2baa1680febd84ccb9e225fa3a386..2fcc60af00d9d3b29b9809865ed7747ab4dbde45 100644 (file)
 #include "connection.h"
 #include "tracefile-array.h"
 
 #include "connection.h"
 #include "tracefile-array.h"
 
+static const char *help_msg =
+#ifdef LTTNG_EMBED_HELP
+#include <lttng-relayd.8.h>
+#else
+NULL
+#endif
+;
+
 /* command line options */
 char *opt_output_path;
 static int opt_daemon, opt_background;
 /* command line options */
 char *opt_output_path;
 static int opt_daemon, opt_background;
@@ -250,9 +258,9 @@ static int set_option(int opt, const char *arg, const char *optname)
                }
                break;
        case 'h':
                }
                break;
        case 'h':
-               ret = utils_show_man_page(8, "lttng-relayd");
+               ret = utils_show_help(8, "lttng-relayd", help_msg);
                if (ret) {
                if (ret) {
-                       ERR("Cannot view man page lttng-relayd(8)");
+                       ERR("Cannot show --help for `lttng-relayd`");
                        perror("exec");
                }
                exit(EXIT_FAILURE);
                        perror("exec");
                }
                exit(EXIT_FAILURE);
index 0ac7506b440dc825151c32db1bbeca862c70613c..755c2aa0ff61153cb0151f7c45a0d70fc1933b26 100644 (file)
@@ -2,6 +2,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
                          -DINSTALL_BIN_PATH=\""$(lttnglibexecdir)"\" \
                          -DINSTALL_LIB_PATH=\""$(libdir)"\"
 
                          -DINSTALL_BIN_PATH=\""$(lttnglibexecdir)"\" \
                          -DINSTALL_LIB_PATH=\""$(libdir)"\"
 
+if EMBED_HELP
+AM_CPPFLAGS += -I$(top_builddir)/doc/man
+endif
+
 AM_CFLAGS = -fno-strict-aliasing
 
 bin_PROGRAMS = lttng-sessiond
 AM_CFLAGS = -fno-strict-aliasing
 
 bin_PROGRAMS = lttng-sessiond
index 9cde946495436f04590339475e96f95b5ea7421c..b856e126fa3fae8c6cc2c3e3d69ae63dd43a84fc 100644 (file)
 
 #define CONSUMERD_FILE "lttng-consumerd"
 
 
 #define CONSUMERD_FILE "lttng-consumerd"
 
+static const char *help_msg =
+#ifdef LTTNG_EMBED_HELP
+#include <lttng-sessiond.8.h>
+#else
+NULL
+#endif
+;
+
 const char *progname;
 const char *tracing_group_name = DEFAULT_TRACING_GROUP;
 static int tracing_group_name_override;
 const char *progname;
 const char *tracing_group_name = DEFAULT_TRACING_GROUP;
 static int tracing_group_name_override;
@@ -4757,9 +4765,9 @@ static int set_option(int opt, const char *arg, const char *optname)
                        tracing_group_name_override = 1;
                }
        } else if (string_match(optname, "help") || opt == 'h') {
                        tracing_group_name_override = 1;
                }
        } else if (string_match(optname, "help") || opt == 'h') {
-               ret = utils_show_man_page(8, "lttng-sessiond");
+               ret = utils_show_help(8, "lttng-sessiond", help_msg);
                if (ret) {
                if (ret) {
-                       ERR("Cannot view man page lttng-sessiond(8)");
+                       ERR("Cannot show --help for `lttng-sessiond`");
                        perror("exec");
                }
                exit(ret ? EXIT_FAILURE : EXIT_SUCCESS);
                        perror("exec");
                }
                exit(ret ? EXIT_FAILURE : EXIT_SUCCESS);
index 03aa31bd04e153e41afaba8d127c80cd123c60bb..23fff77a7f9d144900df5df2e8b0e4071dae7dde 100644 (file)
@@ -1,6 +1,10 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
                          -DINSTALL_BIN_PATH=\""$(bindir)"\"
 
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
                          -DINSTALL_BIN_PATH=\""$(bindir)"\"
 
+if EMBED_HELP
+AM_CPPFLAGS += -I$(top_builddir)/doc/man
+endif
+
 AUTOMAKE_OPTIONS = subdir-objects
 
 bin_PROGRAMS = lttng
 AUTOMAKE_OPTIONS = subdir-objects
 
 bin_PROGRAMS = lttng
index b5c968d39c2b2cdf210d5c2b32830d6706cc90b7..bda6ef937d3b4c4ce0498fce49b771e52ddec45c 100644 (file)
 #define DECL_COMMAND(_name) \
        extern int cmd_##_name(int, const char **)
 
 #define DECL_COMMAND(_name) \
        extern int cmd_##_name(int, const char **)
 
+#ifdef LTTNG_EMBED_HELP
+# define HELP_MSG_NAME         help_msg
+# define SHOW_HELP_ERROR_LINE  ERR("Cannot show --help for `lttng-%s`", argv[0]);
+#else
+# define HELP_MSG_NAME         NULL
+# define SHOW_HELP_ERROR_LINE  ;
+#endif
+
 #define SHOW_HELP()                                                    \
        do {                                                            \
 #define SHOW_HELP()                                                    \
        do {                                                            \
-               ret = show_cmd_man_page(argv[0]);                       \
+               ret = show_cmd_help(argv[0], HELP_MSG_NAME);            \
                                                                        \
                if (ret) {                                              \
                                                                        \
                if (ret) {                                              \
-                       ERR("Cannot view man page lttng-%s(1)", argv[0]); \
-                       perror("exec");                                 \
+                       SHOW_HELP_ERROR_LINE                            \
                        ret = CMD_ERROR;                                \
                }                                                       \
        } while (0)
                        ret = CMD_ERROR;                                \
                }                                                       \
        } while (0)
index df722bb249f39ef8ee28107c501a3b668998ca49..209a9f4eb1eba9a804b701d017f46a7598ad65fa 100644 (file)
@@ -41,6 +41,12 @@ static int opt_jul;
 static int opt_log4j;
 static char *opt_type;
 
 static int opt_log4j;
 static char *opt_type;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-add-context.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_TYPE,
 enum {
        OPT_HELP = 1,
        OPT_TYPE,
index 40d2a77d94b48b9d8435948c2c2b557ade3792ed..d075f64b90742c08b8463058440c7c2722fbc316 100644 (file)
@@ -51,6 +51,12 @@ static int opt_no_output;
 static int opt_snapshot;
 static unsigned int opt_live_timer;
 
 static int opt_snapshot;
 static unsigned int opt_live_timer;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-create.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index e0bafc475b6451cd4e3d0c8cd6b79583609936f4..0e603e13c5c5904b6dca49c2541c8da02bed9b92 100644 (file)
@@ -35,6 +35,12 @@ static char *opt_session_name;
 static int opt_destroy_all;
 static int opt_no_wait;
 
 static int opt_destroy_all;
 static int opt_no_wait;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-destroy.1.h>
+;
+#endif
+
 /* Mi writer */
 static struct mi_writer *writer;
 
 /* Mi writer */
 static struct mi_writer *writer;
 
index 678af746d5091181aed4febe926130525afa7c5b..775ff895905b1fc91247b507a2a78a014adec254 100644 (file)
@@ -34,6 +34,12 @@ static int opt_kernel;
 static char *opt_session_name;
 static int opt_userspace;
 
 static char *opt_session_name;
 static int opt_userspace;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-disable-channel.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_USERSPACE,
 enum {
        OPT_HELP = 1,
        OPT_USERSPACE,
index 238f8463fec1553c4f8410091a3ebbb057752423..269620178e4093101da62a78379d7f9d6af36bcf 100644 (file)
@@ -40,6 +40,12 @@ static int opt_log4j;
 static int opt_python;
 static int opt_event_type;
 
 static int opt_python;
 static int opt_event_type;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-disable-event.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_TYPE_SYSCALL,
 enum {
        OPT_HELP = 1,
        OPT_TYPE_SYSCALL,
index fa8513e72320c1f835af634fed3f14dbca5d18d8..950cdb67e671e61cc164e1d050ba5454ec3bd0e7 100644 (file)
@@ -51,6 +51,12 @@ static struct {
 
 static struct mi_writer *writer;
 
 
 static struct mi_writer *writer;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-enable-channel.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_DISCARD,
 enum {
        OPT_HELP = 1,
        OPT_DISCARD,
index 8a32837e6216e599c06c0861ebd64c1e8a641fd9..1ed3a0ab77c435d5dbe80b5fbfb95778e9c0ec2c 100644 (file)
@@ -55,6 +55,12 @@ static char *opt_channel_name;
 static char *opt_filter;
 static char *opt_exclude;
 
 static char *opt_filter;
 static char *opt_exclude;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-enable-event.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_TRACEPOINT,
 enum {
        OPT_HELP = 1,
        OPT_TRACEPOINT,
index 29f56bab1778f3dd38ce5186bc5da6a21b7ebc7e..5db141959d1bd089d7f8a65ea93fc957893464d3 100644 (file)
 #include "../command.h"
 #include <common/utils.h>
 
 #include "../command.h"
 #include <common/utils.h>
 
+static const char *help_msg =
+#ifdef LTTNG_EMBED_HELP
+#include <lttng-help.1.h>
+#else
+NULL
+#endif
+;
+
+static const char *lttng_help_msg =
+#ifdef LTTNG_EMBED_HELP
+#include <lttng.1.h>
+#else
+NULL
+#endif
+;
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
@@ -69,14 +85,14 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
 
        if (cmd_name == NULL) {
                /* Fall back to lttng(1) */
 
        if (cmd_name == NULL) {
                /* Fall back to lttng(1) */
-               ret = utils_show_man_page(1, "lttng");
-
+               ret = utils_show_help(1, "lttng", lttng_help_msg);
                if (ret) {
                if (ret) {
-                       ERR("Cannot view man page lttng(1)");
+                       ERR("Cannot show --help for `lttng`");
                        perror("exec");
                        ret = CMD_ERROR;
                        perror("exec");
                        ret = CMD_ERROR;
-                       goto end;
                }
                }
+
+               goto end;
        }
 
        /* Make sure command name exists */
        }
 
        /* Make sure command name exists */
index c1f91d13546fe5264f4dad3bb89689ee257fd5cd..1315783f34149721163cfdd125947e7dccb9bbb1 100644 (file)
@@ -42,6 +42,12 @@ const char *indent4 = "    ";
 const char *indent6 = "      ";
 const char *indent8 = "        ";
 
 const char *indent6 = "      ";
 const char *indent8 = "        ";
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-list.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_USERSPACE,
 enum {
        OPT_HELP = 1,
        OPT_USERSPACE,
index 0516351ea8ddaddfbe4fdfb312c6f986d16ef6c7..ad61849235d74220f5328e7bdc496fcabd6896ba 100644 (file)
@@ -37,6 +37,12 @@ static int opt_load_all;
 
 static const char *session_name;
 
 
 static const char *session_name;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-load.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_ALL,
 enum {
        OPT_HELP = 1,
        OPT_ALL,
index 08d6e5894cdf8366b215329789e03616cd75d944..4a5ab819823625883aa27ae46101af5909965b1f 100644 (file)
@@ -33,6 +33,12 @@ static char *session_name = NULL;
 
 static int metadata_regenerate(int argc, const char **argv);
 
 
 static int metadata_regenerate(int argc, const char **argv);
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-metadata.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index 5c982c8a68752ef440c462f4f1fd5eb97790ff01..298312bba6ab01ac1ca3309bd7c743b932fc613c 100644 (file)
@@ -34,6 +34,12 @@ static char *session_name = NULL;
 static int regenerate_metadata(int argc, const char **argv);
 static int regenerate_statedump(int argc, const char **argv);
 
 static int regenerate_metadata(int argc, const char **argv);
 static int regenerate_statedump(int argc, const char **argv);
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-regenerate.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index ee3e17c66e2b3fe89dc921348aeb5005a12f1dc9..4ba90243698c9c13e50b3efc93dc1b57ab98c48d 100644 (file)
@@ -33,6 +33,12 @@ static bool opt_force;
 static bool opt_save_all;
 static struct mi_writer *writer;
 
 static bool opt_save_all;
 static struct mi_writer *writer;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-save.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_ALL,
 enum {
        OPT_HELP = 1,
        OPT_ALL,
index 32e9a5d645763056ad430e6a791decb4a4439082..d143c7dd45ff2623899047b8b5e89ef0ed45dbcc 100644 (file)
 
 static char *opt_session_name;
 
 
 static char *opt_session_name;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-set-session.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index 11cc2496a2b61e649661df782a8da66fc375b30b..d8a6b81486939fdb945ca91b96bc19a6be4c6ce3 100644 (file)
@@ -48,6 +48,12 @@ static int cmd_record(int argc, const char **argv);
 
 static const char *indent4 = "    ";
 
 
 static const char *indent4 = "    ";
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-snapshot.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index 03d99cf4143b4f5a42245a474af9663d9f2e92d6..0287fc7e8cf144a4fee7b574862ae85f892561d9 100644 (file)
 static char *opt_session_name;
 static struct mi_writer *writer;
 
 static char *opt_session_name;
 static struct mi_writer *writer;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-start.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index 5daabdac2f7ec62dd2b67d56d029b5f8a0ad8221..cb7d0329b43faba3b14ef3a5ac1fee8869c6a50e 100644 (file)
 #include "../utils.h"
 #include <config.h>
 
 #include "../utils.h"
 #include <config.h>
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-status.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index c38fc894a741debd87a91aec43ec69701a1af178..336d887651d06b5872f222b652584b88b6fcbeb7 100644 (file)
@@ -34,6 +34,12 @@ static char *opt_session_name;
 static int opt_no_wait;
 static struct mi_writer *writer;
 
 static int opt_no_wait;
 static struct mi_writer *writer;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-stop.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index 154501e597ab56a6de266447be1f6c995235efc3..59bf53d94a4a57476e7526768a1bb97277a3fdcf 100644 (file)
@@ -320,7 +320,7 @@ const char *get_mi_element_command(enum cmd_type cmd_type)
  */
 static
 int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str,
  */
 static
 int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str,
-               int argc, const char **argv)
+               int argc, const char **argv, const char *help_msg)
 {
        int opt, ret = 0;
        enum cmd_error_code command_ret = CMD_SUCCESS;
 {
        int opt, ret = 0;
        enum cmd_error_code command_ret = CMD_SUCCESS;
@@ -454,10 +454,26 @@ end:
 
 int cmd_track(int argc, const char **argv)
 {
 
 int cmd_track(int argc, const char **argv)
 {
-       return cmd_track_untrack(CMD_TRACK, "track", argc, argv);
+       static const char *help_msg =
+#ifdef LTTNG_EMBED_HELP
+#include <lttng-track.1.h>
+#else
+       NULL
+#endif
+       ;
+
+       return cmd_track_untrack(CMD_TRACK, "track", argc, argv, help_msg);
 }
 
 int cmd_untrack(int argc, const char **argv)
 {
 }
 
 int cmd_untrack(int argc, const char **argv)
 {
-       return cmd_track_untrack(CMD_UNTRACK, "untrack", argc, argv);
+       static const char *help_msg =
+#ifdef LTTNG_EMBED_HELP
+#include <lttng-untrack.1.h>
+#else
+       NULL
+#endif
+       ;
+
+       return cmd_track_untrack(CMD_UNTRACK, "untrack", argc, argv, help_msg);
 }
 }
index cf46a8cb0e32fe7f3e1b35ed1dffa43d41dd0a90..ae43eaf2e74b715deb35aa2801dda78202bdc2d4 100644 (file)
 
 #include "../command.h"
 
 
 #include "../command.h"
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-version.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index db13ee22718d9fcc0c4eb9636bcd9593ef012032..c9a5fdc3e09b0f356096a25a051c55d730ea86c8 100644 (file)
@@ -32,6 +32,12 @@ static char *opt_trace_path;
 static const char *babeltrace_bin = CONFIG_BABELTRACE_BIN;
 //static const char *lttv_gui_bin = CONFIG_LTTV_GUI_BIN;
 
 static const char *babeltrace_bin = CONFIG_BABELTRACE_BIN;
 //static const char *lttv_gui_bin = CONFIG_LTTV_GUI_BIN;
 
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-view.1.h>
+;
+#endif
+
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
 enum {
        OPT_HELP = 1,
        OPT_LIST_OPTIONS,
index b3ee2428640f945d1b4bf68736f1c2a91469edc0..ecfea53ff4b36121c8f56b0747e66298968b57ba 100644 (file)
 
 #include "command.h"
 
 
 #include "command.h"
 
+static const char *help_msg =
+#ifdef LTTNG_EMBED_HELP
+#include <lttng.1.h>
+#else
+NULL
+#endif
+;
+
 /* Variables */
 static char *progname;
 int opt_no_sessiond;
 /* Variables */
 static char *progname;
 int opt_no_sessiond;
@@ -316,10 +324,9 @@ static int parse_args(int argc, char **argv)
                        ret = 0;
                        goto end;
                case 'h':
                        ret = 0;
                        goto end;
                case 'h':
-                       ret = utils_show_man_page(1, "lttng");
-
+                       ret = utils_show_help(1, "lttng", help_msg);
                        if (ret) {
                        if (ret) {
-                               ERR("Cannot view man page lttng(1)");
+                               ERR("Cannot show --help for `lttng`");
                                perror("exec");
                        }
                        goto end;
                                perror("exec");
                        }
                        goto end;
index 912cbd5775b08bd97485c3dd3768a8ed1a6a8a71..06df5090ac767307eb37328d418c49b6fc7ca922 100644 (file)
@@ -482,13 +482,18 @@ end:
        return;
 }
 
        return;
 }
 
-int show_cmd_man_page(const char *cmd_name)
+int show_cmd_help(const char *cmd_name, const char *help_msg)
 {
        int ret;
        char page_name[32];
 
        ret = sprintf(page_name, "lttng-%s", cmd_name);
        assert(ret > 0 && ret < 32);
 {
        int ret;
        char page_name[32];
 
        ret = sprintf(page_name, "lttng-%s", cmd_name);
        assert(ret > 0 && ret < 32);
+       ret = utils_show_help(1, page_name, help_msg);
+       if (ret && !help_msg) {
+               ERR("Cannot view man page `lttng-%s(1)`", cmd_name);
+               perror("exec");
+       }
 
 
-       return utils_show_man_page(1, page_name);
+       return ret;
 }
 }
index 7f656df13481c06856a154ac707a356bcc1a4caa..2d20e2bfe0ea9a9c427b105e5490f97b076fb7d3 100644 (file)
@@ -60,6 +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 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);
+int show_cmd_help(const char *cmd_name, const char *help_msg);
 
 #endif /* _LTTNG_UTILS_H */
 
 #endif /* _LTTNG_UTILS_H */
index 4d49728c0f47a23cce6eba1bc2f72f11c2c14836..893122905bd44ca75b9fa3836cdf9098e142dfff 100644 (file)
@@ -1429,11 +1429,17 @@ static const char *get_man_bin_path(void)
 }
 
 LTTNG_HIDDEN
 }
 
 LTTNG_HIDDEN
-int utils_show_man_page(int section, const char *page_name)
+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();
 {
        char section_string[8];
        const char *man_bin_path = get_man_bin_path();
-       int ret;
+       int ret = 0;
+
+       if (help_msg) {
+               printf("%s", help_msg);
+               goto end;
+       }
 
        /* Section integer -> section string */
        ret = sprintf(section_string, "%d", section);
 
        /* Section integer -> section string */
        ret = sprintf(section_string, "%d", section);
@@ -1448,5 +1454,7 @@ int utils_show_man_page(int section, const char *page_name)
         */
        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;
 }
        return ret;
 }
index 0daf5b98df70d7add96b6a7fda2fac53e85ad681..db25c6c9b6de926f6f9f9861b3309ebf9b236a0b 100644 (file)
@@ -60,6 +60,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_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);
+int utils_show_help(int section, const char *page_name, const char *help_msg);
 
 #endif /* _COMMON_UTILS_H */
 
 #endif /* _COMMON_UTILS_H */
This page took 0.053016 seconds and 4 git commands to generate.