Blob Blame History Raw
From 4c351ba82a79b2781fc580f3f5473da0e5a276b8 Mon Sep 17 00:00:00 2001
From: Phil Sutter <phil@nwl.cc>
Date: Sat, 8 Jun 2019 19:34:13 +0200
Subject: [PATCH] xtables-restore: Fix program names in help texts

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>
(cherry picked from commit ac531b4681d1a0309a738d7bc3408fc2270eaa03)

Conflicts:
	iptables/xtables-restore.c
-> missing commit 093cec72e7f77 ("src: replace IPTABLES_VERSION by PACKAGE_VERSION")

Signed-off-by: Phil Sutter <psutter@redhat.com>
---
 iptables/xtables-restore.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
index 6e6daffc9a1df..7c2759a3c5932 100644
--- a/iptables/xtables-restore.c
+++ b/iptables/xtables-restore.c
@@ -7,6 +7,7 @@
 
 #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);
 }
@@ -376,8 +377,7 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
 				p.testing = 1;
 				break;
 			case 'h':
-				print_usage("xtables-restore",
-					    IPTABLES_VERSION);
+				print_usage(prog_name, IPTABLES_VERSION);
 				exit(0);
 			case 'n':
 				noflush = 1;
@@ -402,7 +402,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);
 		}
 	}
@@ -458,13 +459,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);
 }
 
-- 
2.21.0