X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fcreate.c;h=08b12a46eee2b95e6093f738a97a5b0f01936551;hb=94e60b1f03ae2c3c9450ffc3eca8e052e2c37fb4;hp=dd10ab22767b8718ef232f4c19656e758b79c9bf;hpb=07424f161f4afbd07fd165e4ae492726e1de7769;p=lttng-tools.git diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index dd10ab227..08b12a46e 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -60,7 +60,10 @@ static struct poptOption long_options[] = { {0, 0, 0, 0, 0, 0, 0} }; -/* HACK */ +/* + * 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); @@ -104,7 +107,7 @@ 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"); @@ -251,7 +254,7 @@ static int create_session(void) int ret; char *session_name = NULL, *traces_path = NULL, *alloc_path = NULL; char *alloc_url = NULL, *url = NULL, datetime[16]; - char session_name_date[NAME_MAX]; + char session_name_date[NAME_MAX], *print_str_url = NULL; time_t rawtime; struct tm *timeinfo; @@ -268,13 +271,17 @@ static int create_session(void) PERROR("snprintf session name"); goto error; } - session_name = strdup(DEFAULT_SESSION_NAME); - if (session_name == NULL) { - PERROR("strdup session name"); - goto error; - } + 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); @@ -286,6 +293,7 @@ static int create_session(void) if (opt_no_consumer) { url = NULL; + print_str_url = ""; } else if (opt_output_path != NULL) { traces_path = utils_expand_path(opt_output_path); if (traces_path == NULL) { @@ -302,10 +310,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(); @@ -327,25 +335,22 @@ 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_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_date); - } else { - MSG("Session %s created.", session_name); - } + MSG("Session %s created.", session_name); + 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) */ @@ -367,11 +372,6 @@ static int create_session(void) } } - if (opt_session_name == NULL) { - free(session_name); - session_name = session_name_date; - } - /* Init lttng session config */ ret = config_init(session_name); if (ret < 0) { @@ -383,10 +383,6 @@ static int create_session(void) ret = CMD_SUCCESS; error: - if (opt_session_name == NULL && session_name != session_name_date) { - free(session_name); - } - if (alloc_url) { free(alloc_url); } @@ -394,6 +390,7 @@ error: if (traces_path) { free(traces_path); } + free(alloc_path); if (ret < 0) { ERR("%s", lttng_strerror(ret));