X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fcreate.c;h=72702d5a54743a1d91a652ebb6707ff428f156bd;hp=b7d9af52ef4e9e51a46a97c9098411a488306f06;hb=2bba9e532ca1910822005ff7f67400a2e871467c;hpb=487b253b3ec9f187b4c1b425b246e8e74e5ac309 diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index b7d9af52e..72702d5a5 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -40,6 +40,7 @@ static char *opt_url; static char *opt_ctrl_url; static char *opt_data_url; static int opt_no_consumer; +static int opt_no_output; static int opt_disable_consumer; enum { @@ -52,10 +53,11 @@ static struct poptOption long_options[] = { {"help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL}, {"output", 'o', POPT_ARG_STRING, &opt_output_path, 0, NULL, NULL}, {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, - {"set-uri", 'U', POPT_ARG_STRING, &opt_url, 0, 0, 0}, - {"ctrl-uri", 'C', POPT_ARG_STRING, &opt_ctrl_url, 0, 0, 0}, - {"data-uri", 'D', POPT_ARG_STRING, &opt_data_url, 0, 0, 0}, - {"no-consumer", 0, POPT_ARG_VAL, &opt_no_consumer, 1, 0, 0}, + {"set-url", 'U', POPT_ARG_STRING, &opt_url, 0, 0, 0}, + {"ctrl-url", 'C', POPT_ARG_STRING, &opt_ctrl_url, 0, 0, 0}, + {"data-url", 'D', POPT_ARG_STRING, &opt_data_url, 0, 0, 0}, + {"no-output", 0, POPT_ARG_VAL, &opt_no_output, 1, 0, 0}, + {"no-consumer", 0, POPT_ARG_VAL, &opt_no_consumer, 1, 0, 0}, {"disable-consumer", 0, POPT_ARG_VAL, &opt_disable_consumer, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0} }; @@ -80,6 +82,7 @@ static void usage(FILE *ofp) fprintf(ofp, " -h, --help Show this help\n"); fprintf(ofp, " --list-options Simple listing of options\n"); fprintf(ofp, " -o, --output PATH Specify output path for traces\n"); + fprintf(ofp, " --no-output Traces will not be outputed\n"); fprintf(ofp, "\n"); fprintf(ofp, "Extended Options:\n"); fprintf(ofp, "\n"); @@ -91,11 +94,6 @@ static void usage(FILE *ofp) fprintf(ofp, " You can change it with the enable-consumer cmd\n"); fprintf(ofp, " -C, --ctrl-url=URL Set control path URL. (Must use -D also)\n"); fprintf(ofp, " -D, --data-url=URL Set data path URL. (Must use -C also)\n"); - fprintf(ofp, " --no-consumer Don't activate a consumer for this session.\n"); - fprintf(ofp, " OBSELETE\n"); - fprintf(ofp, " --disable-consumer\n"); - fprintf(ofp, " Disable consumer for this session.\n"); - fprintf(ofp, " OBSELETE\n"); fprintf(ofp, "\n"); fprintf(ofp, "Please refer to the man page (lttng(1)) for more information on network\n"); fprintf(ofp, "streaming mechanisms and explanation of the control and data port\n"); @@ -209,9 +207,16 @@ static int create_session(void) ret = LTTNG_ERR_SESSION_FAIL; goto error; } - if (strncmp(opt_session_name, DEFAULT_SESSION_NAME, + /* + * Check if the session name begins with "auto-" or is exactly "auto". + * Both are reserved for the default session name. See bug #449 to + * understand why we need to check both here. + */ + if ((strncmp(opt_session_name, DEFAULT_SESSION_NAME "-", + strlen(DEFAULT_SESSION_NAME) + 1) == 0) || + (strncmp(opt_session_name, DEFAULT_SESSION_NAME, strlen(DEFAULT_SESSION_NAME)) == 0 && - strlen(opt_session_name) == strlen(DEFAULT_SESSION_NAME)) { + strlen(opt_session_name) == strlen(DEFAULT_SESSION_NAME))) { ERR("%s is a reserved keyword for default session(s)", DEFAULT_SESSION_NAME); ret = CMD_ERROR; @@ -246,9 +251,9 @@ static int create_session(void) } else if (opt_url) { /* Handling URL (-U opt) */ url = opt_url; print_str_url = url; - } else if (opt_ctrl_url == NULL && opt_data_url == NULL) { + } else if (!opt_no_output) { /* Auto output path */ - alloc_path = config_get_default_path(); + alloc_path = utils_get_home_dir(); if (alloc_path == NULL) { ERR("HOME path not found.\n \ Please specify an output path using -o, --output PATH"); @@ -267,10 +272,19 @@ static int create_session(void) } url = alloc_url; - print_str_url = alloc_url + strlen("file://"); + if (!opt_data_url && !opt_ctrl_url) { + print_str_url = alloc_url + strlen("file://"); + } + } else { + /* No output means --no-output. */ + url = NULL; } - assert(url); + if ((!opt_ctrl_url && opt_data_url) || (opt_ctrl_url && !opt_data_url)) { + ERR("You need both control and data URL."); + ret = CMD_ERROR; + goto error; + } ret = _lttng_create_session_ext(session_name, url, datetime); if (ret < 0) { @@ -279,26 +293,25 @@ static int create_session(void) case LTTNG_ERR_EXIST_SESS: WARN("Session %s already exists", session_name); break; + default: + break; } goto error; } - MSG("Session %s created.", session_name); - if (print_str_url) { - MSG("Traces will be written in %s", print_str_url); - } - if (opt_ctrl_url && opt_data_url) { /* Setting up control URI (-C or/and -D opt) */ ret = set_consumer_url(session_name, opt_ctrl_url, opt_data_url); if (ret < 0) { + /* Destroy created session because the URL are not valid. */ + lttng_destroy_session(session_name); goto error; } - } else if ((!opt_ctrl_url && opt_data_url) || - (opt_ctrl_url && !opt_data_url)) { - ERR("You need both control and data URL."); - ret = CMD_ERROR; - goto error; + } + + MSG("Session %s created.", session_name); + if (print_str_url) { + MSG("Traces will be written in %s", print_str_url); } /* Init lttng session config */ @@ -308,7 +321,6 @@ static int create_session(void) goto error; } - ret = CMD_SUCCESS; error: @@ -351,7 +363,7 @@ int cmd_create(int argc, const char **argv) } if (opt_no_consumer) { - MSG("The option --no-consumer is obsolete."); + MSG("The option --no-consumer is obsolete. Use --no-output now."); ret = CMD_WARNING; goto end; }