X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=lttng%2Fcommands%2Fcreate.c;h=4083e4195633a609ceba1ee2c28eb55d3bedff2d;hp=9fe82514097e9117ce662e4b6c2fa559fa1f4322;hb=5edd7e09e892604b00ca937c0f1bc887bb5a842c;hpb=31e43e7f5bb5143687462b08a3eef10782694577 diff --git a/lttng/commands/create.c b/lttng/commands/create.c index 9fe825140..4083e4195 100644 --- a/lttng/commands/create.c +++ b/lttng/commands/create.c @@ -65,17 +65,23 @@ static void usage(FILE *ofp) static int create_session() { int ret, have_name = 0; - char name[NAME_MAX]; + char datetime[16]; char *session_name, *traces_path = NULL, *alloc_path = NULL; time_t rawtime; struct tm *timeinfo; + /* Get date and time for automatic session name/path */ + time(&rawtime); + timeinfo = localtime(&rawtime); + strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo); + /* Auto session name creation */ if (opt_session_name == NULL) { - time(&rawtime); - timeinfo = localtime(&rawtime); - strftime(name, sizeof(name), "auto-%Y%m%d-%H%M%S", timeinfo); - session_name = name; + ret = asprintf(&session_name, "auto-%s", datetime); + if (ret < 0) { + perror("asprintf session name"); + goto error; + } DBG("Auto session name set to %s", session_name); } else { session_name = opt_session_name; @@ -92,7 +98,14 @@ static int create_session() goto error; } - ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME, alloc_path); + if (have_name) { + ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME + "/%s-%s", alloc_path, session_name, datetime); + } else { + ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME + "/%s", alloc_path, session_name); + } + if (ret < 0) { perror("asprintf trace dir name"); goto error; @@ -109,15 +122,14 @@ static int create_session() /* Init lttng session config */ ret = config_init(session_name); if (ret < 0) { + if (ret == -1) { + ret = CMD_ERROR; + } goto error; } MSG("Session %s created.", session_name); - if (have_name) { - MSG("Traces will be written in %s/%s--