]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
use missing argument helper
authorStephen Hemminger <stephen@networkplumber.org>
Tue, 23 Apr 2024 16:01:46 +0000 (09:01 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 23 Apr 2024 16:01:46 +0000 (09:01 -0700)
There is a helper in utilities to handle missing argument,
but it was not being used consistently.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ip.c
ip/iproute_lwtunnel.c
ip/rtmon.c
tc/f_u32.c
tc/m_sample.c
tc/tc.c

diff --git a/ip/ip.c b/ip/ip.c
index e51fa206d282c15c234233ae976b5237eb715c83..eb492139a04d7ce8e93ee0b345c51a8c5d5d04f7 100644 (file)
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -203,15 +203,15 @@ int main(int argc, char **argv)
                        argc--;
                        argv++;
                        if (argc <= 1)
-                               usage();
+                               missarg("loop count");
                        max_flush_loops = atoi(argv[1]);
                } else if (matches(opt, "-family") == 0) {
                        argc--;
                        argv++;
                        if (argc <= 1)
-                               usage();
+                               missarg("family type");
                        if (strcmp(argv[1], "help") == 0)
-                               usage();
+                               do_help(argc, argv);
                        else
                                preferred_family = read_family(argv[1]);
                        if (preferred_family == AF_UNSPEC)
@@ -258,7 +258,7 @@ int main(int argc, char **argv)
                        argc--;
                        argv++;
                        if (argc <= 1)
-                               usage();
+                               missarg("batch file");
                        batch_file = argv[1];
                } else if (matches(opt, "-brief") == 0) {
                        ++brief;
@@ -272,7 +272,7 @@ int main(int argc, char **argv)
                        argc--;
                        argv++;
                        if (argc <= 1)
-                               usage();
+                               missarg("rcvbuf size");
                        if (get_unsigned(&size, argv[1], 0)) {
                                fprintf(stderr, "Invalid rcvbuf size '%s'\n",
                                        argv[1]);
index 949859723dcb91ec7b910c93782242cd2c48a7e9..b4df434855aab6600803ef415f2ef9c50574e1a1 100644 (file)
@@ -2228,11 +2228,8 @@ int lwt_parse_encap(struct rtattr *rta, size_t len, int *argcp, char ***argvp,
                invarg("\"encap type\" value is invalid\n", *argv);
 
        NEXT_ARG();
-       if (argc <= 1) {
-               fprintf(stderr,
-                       "Error: unexpected end of line after \"encap\"\n");
-               exit(-1);
-       }
+       if (argc <= 1)
+               missarg("encap type");
 
        nest = rta_nest(rta, len, encap_attr);
        switch (type) {
index aad9968f967b2b2ed95301b2ef3ce983690de913..08105d686c080fb2632df750ba1e7257f2dcf7ba 100644 (file)
@@ -82,7 +82,7 @@ main(int argc, char **argv)
                        argc--;
                        argv++;
                        if (argc <= 1)
-                               usage();
+                               missarg("family type");
                        if (strcmp(argv[1], "inet") == 0)
                                family = AF_INET;
                        else if (strcmp(argv[1], "inet6") == 0)
@@ -108,7 +108,7 @@ main(int argc, char **argv)
                        argc--;
                        argv++;
                        if (argc <= 1)
-                               usage();
+                               missarg("file");
                        file = argv[1];
                } else if (matches(argv[1], "link") == 0) {
                        llink = 1;
index a06996363b078717efacb9b3507be5a2f17d92ea..d7679e7ae14414dd866bec3e58380e8faa910977 100644 (file)
@@ -663,7 +663,7 @@ static int parse_mark(int *argc_p, char ***argv_p, struct nlmsghdr *n)
        struct tc_u32_mark mark;
 
        if (argc <= 1)
-               return -1;
+               missarg("mark");
 
        if (get_u32(&mark.val, *argv, 0)) {
                fprintf(stderr, "Illegal \"mark\" value\n");
index 642ec3a6ea7ed3f54cb35ba7801665b29933730f..3baf1d55be16d6b68bf9ff9abf7377fe49700884 100644 (file)
@@ -45,11 +45,8 @@ static int parse_sample(const struct action_util *a, int *argc_p, char ***argv_p
        __u32 group;
        __u32 rate;
 
-       if (argc <= 1) {
-               fprintf(stderr, "sample bad argument count %d\n", argc);
-               usage();
-               return -1;
-       }
+       if (argc <= 1)
+               missarg("sample count");
 
        if (matches(*argv, "sample") == 0) {
                NEXT_ARG();
diff --git a/tc/tc.c b/tc/tc.c
index 7edff7e391664011e788beff24bbda177e3c0695..26e6f69ca81d972713edd8d3ecba583289b1ac40 100644 (file)
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -289,7 +289,7 @@ int main(int argc, char **argv)
                } else if (matches(argv[1], "-batch") == 0) {
                        argc--; argv++;
                        if (argc <= 1)
-                               usage();
+                               missarg("batch file");
                        batch_file = argv[1];
                } else if (matches(argv[1], "-netns") == 0) {
                        NEXT_ARG();