From 4fc83d948cea6b10484e65f004a6c167e71ac440 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 1 Dec 2016 01:29:38 -0500 Subject: [PATCH] Add --enable-embedded-help option to embed --help messages in binaries MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- .gitignore | 1 + Makefile.am | 4 +-- configure.ac | 26 ++++++++++++++++++ doc/man/Makefile.am | 33 ++++++++++++++++++++++- src/bin/lttng-crash/Makefile.am | 4 +++ src/bin/lttng-crash/lttng-crash.c | 12 +++++++-- src/bin/lttng-relayd/Makefile.am | 4 +++ src/bin/lttng-relayd/main.c | 12 +++++++-- src/bin/lttng-sessiond/Makefile.am | 4 +++ src/bin/lttng-sessiond/main.c | 12 +++++++-- src/bin/lttng/Makefile.am | 4 +++ src/bin/lttng/command.h | 13 ++++++--- src/bin/lttng/commands/add_context.c | 6 +++++ src/bin/lttng/commands/create.c | 6 +++++ src/bin/lttng/commands/destroy.c | 6 +++++ src/bin/lttng/commands/disable_channels.c | 6 +++++ src/bin/lttng/commands/disable_events.c | 6 +++++ src/bin/lttng/commands/enable_channels.c | 6 +++++ src/bin/lttng/commands/enable_events.c | 6 +++++ src/bin/lttng/commands/help.c | 24 ++++++++++++++--- src/bin/lttng/commands/list.c | 6 +++++ src/bin/lttng/commands/load.c | 6 +++++ src/bin/lttng/commands/metadata.c | 6 +++++ src/bin/lttng/commands/regenerate.c | 6 +++++ src/bin/lttng/commands/save.c | 6 +++++ src/bin/lttng/commands/set_session.c | 6 +++++ src/bin/lttng/commands/snapshot.c | 6 +++++ src/bin/lttng/commands/start.c | 6 +++++ src/bin/lttng/commands/status.c | 6 +++++ src/bin/lttng/commands/stop.c | 6 +++++ src/bin/lttng/commands/track-untrack.c | 22 ++++++++++++--- src/bin/lttng/commands/version.c | 6 +++++ src/bin/lttng/commands/view.c | 6 +++++ src/bin/lttng/lttng.c | 13 ++++++--- src/bin/lttng/utils.c | 9 +++++-- src/bin/lttng/utils.h | 2 +- src/common/utils.c | 12 +++++++-- src/common/utils.h | 2 +- 38 files changed, 299 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 93ef38935..3ee082191 100644 --- a/.gitignore +++ b/.gitignore @@ -116,6 +116,7 @@ tests/regression/ust/python-logging/test_python_logging /doc/man/*.8 /doc/man/*.xml /doc/man/*.html +/doc/man/*.h /doc/man/asciidoc-attrs.conf !/doc/man/lttng-health-check.3 diff --git a/Makefile.am b/Makefile.am index 63101c541..6ebdb589a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,8 @@ 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 diff --git a/configure.ac b/configure.ac index 191dd838c..b19d9d0d5 100644 --- a/configure.ac +++ b/configure.ac @@ -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.]) +# 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" @@ -1186,6 +1209,9 @@ AS_IF([test "x$man_pages_opt" != "xno"], [ 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`" diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am index 845e475dd..2258890f0 100644 --- a/doc/man/Makefile.am +++ b/doc/man/Makefile.am @@ -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) +# 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 @@ -106,7 +134,7 @@ COMMON_DEPS += $(ASCIIDOC_ATTRS_CONF) $(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 @@ -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 + +# keep generated man pages that can be considered intermediate files +.PRECIOUS: %.1 %.3 %.8 diff --git a/src/bin/lttng-crash/Makefile.am b/src/bin/lttng-crash/Makefile.am index a0adfbc84..ae4776f7e 100644 --- a/src/bin/lttng-crash/Makefile.am +++ b/src/bin/lttng-crash/Makefile.am @@ -1,6 +1,10 @@ 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 diff --git a/src/bin/lttng-crash/lttng-crash.c b/src/bin/lttng-crash/lttng-crash.c index ba28af9af..53de81bd4 100644 --- a/src/bin/lttng-crash/lttng-crash.c +++ b/src/bin/lttng-crash/lttng-crash.c @@ -61,6 +61,14 @@ 0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, \ } +static const char *help_msg = +#ifdef LTTNG_EMBED_HELP +#include +#else +NULL +#endif +; + /* * 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) { - int ret = utils_show_man_page(1, "lttng-crash"); + int ret = utils_show_help(1, "lttng-crash", help_msg); if (ret) { - ERR("Cannot view man page lttng-crash(1)"); + ERR("Cannot show --help for `lttng-crash`"); perror("exec"); exit(EXIT_FAILURE); } diff --git a/src/bin/lttng-relayd/Makefile.am b/src/bin/lttng-relayd/Makefile.am index df87bc300..31859b564 100644 --- a/src/bin/lttng-relayd/Makefile.am +++ b/src/bin/lttng-relayd/Makefile.am @@ -2,6 +2,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \ -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 diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 919c5a96a..2fcc60af0 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -71,6 +71,14 @@ #include "connection.h" #include "tracefile-array.h" +static const char *help_msg = +#ifdef LTTNG_EMBED_HELP +#include +#else +NULL +#endif +; + /* 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': - ret = utils_show_man_page(8, "lttng-relayd"); + ret = utils_show_help(8, "lttng-relayd", help_msg); if (ret) { - ERR("Cannot view man page lttng-relayd(8)"); + ERR("Cannot show --help for `lttng-relayd`"); perror("exec"); } exit(EXIT_FAILURE); diff --git a/src/bin/lttng-sessiond/Makefile.am b/src/bin/lttng-sessiond/Makefile.am index 0ac7506b4..755c2aa0f 100644 --- a/src/bin/lttng-sessiond/Makefile.am +++ b/src/bin/lttng-sessiond/Makefile.am @@ -2,6 +2,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \ -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 diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 9cde94649..b856e126f 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -79,6 +79,14 @@ #define CONSUMERD_FILE "lttng-consumerd" +static const char *help_msg = +#ifdef LTTNG_EMBED_HELP +#include +#else +NULL +#endif +; + 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') { - ret = utils_show_man_page(8, "lttng-sessiond"); + ret = utils_show_help(8, "lttng-sessiond", help_msg); 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); diff --git a/src/bin/lttng/Makefile.am b/src/bin/lttng/Makefile.am index 03aa31bd0..23fff77a7 100644 --- a/src/bin/lttng/Makefile.am +++ b/src/bin/lttng/Makefile.am @@ -1,6 +1,10 @@ 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 diff --git a/src/bin/lttng/command.h b/src/bin/lttng/command.h index b5c968d39..bda6ef937 100644 --- a/src/bin/lttng/command.h +++ b/src/bin/lttng/command.h @@ -28,13 +28,20 @@ #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 { \ - ret = show_cmd_man_page(argv[0]); \ + ret = show_cmd_help(argv[0], HELP_MSG_NAME); \ \ if (ret) { \ - ERR("Cannot view man page lttng-%s(1)", argv[0]); \ - perror("exec"); \ + SHOW_HELP_ERROR_LINE \ ret = CMD_ERROR; \ } \ } while (0) diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index df722bb24..209a9f4eb 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -41,6 +41,12 @@ static int opt_jul; static int opt_log4j; static char *opt_type; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_TYPE, diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index 40d2a77d9..d075f64b9 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -51,6 +51,12 @@ static int opt_no_output; static int opt_snapshot; static unsigned int opt_live_timer; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/destroy.c b/src/bin/lttng/commands/destroy.c index e0bafc475..0e603e13c 100644 --- a/src/bin/lttng/commands/destroy.c +++ b/src/bin/lttng/commands/destroy.c @@ -35,6 +35,12 @@ static char *opt_session_name; static int opt_destroy_all; static int opt_no_wait; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + /* Mi writer */ static struct mi_writer *writer; diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index 678af746d..775ff8959 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -34,6 +34,12 @@ static int opt_kernel; static char *opt_session_name; static int opt_userspace; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_USERSPACE, diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index 238f8463f..269620178 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -40,6 +40,12 @@ static int opt_log4j; static int opt_python; static int opt_event_type; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_TYPE_SYSCALL, diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index fa8513e72..950cdb67e 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -51,6 +51,12 @@ static struct { static struct mi_writer *writer; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_DISCARD, diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 8a32837e6..1ed3a0ab7 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -55,6 +55,12 @@ static char *opt_channel_name; static char *opt_filter; static char *opt_exclude; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_TRACEPOINT, diff --git a/src/bin/lttng/commands/help.c b/src/bin/lttng/commands/help.c index 29f56bab1..5db141959 100644 --- a/src/bin/lttng/commands/help.c +++ b/src/bin/lttng/commands/help.c @@ -24,6 +24,22 @@ #include "../command.h" #include +static const char *help_msg = +#ifdef LTTNG_EMBED_HELP +#include +#else +NULL +#endif +; + +static const char *lttng_help_msg = +#ifdef LTTNG_EMBED_HELP +#include +#else +NULL +#endif +; + 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) */ - ret = utils_show_man_page(1, "lttng"); - + ret = utils_show_help(1, "lttng", lttng_help_msg); if (ret) { - ERR("Cannot view man page lttng(1)"); + ERR("Cannot show --help for `lttng`"); perror("exec"); ret = CMD_ERROR; - goto end; } + + goto end; } /* Make sure command name exists */ diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index c1f91d135..1315783f3 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -42,6 +42,12 @@ const char *indent4 = " "; const char *indent6 = " "; const char *indent8 = " "; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_USERSPACE, diff --git a/src/bin/lttng/commands/load.c b/src/bin/lttng/commands/load.c index 0516351ea..ad6184923 100644 --- a/src/bin/lttng/commands/load.c +++ b/src/bin/lttng/commands/load.c @@ -37,6 +37,12 @@ static int opt_load_all; static const char *session_name; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_ALL, diff --git a/src/bin/lttng/commands/metadata.c b/src/bin/lttng/commands/metadata.c index 08d6e5894..4a5ab8198 100644 --- a/src/bin/lttng/commands/metadata.c +++ b/src/bin/lttng/commands/metadata.c @@ -33,6 +33,12 @@ static char *session_name = NULL; static int metadata_regenerate(int argc, const char **argv); +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/regenerate.c b/src/bin/lttng/commands/regenerate.c index 5c982c8a6..298312bba 100644 --- a/src/bin/lttng/commands/regenerate.c +++ b/src/bin/lttng/commands/regenerate.c @@ -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); +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/save.c b/src/bin/lttng/commands/save.c index ee3e17c66..4ba902436 100644 --- a/src/bin/lttng/commands/save.c +++ b/src/bin/lttng/commands/save.c @@ -33,6 +33,12 @@ static bool opt_force; static bool opt_save_all; static struct mi_writer *writer; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_ALL, diff --git a/src/bin/lttng/commands/set_session.c b/src/bin/lttng/commands/set_session.c index 32e9a5d64..d143c7dd4 100644 --- a/src/bin/lttng/commands/set_session.c +++ b/src/bin/lttng/commands/set_session.c @@ -31,6 +31,12 @@ static char *opt_session_name; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c index 11cc2496a..d8a6b8148 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -48,6 +48,12 @@ static int cmd_record(int argc, const char **argv); static const char *indent4 = " "; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/start.c b/src/bin/lttng/commands/start.c index 03d99cf41..0287fc7e8 100644 --- a/src/bin/lttng/commands/start.c +++ b/src/bin/lttng/commands/start.c @@ -33,6 +33,12 @@ static char *opt_session_name; static struct mi_writer *writer; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/status.c b/src/bin/lttng/commands/status.c index 5daabdac2..cb7d0329b 100644 --- a/src/bin/lttng/commands/status.c +++ b/src/bin/lttng/commands/status.c @@ -28,6 +28,12 @@ #include "../utils.h" #include +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/stop.c b/src/bin/lttng/commands/stop.c index c38fc894a..336d88765 100644 --- a/src/bin/lttng/commands/stop.c +++ b/src/bin/lttng/commands/stop.c @@ -34,6 +34,12 @@ static char *opt_session_name; static int opt_no_wait; static struct mi_writer *writer; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index 154501e59..59bf53d94 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -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, - 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; @@ -454,10 +454,26 @@ end: 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 +#else + NULL +#endif + ; + + return cmd_track_untrack(CMD_TRACK, "track", argc, argv, help_msg); } 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 +#else + NULL +#endif + ; + + return cmd_track_untrack(CMD_UNTRACK, "untrack", argc, argv, help_msg); } diff --git a/src/bin/lttng/commands/version.c b/src/bin/lttng/commands/version.c index cf46a8cb0..ae43eaf2e 100644 --- a/src/bin/lttng/commands/version.c +++ b/src/bin/lttng/commands/version.c @@ -28,6 +28,12 @@ #include "../command.h" +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/commands/view.c b/src/bin/lttng/commands/view.c index db13ee227..c9a5fdc3e 100644 --- a/src/bin/lttng/commands/view.c +++ b/src/bin/lttng/commands/view.c @@ -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; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index b3ee24286..ecfea53ff 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -33,6 +33,14 @@ #include "command.h" +static const char *help_msg = +#ifdef LTTNG_EMBED_HELP +#include +#else +NULL +#endif +; + /* 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 = utils_show_man_page(1, "lttng"); - + ret = utils_show_help(1, "lttng", help_msg); if (ret) { - ERR("Cannot view man page lttng(1)"); + ERR("Cannot show --help for `lttng`"); perror("exec"); } goto end; diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index 912cbd577..06df5090a 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -482,13 +482,18 @@ end: 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); + 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; } diff --git a/src/bin/lttng/utils.h b/src/bin/lttng/utils.h index 7f656df13..2d20e2bfe 100644 --- a/src/bin/lttng/utils.h +++ b/src/bin/lttng/utils.h @@ -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 show_cmd_man_page(const char *cmd_name); +int show_cmd_help(const char *cmd_name, const char *help_msg); #endif /* _LTTNG_UTILS_H */ diff --git a/src/common/utils.c b/src/common/utils.c index 4d49728c0..893122905 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -1429,11 +1429,17 @@ static const char *get_man_bin_path(void) } 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(); - int ret; + int ret = 0; + + if (help_msg) { + printf("%s", help_msg); + goto end; + } /* 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); + +end: return ret; } diff --git a/src/common/utils.h b/src/common/utils.h index 0daf5b98d..db25c6c9b 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -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_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 */ -- 2.34.1