X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttng%2Fcommands%2Fcreate.c;h=3ed9ba0634552e8c7a81c90b8c6e9000f5e3c8cd;hb=7d29a2477524f7ee2ee46a94e538e6141f5ecc0e;hp=941f72355426e792987442134061d7569e52cbb3;hpb=beb8c75afd91bc32f2e7a9c124c9a21ecffd1486;p=lttng-tools.git diff --git a/lttng/commands/create.c b/lttng/commands/create.c index 941f72355..3ed9ba063 100644 --- a/lttng/commands/create.c +++ b/lttng/commands/create.c @@ -28,6 +28,7 @@ #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"); } @@ -65,7 +66,7 @@ static int create_session() { int ret; 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; @@ -82,39 +83,36 @@ static int create_session() /* 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); + MSG("Traces will be written in %s/%s--