]> granicus.if.org Git - sysstat/commitdiff
sar: Stricter syntax check
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 2 Jul 2014 19:43:16 +0000 (21:43 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 2 Jul 2014 19:43:16 +0000 (21:43 +0200)
"sar -1 -f" output was different than "sar -f -1" one.
So now enforce options check more aggressively: You cannot enter a day
offset (eg. -1) together with option -f (which tells here to use the
standard sa datafile).

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sar.c

diff --git a/sar.c b/sar.c
index ce050fd0817681da0063a5310e77373fce976b5d..8ac40a5ee10b5393e435925433ac04292a6b295b 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -1206,7 +1206,7 @@ int main(int argc, char **argv)
                }
 
                else if (!strcmp(argv[opt], "-f")) {
-                       if (from_file[0]) {
+                       if (from_file[0] || day_offset) {
                                /* Input file already specified */
                                usage(argv[0]);
                        }
@@ -1281,6 +1281,10 @@ int main(int argc, char **argv)
                         (strlen(argv[opt]) < 4) &&
                         !strncmp(argv[opt], "-", 1) &&
                         (strspn(argv[opt] + 1, DIGITS) == (strlen(argv[opt]) - 1))) {
+                       if (from_file[0] || day_offset) {
+                               /* Input file already specified */
+                               usage(argv[0]);
+                       }
                        day_offset = atoi(argv[opt++] + 1);
                }