Skip to content

Commit 4fc83d9

Browse files
eeppjgalar
authored andcommitted
Add --enable-embedded-help option to embed --help messages in binaries
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 <[email protected]> Signed-off-by: Jérémie Galarneau <[email protected]>
1 parent cf0bcb5 commit 4fc83d9

38 files changed

+299
-28
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ tests/regression/ust/python-logging/test_python_logging
116116
/doc/man/*.8
117117
/doc/man/*.xml
118118
/doc/man/*.html
119+
/doc/man/*.h
119120
/doc/man/asciidoc-attrs.conf
120121
!/doc/man/lttng-health-check.3
121122

Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ACLOCAL_AMFLAGS = -I m4
22

3-
DIST_SUBDIRS = include src extras doc tests
3+
DIST_SUBDIRS = include doc src extras tests
44

5-
SUBDIRS = include src doc tests
5+
SUBDIRS = include doc src tests
66

77
if BUILD_EXTRAS
88
SUBDIRS += extras

configure.ac

+26
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,29 @@ AM_CONDITIONAL([HAVE_ASCIIDOC_XMLTO], [test "x$have_asciidoc_xmlto" = "xyes"])
653653

654654
AC_DEFINE_UNQUOTED([MANPATH], ["`eval eval echo $mandir`"], [Path to man pages.])
655655

656+
# embedded --help message
657+
AC_ARG_ENABLE(
658+
[embedded-help],
659+
AS_HELP_STRING(
660+
[--enable-embedded-help],
661+
[Embed the --help messages in the executable files]
662+
),
663+
[embedded_help=$enableval],
664+
[embedded_help=no]
665+
)
666+
AS_IF([test "x$embedded_help" = "xyes"], [
667+
AS_IF([test "x$man_pages_opt" = "xno"], [
668+
AC_MSG_ERROR([You need the --enable-man-pages option with the --enable-embedded-help option.])
669+
])
670+
AC_PATH_PROG([man_prog_path], [man], [no])
671+
AS_IF([test "x$man_prog_path" = "xno"], [
672+
AC_MSG_ERROR([You need man with the --enable-embedded-help option.])
673+
])
674+
AC_DEFINE_UNQUOTED([LTTNG_EMBED_HELP], 1, [Embed --help messages.])
675+
AC_SUBST([MANPROG], [$man_prog_path])
676+
])
677+
AM_CONDITIONAL([EMBED_HELP], [test "x$embedded_help" != "xno"])
678+
656679
# Python agent test
657680
UST_PYTHON_AGENT="lttngust"
658681

@@ -1186,6 +1209,9 @@ AS_IF([test "x$man_pages_opt" != "xno"], [
11861209

11871210
m4_popdef([build_man_pages_msg])
11881211

1212+
test "x$embedded_help" = xyes && value=1 || value=0
1213+
PPRINT_PROP_BOOL([Embed --help messages], $value, $PPRINT_COLOR_SUBTITLE)
1214+
11891215
PPRINT_SET_INDENT(1)
11901216

11911217
report_bindir="`eval eval echo $bindir`"

doc/man/Makefile.am

+32-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ MAN3_NO_ASCIIDOC = $(addsuffix .3,$(MAN3_NO_ASCIIDOC_NAMES))
7373
MAN8_NO_ASCIIDOC = $(addsuffix .8,$(MAN8_NO_ASCIIDOC_NAMES))
7474
MAN = $(MAN1) $(MAN3) $(MAN8)
7575

76+
# initially empty
77+
CLEANFILES =
78+
79+
if EMBED_HELP
80+
MAN1_H = $(addsuffix .1.h,$(MAN1_NAMES))
81+
MAN3_H = $(addsuffix .3.h,$(MAN3_NAMES))
82+
MAN8_H = $(addsuffix .8.h,$(MAN8_NAMES))
83+
MAN_H = $(MAN1_H) $(MAN3_H) $(MAN8_H)
84+
MAN_H_RECIPE = \
85+
MANWIDTH=80 @MANPROG@ --encoding=UTF-8 --no-hyphenation --no-justification --local-file $< > $@ ; \
86+
$(SED) -i 's/\\/\\\\/g' $@ ; \
87+
$(SED) -i 's/"/\\"/g' $@ ; \
88+
$(SED) -i 's/^\(.*\)$$/"\1\\n"/' $@
89+
90+
%.1.h: %.1
91+
$(MAN_H_RECIPE)
92+
93+
%.3.h: %.3
94+
$(MAN_H_RECIPE)
95+
96+
%.8.h: %.8
97+
$(MAN_H_RECIPE)
98+
99+
all-local: $(MAN_H)
100+
101+
CLEANFILES += $(MAN_H)
102+
endif # EMBED_HELP
103+
76104
if MAN_PAGES_OPT
77105
# at this point, we know the user asked to build the man pages
78106
if HAVE_ASCIIDOC_XMLTO
@@ -106,7 +134,7 @@ COMMON_DEPS += $(ASCIIDOC_ATTRS_CONF)
106134
$(XTO) $<
107135

108136
# only clean the generated files if we have the tools to generate them again
109-
CLEANFILES = $(MAN_XML) $(MAN)
137+
CLEANFILES += $(MAN_XML) $(MAN)
110138
else # HAVE_ASCIIDOC_XMLTO
111139
# create man page targets used to stop the build if we want to
112140
# build the man pages, but we don't have the necessary tools to do so
@@ -148,3 +176,6 @@ endif # !MAN_PAGES_OPT
148176
# always distribute the source files
149177
EXTRA_DIST = $(MAN_TXT) $(COMMON_TXT) $(XSL_SRC_FILES) \
150178
$(ASCIIDOC_CONF) $(ASCIIDOC_ATTRS_CONF).in
179+
180+
# keep generated man pages that can be considered intermediate files
181+
.PRECIOUS: %.1 %.3 %.8

src/bin/lttng-crash/Makefile.am

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
22
-DINSTALL_BIN_PATH=\""$(bindir)"\"
33

4+
if EMBED_HELP
5+
AM_CPPFLAGS += -I$(top_builddir)/doc/man
6+
endif
7+
48
bin_PROGRAMS = lttng-crash
59

610
lttng_crash_SOURCES = lttng-crash.c

src/bin/lttng-crash/lttng-crash.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, \
6262
}
6363

64+
static const char *help_msg =
65+
#ifdef LTTNG_EMBED_HELP
66+
#include <lttng-crash.1.h>
67+
#else
68+
NULL
69+
#endif
70+
;
71+
6472
/*
6573
* Non-static to ensure the compiler does not optimize away the xor.
6674
*/
@@ -207,10 +215,10 @@ static struct option long_options[] = {
207215

208216
static void usage(void)
209217
{
210-
int ret = utils_show_man_page(1, "lttng-crash");
218+
int ret = utils_show_help(1, "lttng-crash", help_msg);
211219

212220
if (ret) {
213-
ERR("Cannot view man page lttng-crash(1)");
221+
ERR("Cannot show --help for `lttng-crash`");
214222
perror("exec");
215223
exit(EXIT_FAILURE);
216224
}

src/bin/lttng-relayd/Makefile.am

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
22
-DINSTALL_BIN_PATH=\""$(lttnglibexecdir)"\" \
33
-DINSTALL_LIB_PATH=\""$(libdir)"\"
44

5+
if EMBED_HELP
6+
AM_CPPFLAGS += -I$(top_builddir)/doc/man
7+
endif
8+
59
AM_CFLAGS = -fno-strict-aliasing
610

711
bin_PROGRAMS = lttng-relayd

src/bin/lttng-relayd/main.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@
7171
#include "connection.h"
7272
#include "tracefile-array.h"
7373

74+
static const char *help_msg =
75+
#ifdef LTTNG_EMBED_HELP
76+
#include <lttng-relayd.8.h>
77+
#else
78+
NULL
79+
#endif
80+
;
81+
7482
/* command line options */
7583
char *opt_output_path;
7684
static int opt_daemon, opt_background;
@@ -250,9 +258,9 @@ static int set_option(int opt, const char *arg, const char *optname)
250258
}
251259
break;
252260
case 'h':
253-
ret = utils_show_man_page(8, "lttng-relayd");
261+
ret = utils_show_help(8, "lttng-relayd", help_msg);
254262
if (ret) {
255-
ERR("Cannot view man page lttng-relayd(8)");
263+
ERR("Cannot show --help for `lttng-relayd`");
256264
perror("exec");
257265
}
258266
exit(EXIT_FAILURE);

src/bin/lttng-sessiond/Makefile.am

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
22
-DINSTALL_BIN_PATH=\""$(lttnglibexecdir)"\" \
33
-DINSTALL_LIB_PATH=\""$(libdir)"\"
44

5+
if EMBED_HELP
6+
AM_CPPFLAGS += -I$(top_builddir)/doc/man
7+
endif
8+
59
AM_CFLAGS = -fno-strict-aliasing
610

711
bin_PROGRAMS = lttng-sessiond

src/bin/lttng-sessiond/main.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@
7979

8080
#define CONSUMERD_FILE "lttng-consumerd"
8181

82+
static const char *help_msg =
83+
#ifdef LTTNG_EMBED_HELP
84+
#include <lttng-sessiond.8.h>
85+
#else
86+
NULL
87+
#endif
88+
;
89+
8290
const char *progname;
8391
const char *tracing_group_name = DEFAULT_TRACING_GROUP;
8492
static int tracing_group_name_override;
@@ -4757,9 +4765,9 @@ static int set_option(int opt, const char *arg, const char *optname)
47574765
tracing_group_name_override = 1;
47584766
}
47594767
} else if (string_match(optname, "help") || opt == 'h') {
4760-
ret = utils_show_man_page(8, "lttng-sessiond");
4768+
ret = utils_show_help(8, "lttng-sessiond", help_msg);
47614769
if (ret) {
4762-
ERR("Cannot view man page lttng-sessiond(8)");
4770+
ERR("Cannot show --help for `lttng-sessiond`");
47634771
perror("exec");
47644772
}
47654773
exit(ret ? EXIT_FAILURE : EXIT_SUCCESS);

src/bin/lttng/Makefile.am

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
22
-DINSTALL_BIN_PATH=\""$(bindir)"\"
33

4+
if EMBED_HELP
5+
AM_CPPFLAGS += -I$(top_builddir)/doc/man
6+
endif
7+
48
AUTOMAKE_OPTIONS = subdir-objects
59

610
bin_PROGRAMS = lttng

src/bin/lttng/command.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@
2828
#define DECL_COMMAND(_name) \
2929
extern int cmd_##_name(int, const char **)
3030

31+
#ifdef LTTNG_EMBED_HELP
32+
# define HELP_MSG_NAME help_msg
33+
# define SHOW_HELP_ERROR_LINE ERR("Cannot show --help for `lttng-%s`", argv[0]);
34+
#else
35+
# define HELP_MSG_NAME NULL
36+
# define SHOW_HELP_ERROR_LINE ;
37+
#endif
38+
3139
#define SHOW_HELP() \
3240
do { \
33-
ret = show_cmd_man_page(argv[0]); \
41+
ret = show_cmd_help(argv[0], HELP_MSG_NAME); \
3442
\
3543
if (ret) { \
36-
ERR("Cannot view man page lttng-%s(1)", argv[0]); \
37-
perror("exec"); \
44+
SHOW_HELP_ERROR_LINE \
3845
ret = CMD_ERROR; \
3946
} \
4047
} while (0)

src/bin/lttng/commands/add_context.c

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ static int opt_jul;
4141
static int opt_log4j;
4242
static char *opt_type;
4343

44+
#ifdef LTTNG_EMBED_HELP
45+
static const char help_msg[] =
46+
#include <lttng-add-context.1.h>
47+
;
48+
#endif
49+
4450
enum {
4551
OPT_HELP = 1,
4652
OPT_TYPE,

src/bin/lttng/commands/create.c

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static int opt_no_output;
5151
static int opt_snapshot;
5252
static unsigned int opt_live_timer;
5353

54+
#ifdef LTTNG_EMBED_HELP
55+
static const char help_msg[] =
56+
#include <lttng-create.1.h>
57+
;
58+
#endif
59+
5460
enum {
5561
OPT_HELP = 1,
5662
OPT_LIST_OPTIONS,

src/bin/lttng/commands/destroy.c

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ static char *opt_session_name;
3535
static int opt_destroy_all;
3636
static int opt_no_wait;
3737

38+
#ifdef LTTNG_EMBED_HELP
39+
static const char help_msg[] =
40+
#include <lttng-destroy.1.h>
41+
;
42+
#endif
43+
3844
/* Mi writer */
3945
static struct mi_writer *writer;
4046

src/bin/lttng/commands/disable_channels.c

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ static int opt_kernel;
3434
static char *opt_session_name;
3535
static int opt_userspace;
3636

37+
#ifdef LTTNG_EMBED_HELP
38+
static const char help_msg[] =
39+
#include <lttng-disable-channel.1.h>
40+
;
41+
#endif
42+
3743
enum {
3844
OPT_HELP = 1,
3945
OPT_USERSPACE,

src/bin/lttng/commands/disable_events.c

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ static int opt_log4j;
4040
static int opt_python;
4141
static int opt_event_type;
4242

43+
#ifdef LTTNG_EMBED_HELP
44+
static const char help_msg[] =
45+
#include <lttng-disable-event.1.h>
46+
;
47+
#endif
48+
4349
enum {
4450
OPT_HELP = 1,
4551
OPT_TYPE_SYSCALL,

src/bin/lttng/commands/enable_channels.c

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static struct {
5151

5252
static struct mi_writer *writer;
5353

54+
#ifdef LTTNG_EMBED_HELP
55+
static const char help_msg[] =
56+
#include <lttng-enable-channel.1.h>
57+
;
58+
#endif
59+
5460
enum {
5561
OPT_HELP = 1,
5662
OPT_DISCARD,

src/bin/lttng/commands/enable_events.c

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ static char *opt_channel_name;
5555
static char *opt_filter;
5656
static char *opt_exclude;
5757

58+
#ifdef LTTNG_EMBED_HELP
59+
static const char help_msg[] =
60+
#include <lttng-enable-event.1.h>
61+
;
62+
#endif
63+
5864
enum {
5965
OPT_HELP = 1,
6066
OPT_TRACEPOINT,

src/bin/lttng/commands/help.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
#include "../command.h"
2525
#include <common/utils.h>
2626

27+
static const char *help_msg =
28+
#ifdef LTTNG_EMBED_HELP
29+
#include <lttng-help.1.h>
30+
#else
31+
NULL
32+
#endif
33+
;
34+
35+
static const char *lttng_help_msg =
36+
#ifdef LTTNG_EMBED_HELP
37+
#include <lttng.1.h>
38+
#else
39+
NULL
40+
#endif
41+
;
42+
2743
enum {
2844
OPT_HELP = 1,
2945
OPT_LIST_OPTIONS,
@@ -69,14 +85,14 @@ int cmd_help(int argc, const char **argv, const struct cmd_struct commands[])
6985

7086
if (cmd_name == NULL) {
7187
/* Fall back to lttng(1) */
72-
ret = utils_show_man_page(1, "lttng");
73-
88+
ret = utils_show_help(1, "lttng", lttng_help_msg);
7489
if (ret) {
75-
ERR("Cannot view man page lttng(1)");
90+
ERR("Cannot show --help for `lttng`");
7691
perror("exec");
7792
ret = CMD_ERROR;
78-
goto end;
7993
}
94+
95+
goto end;
8096
}
8197

8298
/* Make sure command name exists */

0 commit comments

Comments
 (0)