]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables-restore: Fix program names in help texts
authorPhil Sutter <phil@nwl.cc>
Sat, 8 Jun 2019 17:34:13 +0000 (19:34 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 9 Jun 2019 18:24:06 +0000 (20:24 +0200)
Avoid referring to wrong or even non-existent commands:

* When calling xtables_restore_main(), pass the actual program name
  taken from argv[0].
* Use 'prog_name' in unknown parameter and help output instead of
  'xtables-restore' which probably doesn't exist.
* While being at it, fix false whitespace in help text.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/xtables-restore.c

index 86f6a3af971f0f06d28dfd6a82bc84e0299d4d8d..2ef42fabc6f45728bb2e56743d71162b97b44075 100644 (file)
@@ -7,6 +7,7 @@
 #include "config.h"
 #include <getopt.h>
 #include <errno.h>
+#include <libgen.h>
 #include <stdbool.h>
 #include <string.h>
 #include <stdio.h>
@@ -51,7 +52,7 @@ static void print_usage(const char *name, const char *version)
                        "          [ --help ]\n"
                        "          [ --noflush ]\n"
                        "          [ --table=<TABLE> ]\n"
-                       "          [ --modprobe=<command> ]\n"
+                       "          [ --modprobe=<command> ]\n"
                        "          [ --ipv4 ]\n"
                        "          [ --ipv6 ]\n", name);
 }
@@ -361,8 +362,7 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
                                p.testing = 1;
                                break;
                        case 'h':
-                               print_usage("xtables-restore",
-                                           PACKAGE_VERSION);
+                               print_usage(prog_name, PACKAGE_VERSION);
                                exit(0);
                        case 'n':
                                h.noflush = 1;
@@ -387,7 +387,8 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
                                break;
                        default:
                                fprintf(stderr,
-                                       "Try `xtables-restore -h' for more information.\n");
+                                       "Try `%s -h' for more information.\n",
+                                       prog_name);
                                exit(1);
                }
        }
@@ -443,13 +444,13 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
 
 int xtables_ip4_restore_main(int argc, char *argv[])
 {
-       return xtables_restore_main(NFPROTO_IPV4, "iptables-restore",
+       return xtables_restore_main(NFPROTO_IPV4, basename(*argv),
                                    argc, argv);
 }
 
 int xtables_ip6_restore_main(int argc, char *argv[])
 {
-       return xtables_restore_main(NFPROTO_IPV6, "ip6tables-restore",
+       return xtables_restore_main(NFPROTO_IPV6, basename(*argv),
                                    argc, argv);
 }