X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fcreate.c;h=5588d4267bae2d304facb6ea73866f175f46e2e8;hp=3e7074e02bc0e35f611fb2e9347342159a7234d2;hb=785d2d0dc3aec3a4e44fcf677155dd07e8e4cc1f;hpb=a4b92340642035d1eafeb1eead0ad01f64d2007d diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index 3e7074e02..5588d4267 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -60,6 +60,13 @@ static struct poptOption long_options[] = { {0, 0, 0, 0, 0, 0, 0} }; +/* + * Please have a look at src/lib/lttng-ctl/lttng-ctl.c for more information on + * why this declaration exists and used ONLY in for this command. + */ +extern int _lttng_create_session_ext(const char *name, const char *url, + const char *datetime); + /* * usage */ @@ -85,8 +92,10 @@ static void usage(FILE *ofp) 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"); @@ -100,12 +109,12 @@ static void usage(FILE *ofp) fprintf(ofp, " > file://...\n"); fprintf(ofp, " Local filesystem full path.\n"); fprintf(ofp, "\n"); - fprintf(ofp, " > net[4|6]://...\n"); + fprintf(ofp, " > net[6]://...\n"); fprintf(ofp, " This will use the default network transport layer which is\n"); fprintf(ofp, " TCP for both control (PORT1) and data port (PORT2).\n"); fprintf(ofp, " The default ports are respectively 5342 and 5343.\n"); fprintf(ofp, "\n"); - fprintf(ofp, " > tcp[4|6]://...\n"); + fprintf(ofp, " > tcp[6]://...\n"); fprintf(ofp, " Can only be used with -C and -D together\n"); fprintf(ofp, "\n"); fprintf(ofp, "NOTE: IPv6 address MUST be enclosed in brackets '[]' (rfc2732)\n"); @@ -163,79 +172,6 @@ error: return ret; } -/* - * For a session name, enable the consumer. - */ -static int enable_consumer(const char *session_name) -{ - int ret; - struct lttng_handle *handle; - struct lttng_domain dom; - - assert(session_name); - - /* - * Set handle with the session name and the domain set to 0. This means to - * the session daemon that the next action applies on the tracing session - * rather then the domain specific session. - * - * XXX: This '0' value should be a domain enum value. - */ - memset(&dom, 0, sizeof(dom)); - - handle = lttng_create_handle(session_name, 0); - if (handle == NULL) { - ret = CMD_FATAL; - goto error; - } - - ret = lttng_enable_consumer(handle); - if (ret < 0) { - goto error; - } - - MSG("Consumer enabled for session %s", session_name); - -error: - lttng_destroy_handle(handle); - return ret; -} - -/* - * For a session name, disable the consumer. - */ -static int disable_consumer(const char *session_name) -{ - int ret; - struct lttng_handle *handle; - - assert(session_name); - - /* - * Set handle with the session name and the domain set to 0. This means to - * the session daemon that the next action applies on the tracing session - * rather then the domain specific session. - * - * XXX: This '0' value should be a domain enum value. - */ - handle = lttng_create_handle(session_name, 0); - if (handle == NULL) { - ret = CMD_FATAL; - goto error; - } - - ret = lttng_disable_consumer(handle); - if (ret < 0) { - goto error; - } - free(handle); - - MSG("Consumer disabled for session %s", session_name); - -error: - return ret; -} - /* * Create a tracing session. * If no name is specified, a default name is generated. @@ -245,8 +181,9 @@ error: static int create_session(void) { int ret; - char *session_name, *traces_path = NULL, *alloc_path = NULL; + char *session_name = NULL, *traces_path = NULL, *alloc_path = NULL; char *alloc_url = NULL, *url = NULL, datetime[16]; + char session_name_date[NAME_MAX], *print_str_url = NULL; time_t rawtime; struct tm *timeinfo; @@ -257,19 +194,33 @@ static int create_session(void) /* Auto session name creation */ if (opt_session_name == NULL) { - ret = asprintf(&session_name, DEFAULT_SESSION_NAME "%s", datetime); + ret = snprintf(session_name_date, sizeof(session_name_date), + DEFAULT_SESSION_NAME "-%s", datetime); if (ret < 0) { - PERROR("asprintf session name"); + PERROR("snprintf session name"); goto error; } - DBG("Auto session name set to %s", session_name); + session_name = session_name_date; + DBG("Auto session name set to %s", session_name_date); } else { + if (strncmp(opt_session_name, DEFAULT_SESSION_NAME, + strlen(DEFAULT_SESSION_NAME)) == 0 && + strlen(opt_session_name) == strlen(DEFAULT_SESSION_NAME)) { + ERR("%s is a reserved keyword for default session(s)", + DEFAULT_SESSION_NAME); + ret = CMD_ERROR; + goto error; + } session_name = opt_session_name; + ret = snprintf(session_name_date, sizeof(session_name_date), + "%s-%s", session_name, datetime); + if (ret < 0) { + PERROR("snprintf session name"); + goto error; + } } - if (opt_no_consumer) { - url = NULL; - } else if (opt_output_path != NULL) { + if (opt_output_path != NULL) { traces_path = utils_expand_path(opt_output_path); if (traces_path == NULL) { ret = CMD_ERROR; @@ -285,10 +236,10 @@ static int create_session(void) } /* URL to use in the lttng_create_session() call */ url = alloc_url; - MSG("Trace(s) output set to %s", traces_path); + print_str_url = traces_path; } else if (opt_url) { /* Handling URL (-U opt) */ url = opt_url; - MSG("Trace(s) output set to %s", url); + print_str_url = url; } else if (opt_ctrl_url == NULL && opt_data_url == NULL) { /* Auto output path */ alloc_path = config_get_default_path(); @@ -300,8 +251,9 @@ static int create_session(void) } alloc_path = strdup(alloc_path); - ret = asprintf(&alloc_url, "file://%s/" DEFAULT_TRACE_DIR_NAME, - alloc_path); + ret = asprintf(&alloc_url, + "file://%s/" DEFAULT_TRACE_DIR_NAME "/%s", + alloc_path, session_name_date); if (ret < 0) { PERROR("asprintf trace dir name"); ret = CMD_FATAL; @@ -309,44 +261,38 @@ static int create_session(void) } url = alloc_url; - MSG("Trace(s) output set to %s", alloc_url + strlen("file://")); + print_str_url = alloc_url + strlen("file://"); } - ret = lttng_create_session(session_name, url); + assert(url); + + ret = _lttng_create_session_ext(session_name, url, datetime); if (ret < 0) { /* Don't set ret so lttng can interpret the sessiond error. */ switch (-ret) { - case LTTCOMM_EXIST_SESS: + case LTTNG_ERR_EXIST_SESS: WARN("Session %s already exists", session_name); break; } goto error; } - if (opt_session_name == NULL) { - MSG("Session created with default name %s", session_name); - } else { - MSG("Session %s created.", session_name); + 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) { + 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) { goto error; } - - ret = enable_consumer(session_name); - if (ret < 0) { - goto error; - } - } - - if (opt_disable_consumer && !opt_no_consumer) { - ret = disable_consumer(session_name); - if (ret < 0) { - 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; } /* Init lttng session config */ @@ -356,20 +302,13 @@ static int create_session(void) goto error; } + ret = CMD_SUCCESS; error: - if (opt_session_name == NULL) { - free(session_name); - } - - if (alloc_url) { - free(alloc_url); - } - - if (traces_path) { - free(traces_path); - } + free(alloc_url); + free(traces_path); + free(alloc_path); if (ret < 0) { ERR("%s", lttng_strerror(ret)); @@ -405,6 +344,18 @@ int cmd_create(int argc, const char **argv) } } + if (opt_no_consumer) { + MSG("The option --no-consumer is obsolete."); + ret = CMD_WARNING; + goto end; + } + + if (opt_disable_consumer) { + MSG("The option --disable-consumer is obsolete."); + ret = CMD_WARNING; + goto end; + } + opt_session_name = (char*) poptGetArg(pc); ret = create_session();