X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttng%2Fcommands%2Fcreate.c;h=9fe82514097e9117ce662e4b6c2fa559fa1f4322;hb=f40799e8d49a5e8161084fa98023f3e571b51962;hp=522ebc9c3aa3a6a3eff33015aa06d33dd3a95da6;hpb=f3ed775ef4842019b396f06095b053c3a70bc3c8;p=lttng-tools.git diff --git a/lttng/commands/create.c b/lttng/commands/create.c index 522ebc9c3..9fe825140 100644 --- a/lttng/commands/create.c +++ b/lttng/commands/create.c @@ -3,8 +3,8 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * as published by the Free Software Foundation; only version 2 + * of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -26,8 +26,9 @@ #include #include -#include "cmd.h" -#include "config.h" +#include "../cmd.h" +#include "../conf.h" +#include "../utils.h" static char *opt_output_path; static char *opt_session_name; @@ -51,7 +52,7 @@ static void usage(FILE *ofp) fprintf(ofp, "usage: lttng create [options] [NAME]\n"); fprintf(ofp, "\n"); fprintf(ofp, " -h, --help Show this help\n"); - fprintf(ofp, " -o, --output PATH Specify output path\n"); + fprintf(ofp, " -o, --output PATH Specify output path for traces\n"); fprintf(ofp, "\n"); } @@ -63,9 +64,9 @@ static void usage(FILE *ofp) */ static int create_session() { - int ret; + int ret, have_name = 0; char name[NAME_MAX]; - char *session_name, *path = NULL, *alloc_path; + char *session_name, *traces_path = NULL, *alloc_path = NULL; time_t rawtime; struct tm *timeinfo; @@ -78,43 +79,45 @@ static int create_session() DBG("Auto session name set to %s", session_name); } else { session_name = opt_session_name; + have_name = 1; } /* Auto output path */ if (opt_output_path == NULL) { - alloc_path = config_get_default_path(); + alloc_path = strdup(config_get_default_path()); if (alloc_path == NULL) { + ERR("Home path not found.\n \ + Please specify an output path using -o, --output PATH"); ret = CMD_FATAL; goto error; } - } else { - alloc_path = opt_output_path; - } - path = config_generate_dir_path(alloc_path); - if (path == NULL) { - ret = CMD_FATAL; - goto error; - } - - /* Init lttng session config */ - ret = config_init(path); - if (ret < 0) { - goto error; + ret = asprintf(&traces_path, "%s/" LTTNG_DEFAULT_TRACE_DIR_NAME, alloc_path); + if (ret < 0) { + perror("asprintf trace dir name"); + goto error; + } + } else { + traces_path = opt_output_path; } - ret = config_add_session_name(path, session_name); + ret = lttng_create_session(session_name, traces_path); if (ret < 0) { goto error; } - ret = lttng_create_session(session_name, path); + /* Init lttng session config */ + ret = config_init(session_name); if (ret < 0) { goto error; } MSG("Session %s created.", session_name); - MSG("Working directory of created session is %s", path); + if (have_name) { + MSG("Traces will be written in %s/%s--