From: Simon Marchi Date: Wed, 17 Jun 2015 18:39:51 +0000 (-0400) Subject: Use utils_parse_time_suffix in create and enable-channel command X-Git-Tag: v2.11.0-rc1~336 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c72196171a55e7cabeebe19d68352452e2bf6b25;p=lttng-tools.git Use utils_parse_time_suffix in create and enable-channel command Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index faf9f3e0d..60ca1f5d4 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -49,7 +49,7 @@ 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[] = @@ -641,7 +641,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); @@ -653,22 +653,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; diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 214c8a362..3314bde0d 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -493,16 +493,17 @@ int cmd_enable_channels(int argc, const char **argv) } case OPT_SWITCH_TIMER: { - unsigned long v; + uint64_t v; errno = 0; opt_arg = poptGetOptArg(pc); - v = strtoul(opt_arg, NULL, 0); - if (errno != 0 || !isdigit(opt_arg[0])) { - ERR("Wrong value in --switch-timer parameter: %s", opt_arg); + + if (utils_parse_time_suffix(opt_arg, &v) < 0) { + ERR("Wrong value for --switch-timer parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } + if (v != (uint32_t) v) { ERR("32-bit overflow in --switch-timer parameter: %s", opt_arg); ret = CMD_ERROR; @@ -514,16 +515,17 @@ int cmd_enable_channels(int argc, const char **argv) } case OPT_READ_TIMER: { - unsigned long v; + uint64_t v; errno = 0; opt_arg = poptGetOptArg(pc); - v = strtoul(opt_arg, NULL, 0); - if (errno != 0 || !isdigit(opt_arg[0])) { - ERR("Wrong value in --read-timer parameter: %s", opt_arg); + + if (utils_parse_time_suffix(opt_arg, &v) < 0) { + ERR("Wrong value for --read-timer parameter: %s", opt_arg); ret = CMD_ERROR; goto end; } + if (v != (uint32_t) v) { ERR("32-bit overflow in --read-timer parameter: %s", opt_arg); ret = CMD_ERROR;