X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fcreate.c;h=2778ef553cdd2a24c27567f780be0b1c950678c6;hp=9dc3752244616c122683416f4d9ee7af5945d33b;hb=3badf2bf32930336a4902002d840402adb6859e1;hpb=1c8d13c8a4111fcfd4cc00c335d47506ab98bb33 diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index 9dc375224..2778ef553 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -1,19 +1,18 @@ /* * Copyright (C) 2011 - David Goulet * - * 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; only version 2 - * of the License. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2 only, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _GNU_SOURCE @@ -29,6 +28,8 @@ #include "../command.h" #include "../utils.h" +#include + static char *opt_output_path; static char *opt_session_name; @@ -114,20 +115,28 @@ static int create_session() goto error; } } else { - traces_path = opt_output_path; + traces_path = expand_full_path(opt_output_path); + if (traces_path == NULL) { + ret = CMD_ERROR; + goto error; + } } ret = lttng_create_session(session_name, traces_path); if (ret < 0) { + /* Don't set ret so lttng can interpret the sessiond error. */ + switch (-ret) { + case LTTCOMM_EXIST_SESS: + WARN("Session %s already exists", session_name); + break; + } goto error; } /* Init lttng session config */ ret = config_init(session_name); if (ret < 0) { - if (ret == -1) { - ret = CMD_ERROR; - } + ret = CMD_ERROR; goto error; } @@ -137,6 +146,10 @@ static int create_session() ret = CMD_SUCCESS; error: + if (opt_session_name == NULL) { + free(session_name); + } + if (alloc_path) { free(alloc_path); } @@ -163,11 +176,10 @@ int cmd_create(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); + usage(stdout); goto end; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); - ret = CMD_SUCCESS; goto end; default: usage(stderr); @@ -181,5 +193,6 @@ int cmd_create(int argc, const char **argv) ret = create_session(); end: + poptFreeContext(pc); return ret; }