[iptables,03/12] xtables-save: Use argv[0] as program name
diff mbox series

Message ID 20190720163026.15410-4-phil@nwl.cc
State Changes Requested
Delegated to: Pablo Neira
Headers show
Series
  • Larger xtables-save review
Related show

Commit Message

Phil Sutter July 20, 2019, 4:30 p.m. UTC
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(-)

Comments

Phil Sutter July 20, 2019, 4:52 p.m. UTC | #1
On Sat, Jul 20, 2019 at 06:30:17PM +0200, Phil Sutter wrote:
> 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>

Argh, I should have pulled upstream first, this one was already
accepted. My series rebases cleanly, should I respin?

Sorry for the mess. :(
Pablo Neira Ayuso July 21, 2019, 6:44 p.m. UTC | #2
On Sat, Jul 20, 2019 at 06:52:04PM +0200, Phil Sutter wrote:
> On Sat, Jul 20, 2019 at 06:30:17PM +0200, Phil Sutter wrote:
> > 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>
> 
> Argh, I should have pulled upstream first, this one was already
> accepted. My series rebases cleanly, should I respin?

Please, if not matching asking, please do so. Also addressing
Florian's feedback updating the comments, thanks.

I'll make a quick review tomorrow, sorry but I cannot get on these any
sooner.

Patch
diff mbox series

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",