X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Ftrack-untrack.c;h=3771de5d94b5b7bfcaacf26b0663044cecaac98f;hp=bb3fc551b1e30c6b86e782004163a695e7bbda5b;hb=38b4ef1b199ddb15db78774a39e9c524ca7e2d24;hpb=669d25b6d224253699e8521fbd7f50d3187b238e diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index bb3fc551b..3771de5d9 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -16,7 +16,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -26,6 +25,7 @@ #include #include #include +#include #include @@ -64,28 +64,6 @@ static struct poptOption long_options[] = { { 0, 0, 0, 0, 0, 0, 0, }, }; -/* - * usage - */ -static void usage(FILE *ofp, const char *cmd_str) -{ - fprintf(ofp, "usage: lttng %s [-k|-u] [OPTIONS]\n", cmd_str); - fprintf(ofp, "\n"); - fprintf(ofp, "If no session is given (-s), the context is added to\n"); - fprintf(ofp, "the current sesssion. Exactly one domain (-k or -u)\n"); - fprintf(ofp, "must be specified.\n"); - fprintf(ofp, "\n"); - fprintf(ofp, "Options:\n"); - fprintf(ofp, " -h, --help Show this help.\n"); - fprintf(ofp, " --list-options Simple listing of options.\n"); - fprintf(ofp, " -s, --session NAME Apply to session name.\n"); - fprintf(ofp, " -k, --kernel Apply to the kernel tracer.\n"); - fprintf(ofp, " -u, --userspace Apply to the user-space tracer.\n"); - fprintf(ofp, " -p, --pid [PID] Process ID tracker. Leave PID empty when used with --all.\n"); - fprintf(ofp, " -a, --all All PIDs (use with --pid).\n"); - fprintf(ofp, "\n"); -} - static int parse_pid_string(const char *_pid_string, int all, int **_pid_list, int *nr_pids) @@ -229,15 +207,13 @@ enum cmd_error_code track_untrack_pid(enum cmd_type cmd_type, const char *cmd_st } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto end; + /* Checked by the caller. */ + assert(0); } ret = parse_pid_string(pid_string, all, &pid_list, &nr_pids); if (ret != CMD_SUCCESS) { ERR("Error parsing PID string"); - usage(stderr, cmd_str); retval = CMD_ERROR; goto end; } @@ -354,7 +330,6 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, struct mi_writer *writer = NULL; if (argc < 1) { - usage(stderr, cmd_str); command_ret = CMD_ERROR; goto end; } @@ -365,7 +340,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); @@ -375,16 +350,14 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, opt_pid = 1; break; default: - usage(stderr, cmd_str); command_ret = CMD_UNDEFINED; goto end; } } - if (!(opt_userspace ^ opt_kernel)) { - ERR("Exactly one of -u or -k needs to be specified."); - usage(stderr, cmd_str); - command_ret = CMD_ERROR; + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); + if (ret) { + ret = CMD_ERROR; goto end; } @@ -401,7 +374,6 @@ int cmd_track_untrack(enum cmd_type cmd_type, const char *cmd_str, /* Currently only PID tracker is supported */ if (!opt_pid) { ERR("Please specify at least one tracker with its expected arguments"); - usage(stderr, cmd_str); command_ret = CMD_ERROR; goto end; }