X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fcreate.c;h=d3e5b9a84106f84fbde44c50eb8376bcd8faae94;hb=5b89fc92cbb5a2a9d1fd2994edebb0453584f87c;hp=3379a3b27b8638a3f3455af6cc4b0dca981a90b5;hpb=95681498599cbd3bc1aa6dfa725a668ab272170b;p=lttng-tools.git diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index 3379a3b27..d3e5b9a84 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -49,7 +49,13 @@ static char *opt_shm_path; static int opt_no_consumer; static int opt_no_output; static int opt_snapshot; -static unsigned int opt_live_timer; +static uint32_t opt_live_timer; + +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif enum { OPT_HELP = 1, @@ -342,6 +348,10 @@ static int create_session(void) /* Use default live URL if NO url is/are found. */ if ((opt_live_timer && !opt_url) && (opt_live_timer && !opt_data_url)) { + /* Override the url */ + free(url); + url = NULL; + ret = asprintf(&alloc_url, "net://127.0.0.1"); if (ret < 0) { PERROR("asprintf default live URL"); @@ -432,14 +442,14 @@ static int create_session(void) MSG("Traces will be written in %s", print_str_url); if (opt_live_timer) { - MSG("Live timer set to %u usec", opt_live_timer); + MSG("Live timer set to %u %s", opt_live_timer, USEC_UNIT); } } else if (opt_snapshot) { if (print_str_url) { MSG("Default snapshot output set to: %s", print_str_url); } MSG("Snapshot mode set. Every channel enabled for that session will " - "be set in overwrite mode and mmap output."); + "be set to mmap output, and default to overwrite mode."); } if (opt_shm_path) { MSG("Session %s set to shm_path: %s.", session_name, @@ -606,6 +616,22 @@ end: return ret; } +int validate_url_option_combination(void) +{ + int ret = 0; + int used_count = 0; + + used_count += !!opt_url; + used_count += !!opt_output_path; + used_count += (opt_data_url || opt_ctrl_url); + if (used_count > 1) { + ERR("Only one of the --set-url, --ctrl-url/data-url, or --output options may be used at once."); + ret = -1; + } + + return ret; +} + /* * The 'create ' first level command * @@ -615,6 +641,7 @@ int cmd_create(int argc, const char **argv) { int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1; char *opt_arg = NULL; + const char *leftover = NULL; static poptContext pc; pc = poptGetContext(NULL, argc, argv, long_options, 0); @@ -630,7 +657,7 @@ int cmd_create(int argc, const char **argv) goto end; case OPT_LIVE_TIMER: { - unsigned long v; + uint64_t v; errno = 0; opt_arg = poptGetOptArg(pc); @@ -642,22 +669,24 @@ int cmd_create(int argc, const char **argv) break; } - v = strtoul(opt_arg, NULL, 0); - if (errno != 0 || !isdigit(opt_arg[0])) { - ERR("Wrong value in --live parameter: %s", opt_arg); + if (utils_parse_time_suffix(opt_arg, &v) < 0) { + ERR("Wrong value for --live parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } + if (v != (uint32_t) v) { ERR("32-bit overflow in --live parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } + if (v == 0) { ERR("Live timer interval must be greater than zero"); ret = CMD_ERROR; goto end; } + opt_live_timer = (uint32_t) v; DBG("Session live timer interval set to %d", opt_live_timer); break; @@ -674,6 +703,12 @@ int cmd_create(int argc, const char **argv) goto end; } + ret = validate_url_option_combination(); + if (ret) { + ret = CMD_ERROR; + goto end; + } + /* Spawn a session daemon if needed */ if (!opt_no_sessiond) { ret = launch_sessiond(); @@ -709,6 +744,13 @@ int cmd_create(int argc, const char **argv) } opt_session_name = (char*) poptGetArg(pc); + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + command_ret = create_session(); if (command_ret) { success = 0;