aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-03-31 06:15:01 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-03-31 06:15:01 -0400
commit15517158270e70ae38d643c7cd11292fa8a0b6db (patch)
treec9aa84d9626e699028230642aa78515b277a0766
parent755cbcd7ad8fb0d7ee59bc8a2b3ed87a5c18febe (diff)
trace-cmd: Make sure trace-cmd split start and end values are floats
It is a common mistake to do: trace-cmd split my-trace.dat Expecting to be splitting the file my-trace.dat. But this is taken as the starting value and the user will not know that the command ran the split against trace.dat (if it exists). This patch checks to make sure that the start and end values passed in are indeed floating point (or integer) values. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-split.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/trace-split.c b/trace-split.c
index d3594ab..4f1d139 100644
--- a/trace-split.c
+++ b/trace-split.c
@@ -404,6 +404,7 @@ void trace_split (int argc, char **argv)
404 unsigned long long start_ns = 0, end_ns = 0; 404 unsigned long long start_ns = 0, end_ns = 0;
405 unsigned long long current; 405 unsigned long long current;
406 double start, end; 406 double start, end;
407 char *endptr;
407 char *output = NULL; 408 char *output = NULL;
408 char *output_file; 409 char *output_file;
409 enum split_types split_type = SPLIT_NONE; 410 enum split_types split_type = SPLIT_NONE;
@@ -464,14 +465,24 @@ void trace_split (int argc, char **argv)
464 465
465 if (ac >= 2) { 466 if (ac >= 2) {
466 optind++; 467 optind++;
467 start = strtod(argv[optind], NULL); 468 start = strtod(argv[optind], &endptr);
468 if (ac > 3) 469 if (ac > 3)
469 usage(argv); 470 usage(argv);
470 471
472 /* Make sure a true start value was entered */
473 if (*endptr != 0)
474 die("Start value not floating point: %s", argv[optind]);
475
471 start_ns = (unsigned long long)(start * 1000000000.0); 476 start_ns = (unsigned long long)(start * 1000000000.0);
472 optind++; 477 optind++;
473 if (ac == 3) { 478 if (ac == 3) {
474 end = strtod(argv[optind], NULL); 479 end = strtod(argv[optind], &endptr);
480
481 /* Make sure a true end value was entered */
482 if (*endptr != 0)
483 die("End value not floating point: %s",
484 argv[optind]);
485
475 end_ns = (unsigned long long)(end * 1000000000.0); 486 end_ns = (unsigned long long)(end * 1000000000.0);
476 if (end_ns < start_ns) 487 if (end_ns < start_ns)
477 die("Error: end is less than start"); 488 die("Error: end is less than start");