All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH 03/12] xtables-save: Use argv[0] as program name
Date: Sat, 20 Jul 2019 18:30:17 +0200	[thread overview]
Message-ID: <20190720163026.15410-4-phil@nwl.cc> (raw)
In-Reply-To: <20190720163026.15410-1-phil@nwl.cc>

Don't hard-code program names. This also fixes for bogus 'xtables-save'
name which is no longer used.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 iptables/xtables-save.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/iptables/xtables-save.c b/iptables/xtables-save.c
index 3f389e8fdc234..491122f39bbb0 100644
--- a/iptables/xtables-save.c
+++ b/iptables/xtables-save.c
@@ -9,6 +9,7 @@
 #include "config.h"
 #include <getopt.h>
 #include <errno.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <stdlib.h>
@@ -80,8 +81,8 @@ __do_output(struct nft_handle *h, const char *tablename, bool counters)
 
 	time_t now = time(NULL);
 
-	printf("# Generated by xtables-save v%s on %s",
-	       PACKAGE_VERSION, ctime(&now));
+	printf("# Generated by %s v%s on %s", prog_name,
+	       prog_vers, ctime(&now));
 	printf("*%s\n", tablename);
 
 	/* Dump out chain names first,
@@ -122,7 +123,7 @@ do_output(struct nft_handle *h, const char *tablename, bool counters)
  * rule
  */
 static int
-xtables_save_main(int family, const char *progname, int argc, char *argv[])
+xtables_save_main(int family, int argc, char *argv[])
 {
 	const struct builtin_table *tables;
 	const char *tablename = NULL;
@@ -133,7 +134,7 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[])
 	FILE *file = NULL;
 	int ret, c;
 
-	xtables_globals.program_name = progname;
+	xtables_globals.program_name = basename(*argv);;
 	c = xtables_init_all(&xtables_globals, family);
 	if (c < 0) {
 		fprintf(stderr, "%s/%s Failed to initialize xtables\n",
@@ -237,12 +238,12 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[])
 
 int xtables_ip4_save_main(int argc, char *argv[])
 {
-	return xtables_save_main(NFPROTO_IPV4, "iptables-save", argc, argv);
+	return xtables_save_main(NFPROTO_IPV4, argc, argv);
 }
 
 int xtables_ip6_save_main(int argc, char *argv[])
 {
-	return xtables_save_main(NFPROTO_IPV6, "ip6tables-save", argc, argv);
+	return xtables_save_main(NFPROTO_IPV6, argc, argv);
 }
 
 static int __ebt_save(struct nft_handle *h, const char *tablename, bool counters)
@@ -266,8 +267,8 @@ static int __ebt_save(struct nft_handle *h, const char *tablename, bool counters
 
 	if (first) {
 		now = time(NULL);
-		printf("# Generated by ebtables-save v%s on %s",
-		       PACKAGE_VERSION, ctime(&now));
+		printf("# Generated by %s v%s on %s", prog_name,
+		       prog_vers, ctime(&now));
 		first = false;
 	}
 	printf("*%s\n", tablename);
@@ -308,7 +309,7 @@ int xtables_eb_save_main(int argc_, char *argv_[])
 		}
 	}
 
-	xtables_globals.program_name = "ebtables-save";
+	xtables_globals.program_name = basename(*argv_);
 	c = xtables_init_all(&xtables_globals, h.family);
 	if (c < 0) {
 		fprintf(stderr, "%s/%s Failed to initialize xtables\n",
@@ -362,7 +363,7 @@ int xtables_arp_save_main(int argc, char **argv)
 	};
 	int c;
 
-	xtables_globals.program_name = "arptables-save";
+	xtables_globals.program_name = basename(*argv);;
 	c = xtables_init_all(&xtables_globals, h.family);
 	if (c < 0) {
 		fprintf(stderr, "%s/%s Failed to initialize xtables\n",
-- 
2.22.0


  parent reply	other threads:[~2019-07-20 16:30 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-20 16:30 [iptables PATCH 00/12] Larger xtables-save review Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 01/12] ebtables: Fix error message for invalid parameters Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 02/12] ebtables-save: Fix counter formatting Phil Sutter
2019-07-20 16:30 ` Phil Sutter [this message]
2019-07-20 16:52   ` [iptables PATCH 03/12] xtables-save: Use argv[0] as program name Phil Sutter
2019-07-21 18:44     ` Pablo Neira Ayuso
2019-07-20 16:30 ` [iptables PATCH 04/12] xtables-save: Unify *-save header/footer comments Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 05/12] xtables-save: Fix table compatibility check Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 06/12] nft: Make nft_for_each_table() more versatile Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 07/12] xtables-save: Avoid mixed code and declarations Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 08/12] xtables-save: Pass optstring/longopts to xtables_save_main() Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 09/12] xtables-save: Make COMMIT line optional Phil Sutter
2019-07-20 19:29   ` Florian Westphal
2019-07-20 20:11     ` Phil Sutter
2019-07-20 20:13       ` Florian Westphal
2019-07-20 20:15         ` Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 10/12] xtables-save: Pass format flags to do_output() Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 11/12] arptables-save: Merge into xtables_save_main() Phil Sutter
2019-07-20 16:30 ` [iptables PATCH 12/12] ebtables-save: " Phil Sutter
2019-07-20 19:35 ` [iptables PATCH 00/12] Larger xtables-save review Florian Westphal
2019-07-21 18:56 ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190720163026.15410-4-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.