int create_session(char *name, char *path)
{
int ret;
- char date_time[NAME_MAX];
struct ltt_session *new_session;
- time_t rawtime;
- struct tm *timeinfo;
new_session = find_session_by_name(name);
if (new_session != NULL) {
/* Define session system path */
if (path != NULL) {
- if (strstr(name, "auto-") == NULL) {
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- strftime(date_time, sizeof(date_time), "-%Y%m%d-%H%M%S", timeinfo);
- } else {
- date_time[0] = '\0';
- }
-
- if (asprintf(&new_session->path, "%s/%s%s", path, name, date_time) < 0) {
+ if (asprintf(&new_session->path, "%s", path) < 0) {
ret = -ENOMEM;
goto error_asprintf;
}
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;
goto error;
}
- ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME, alloc_path);
+ ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME
+ "/%s-%s", alloc_path, session_name, datetime);
if (ret < 0) {
perror("asprintf trace dir name");
goto error;
MSG("Session %s created.", session_name);
if (have_name) {
- MSG("Traces will be written in %s/%s-<date>-<time>" , traces_path, session_name);
+ MSG("Traces will be written in %s" , traces_path);
} else {
MSG("Traces will be written in %s/%s", traces_path, session_name);
}