#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,
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
- usage(stdout);
+ SHOW_HELP();
goto end;
case OPT_LIST:
print_ctx_type(stdout);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
- usage(stdout);
+ SHOW_HELP();
goto end;
case OPT_TRACEPOINT:
ret = CMD_UNDEFINED;
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);
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);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
- usage(stdout);
+ SHOW_HELP();
goto end;
case OPT_USERSPACE:
opt_userspace = 1;
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;
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
- usage(stdout);
+ SHOW_HELP();
goto end;
case OPT_DISCARD:
chan.attr.overwrite = 0;
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;
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
- usage(stdout);
+ SHOW_HELP();
goto end;
case OPT_USERSPACE:
opt_userspace = 1;
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
- usage(stdout);
+ SHOW_HELP();
goto end;
case OPT_ALL:
opt_load_all = 1;
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case OPT_HELP:
- usage(stdout);
+ SHOW_HELP();
goto end;
case OPT_ALL:
opt_save_all = 1;
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);
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);
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);
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);
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);
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);
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);
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);
#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"
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);
+}
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 */
-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
/* 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"
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;
+}
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 */