X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttng%2Fcommands%2Fadd_context.c;h=02220415d88d5c17e186dfef123be903115b6c93;hb=5450ed5091dd727e58b412b6b9a6cb94ae74b609;hp=619f7c9aca2af41a36da6bab95aa716810a31267;hpb=cd80958d00fddabced5fbd60641978516a01e29e;p=lttng-tools.git diff --git a/lttng/commands/add_context.c b/lttng/commands/add_context.c index 619f7c9ac..02220415d 100644 --- a/lttng/commands/add_context.c +++ b/lttng/commands/add_context.c @@ -40,11 +40,14 @@ static char *opt_session_name; static int *opt_kernel; static int opt_pid_all; static int opt_userspace; +static char *opt_cmd_name; static pid_t opt_pid; +static char *opt_type; enum { OPT_HELP = 1, OPT_TYPE, + OPT_USERSPACE, }; static struct lttng_handle *handle; @@ -138,10 +141,10 @@ static struct poptOption long_options[] = { {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, {"event", 'e', POPT_ARG_STRING, &opt_event_name, 0, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, - {"userspace", 'u', POPT_ARG_VAL, &opt_userspace, 1, 0, 0}, + {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0}, {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0}, {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, - {"type", 't', POPT_ARG_STRING, 0, OPT_TYPE, 0, 0}, + {"type", 't', POPT_ARG_STRING, &opt_type, OPT_TYPE, 0, 0}, {0, 0, 0, 0, 0, 0, 0} }; @@ -383,7 +386,7 @@ static int add_context(char *session_name) opt_channel_name); if (ret < 0) { fprintf(stderr, "%s: ", type->opt->symbol); - goto error; + continue; } else { MSG("Kernel context %s added", type->opt->symbol); } @@ -414,7 +417,6 @@ error: int cmd_add_context(int argc, const char **argv) { int index, opt, ret = CMD_SUCCESS; - char *tmp; static poptContext pc; struct ctx_type *type, *tmptype; char *session_name = NULL; @@ -434,32 +436,27 @@ int cmd_add_context(int argc, const char **argv) ret = CMD_SUCCESS; goto end; case OPT_TYPE: - /* Mandatory field */ - tmp = poptGetOptArg(pc); - if (tmp == NULL) { - usage(stderr); - ret = CMD_ERROR; - free(tmp); - goto end; - } type = malloc(sizeof(struct ctx_type)); if (type == NULL) { perror("malloc ctx_type"); ret = -1; goto end; } - index = find_ctx_type_idx(tmp); + index = find_ctx_type_idx(opt_type); if (index < 0) { - ERR("Unknown context type %s", tmp); + ERR("Unknown context type %s", opt_type); goto end; } type->opt = &ctx_opts[index]; if (type->opt->ctx_type == -1) { - ERR("Unknown context type %s", tmp); + ERR("Unknown context type %s", opt_type); } else { cds_list_add(&type->list, &ctx_type_list.head); } - free(tmp); + break; + case OPT_USERSPACE: + opt_userspace = 1; + opt_cmd_name = poptGetOptArg(pc); break; default: usage(stderr);