From a8f307d87d2d308671df9fed0855f4344c60d335 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 13 Aug 2013 14:22:31 -0400 Subject: [PATCH] Use parse_size_suffix in snapshot Signed-off-by: Simon Marchi Signed-off-by: David Goulet --- doc/man/lttng.1 | 5 +++-- src/bin/lttng/commands/snapshot.c | 19 +++++-------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/doc/man/lttng.1 b/doc/man/lttng.1 index 0a74f9c50..57c89f0fa 100644 --- a/doc/man/lttng.1 +++ b/doc/man/lttng.1 @@ -761,8 +761,9 @@ Apply to session name. Name of the snapshot's output. .TP .BR "\-m, \-\-max-size SIZE" -Maximum size in bytes of the snapshot. The maxium size does not include -the metadata file. +Maximum size in bytes of the snapshot. The maxium size does not include the +metadata file. Human readable format is accepted: {+k,+M,+G}. For instance, +\-\-max-size 5M .TP .BR "\-C, \-\-ctrl-url URL" Set control path URL. (Must use -D also) diff --git a/src/bin/lttng/commands/snapshot.c b/src/bin/lttng/commands/snapshot.c index 56acca866..dd1137baa 100644 --- a/src/bin/lttng/commands/snapshot.c +++ b/src/bin/lttng/commands/snapshot.c @@ -26,6 +26,7 @@ #include #include +#include #include #include "../command.h" @@ -58,7 +59,7 @@ static struct poptOption snapshot_opts[] = { {"ctrl-url", 'C', POPT_ARG_STRING, &opt_ctrl_url, 0, 0, 0}, {"data-url", 'D', POPT_ARG_STRING, &opt_data_url, 0, 0, 0}, {"name", 'n', POPT_ARG_STRING, &opt_output_name, 0, 0, 0}, - {"max-size", 'm', POPT_ARG_DOUBLE, 0, OPT_MAX_SIZE, 0, 0}, + {"max-size", 'm', POPT_ARG_STRING, 0, OPT_MAX_SIZE, 0, 0}, {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, {0, 0, 0, 0, 0, 0, 0} }; @@ -100,7 +101,7 @@ static void usage(FILE *ofp) fprintf(ofp, " --list-options Simple listing of options\n"); fprintf(ofp, " -s, --session NAME Apply to session name\n"); fprintf(ofp, " -n, --name NAME Name of the output or snapshot\n"); - fprintf(ofp, " -m, --max-size SIZE Maximum bytes size of the snapshot\n"); + fprintf(ofp, " -m, --max-size SIZE Maximum bytes size of the snapshot {+k,+M,+G}\n"); fprintf(ofp, " -C, --ctrl-url URL Set control path URL. (Must use -D also)\n"); fprintf(ofp, " -D, --data-url URL Set data path URL. (Must use -C also)\n"); fprintf(ofp, "\n"); @@ -441,25 +442,15 @@ int cmd_snapshot(int argc, const char **argv) goto end; case OPT_MAX_SIZE: { - long long int val; - char *endptr; + uint64_t val; const char *opt = poptGetOptArg(pc); - /* Documented by the man page of strtoll(3). */ - errno = 0; - val = strtoll(opt, &endptr, 10); - if ((errno == ERANGE && (val == LLONG_MAX || val == LONG_MIN)) - || (errno != 0 && val == 0)) { + if (utils_parse_size_suffix((char *) opt, &val) < 0) { ERR("Unable to handle max-size value %s", opt); ret = CMD_ERROR; goto end; } - if (endptr == opt) { - ERR("No digits were found in %s", opt); - ret = CMD_ERROR; - goto end; - } opt_max_size = val; break; -- 2.34.1